1 Introduction Among the mainstream fieldbus industrial communication technologies such as FF, Lonworks, PROFIBUS, CAN, and HART, the CAN (Controller Area Network) bus, in addition to possessing the open, interoperable, and digital communication characteristics of fieldbuses, also has the following characteristics: (1) It works in a multi-master mode; (2) The node information on CAN is divided into different priorities, which can meet different real-time requirements; (3) It adopts non-destructive bus arbitration technology, saving bus conflict arbitration time; (4) It adopts a short frame structure, with short transmission time, reduced interference rate, and excellent error detection effect; (5) Each frame of information has CRC check and other error detection measures, resulting in an extremely low data error rate; (6) The communication medium can be flexibly selected; (7) The number of nodes on CAN can reach up to 110; (8) It has high reliability and performance-price ratio, etc. These characteristics of the CAN bus enable it to meet the needs of process control and manufacturing automation at the same time. Therefore, the research and application of the CAN bus has become a hot topic in the field of industrial data buses. In a bus system, the traditional 4-20mA analog input signal is replaced by a digital signal. Equipment status, faults, parameters, and other information are transmitted to the host computer via the fieldbus for remote control and parameterization. Various instruments and meters with CAN bus interfaces can communicate with the host computer via CAN bus through a CAN adapter card. 2. Hardware Design The core chip for CAN communication is the CAN controller, which primarily handles the CAN communication protocol and implements all functions of the physical layer and data link layer. CAN controllers have many chip architectures, including standalone chips such as Philips' SJA1000 and Siemens' 82C900, as well as embedded architectures integrated with microprocessors. Based on the principles of intelligence, high reliability, strong anti-interference capability, and low cost, this project adopts a CAN controller solution using the Microchip PIC18F458 microcontroller with an embedded CAN controller. The PIC18F458 is powerful, featuring 1536KB of on-chip data RAM, three 16-bit timers/counters, one 8-bit watchdog WDT timer, and an on-chip ADC with eight analog inputs. The watchdog timer (WDT) is used to monitor the program's running status. Once the CPU deviates from the normal program due to unexpected reasons, the WDT will forcibly reset the CPU and return it to the normal program. The PIC18F458 CAN module, in addition to following the CAN bus protocol, also has its own characteristics, mainly including: (1) support for CAN protocol CAN2.0a and CAN2.0b; (2) support for standard frames, extended frames, remote frames, overload frames, error frames, etc.; (3) 2 receive buffers and 3 transmit buffers; (4) 6 receive filters; (5) 2 shield filters. The use of the powerful PIC18F458 microcontroller greatly simplifies the circuit design and saves costs. The CAN transceiver, i.e., the bus driver, is the interface between the CAN controller and the physical bus. It can provide differential transmission and reception functions for the bus. There are various types of CAN bus drivers, such as 82C250/251, TJA1040, and TJA1050, which are suitable for different occasions. The Philips 82C50 high-speed bus driver uses a two-wire differential drive and has strong anti-interference capabilities. The wiring diagram of the CAN bus driver and the microcontroller is shown in Figure 1. To achieve electrical isolation between nodes on the bus, the CAN driver is connected to the PIC18F458 via a high-speed optocoupler 6N137. 120-ohm matching resistors are connected to the CAN connectors at both ends of the CAN bus to eliminate reflections due to impedance discontinuities. A 30pF capacitor is connected in parallel between the bus and ground to prevent electromagnetic radiation and high-frequency interference. Note that in practical applications, the power supplies between nodes must also be isolated; +5V isolation is required before connecting to VCC, otherwise interference will occur. [align=center] Figure 1 Wiring diagram of 82C250 and PIC18F458[/align] 3 Software Design The software uses the MPLab IDE 7.5 development platform and MCC18 software. To facilitate program portability and modification, the program can be designed as relatively independent subroutines. Various CAN bus protocols have been integrated into the CAN module of the PIC18F458; CAN system communication can be completed simply by operating the corresponding registers. The CAN communication program for the Pici8F458 mainly includes CAN initialization, receive subroutines, and send subroutines. CAN initialization primarily configures the CAN, setting the send and receive mailbox identifiers and initialization data, setting the baud rate and CAN operating mode, and initializing the receive filter and receive mask. Reception uses interrupt mode, and transmission uses polling mode. All nodes on the CAN bus must have the same baud rate. Let's assume the baud rate fosc = 4MHz, the synchronization time sync_seg = 1tq, the transmission time prop_seg = 1tq, the phase buffer time phase_seg1 = 3tq, the phase buffer time phase_seg2 = 3tq, the nominal bit time = 8tq, and the bit rate = 0.125MHz. CAN initialization is crucial in CAN bus communication. 3.1 CAN initialization subroutine void intcan() {trisb = (trisb|0x08) & 0xfb; /* Set rb2 as output and rb3 as input */ cancon = 0x80; /* Request configuration */ while ((canstat & 0x80) == 0) /* Configuration mode */ { ; } /* Wait to enter configuration mode */ brgcon1 = 0x01; /* Set baud rate */ brgcon2 = 0x90; brgcon3 = 0x42; txb0con = 0x03; /* Set priority */ txb0sidl = can_biaosf_l & 0xe0; /* Standard identifier */ txb0sidh = can_biaosf_h; txb0dlc = 0x08; /* Data length 1 byte */ txb0d0 = 0x00; txb0d1=0x00; rxb0sidl=can_biaosf_l&0xe0; /* Standard identifier */ rxb0sidh=can_biaosf_h; rxb0con=0x20; /* Accept valid standard identifier information */ rxb0dlc=0x08; /* Data length 1 byte */ rxb0d0=0x00; /* Initial data */ rxb0d1=0x00; rxb0d2=0x00; rxf0sidh=can_biaosf_h; /* Initialize receive filter and receive mask */ rxf0sidl=can_biaosf_l; rxm0sidh=0xff; rxm0sidl=0xe0; cancon=0x40; /* Normal mode */ while ((canstat&0x40) != 0) /* Detect configuration complete */ { ; } pir3=0x00; /* Initialize CAN interrupt */ pie3=0x01; ipr3=0x01; } 3.2 Receive interrupt subroutine void interruphandlerhigh() { if (pir3bits.rxb0if==1) /* Receive CAN interrupt */ { can_flag=1; /* Set receive interrupt flag */ pir3bits.rxb0if=0; /* Clear receive interrupt flag */ rxb0conbits.rxful=0; /* Receive */ } } 3.3 Send subroutine void fasong() txb0d0=clz; /* clz is the value to send */ txb0con=txb0con|0x08; /* Send */ } After writing these three parts of the program, it is easy to write a communication program. 4. Conclusion This project's design can be used to form CAN interfaces for various electrical devices. Further development is possible by adding control algorithms to the devices, enabling bus-based intelligent transformation. The CAN bus interface designed using the PIC18F458 was used to intelligently transform the DKJ linear electric actuator, achieving CAN bus communication with the host computer. The experimental results were satisfactory.