Design of CAN Wire Communication Module with Microcontroller and MCP2510
2026-04-06 06:40:40··#1
Abstract: Distributed control nodes on a CAN bus are generally composed of a microcontroller and a programmable CAN communication controller. The hardware aspects introduce the circuit principle of the node, while the software aspects present the system program design flow and issues to be aware of. Keywords: MCP2510, CAN controller, intelligent node. CAN (Controller Area Network) bus, also known as a controller local area network, is gaining increasing attention due to its high performance, high reliability, and unique design. Originally designed for automotive monitoring and control systems by Bosch in Germany, the CAN bus is now used in process industries, machinery industries, textile industries, agricultural machinery, robotics, CNC machine tools, medical devices, and sensors. The CAN bus has become an international standard and is widely recognized as one of the most promising fieldbuses. The CAN bus specification has been standardized as ISO 11898 by the International Organization for Standardization and is supported by numerous semiconductor device manufacturers, resulting in various products integrating the CAN protocol. Intelligent nodes in a CAN bus system are the receiving and sending stations of messages on the network, generally composed of a microcontroller and a CAN controller, or a combination of both. The MCP2510 is a standalone programmable CAN controller chip manufactured by Microchip Technology. This article introduces the new independent CAN communication controller MCP2510 and provides an application example of it in a smart node of a CAN bus system. 1. Introduction to the MCP2510 Chip The MCP2510 is a CAN controller with an SPI interface, and its DIP package is shown in Figure 1. It supports the CAN technology specification V2.0A/B. It can send or receive standard and extended information frames, and also has receive filtering and information management functions. The MCP2510 transmits data with the MCU through the SI interface, with a maximum data transmission rate of 5Mbps. The MCU can communicate with other MCU units on the CAN bus through the MCP2510. The MCP2510 contains three transmit buffers and two receive buffers, and also has flexible interrupt management capabilities. These features make the operation of the CAN bus by the MCU very simple. 1.1 Main Features of MCP2510 ◇ Supports CANV2.0A/B; ◇ Has an SPI interface, supporting SPI modes 0, 0 and 1, 1; ◇ Contains 3 transmit buffers and 2 receive buffers, whose priorities can be programmed; ◇ Has 6 receive filters, 2 of which are masked; ◇ Has flexible interrupt management capabilities; ◇ Employs low-power CMOS process technology, with an operating voltage range of 3.0~5.5V, an effective current of 5mA, and a holding current of 10μA; ◇ Operating temperature range of -40~+125℃. 1.2 Structure and Working Principle The MCP2510 is available in PDIP, SOIC, and TSSOP packages. Figure 2 shows the internal structure block diagram of the MCP2510. The CAN protocol unit is responsible for interfacing with the CAN bus, the SPI interface logic is used to realize communication with the MCU, and the register, buffer group, and control logic are used to complete various settings and operation control. The functions and principles of each part will be introduced below in conjunction with its working process. (1) Transmit and Receive Operations: The MCP2510's transmit operation is implemented through three transmit buffers. Each of these three transmit buffers occupies 14 bytes of SRAM. The first byte is the control register TXBNCTRL, which is used to set the conditions for information transmission and provides the information transmission status; bytes 2 to 6 are used to store standard and extended identifiers and arbitration information; the last 8 bytes are used to store the data information to be transmitted. These registers must be initialized before transmission. (2) Interrupt Management: The MCP2510 has eight interrupt sources, including transmit interrupt, receive interrupt, error interrupt, and bus wake-up interrupt. The interrupt enable register (CANINTE) and interrupt mask register (CANINTF) can be used to conveniently manage various interrupts effectively. When an interrupt occurs, the INT pin goes low and remains low until the MCU clears the interrupt. (3) Error Detection: The CAN protocol has detection functions for CRCF errors, acknowledge errors, format errors, bit errors, and stuffing errors. The MCP2510 contains two error counters: a receive error counter (REC) and a transmit error counter (TEC). Therefore, any node in the network may be in one of three states—error-activated, error-acknowledged, or bus-disconnected—due to different error counter values. 2. Application Example of MCP2510 in Intelligent Nodes A CAN bus distributed measurement and control network can be constructed using the MCP2510 and the CAN bus transceiver TJAl050. The system can include a master controller and multiple node controllers. These node controllers can monitor the current, voltage, and ambient temperature of the motor, as shown in Figure 3. This network topology uses a bus structure and passive tap connections, and is simple in structure and low in cost, resulting in high system reliability. Information transmission uses the CAN communication protocol, and the communication medium is twisted-pair cable. Since the CAN bus is based on the encoding of transmitted messages and does not encode the CAN control nodes, the system has good scalability, and adding or removing control nodes on the CAN bus will not affect the other nodes in the system. The MCU of the node controller can be a microprocessor with an SPI interface or a microprocessor without an SPI interface. This system uses the AT89C51 microprocessor without an SPI interface. The AT89C51 can be directly connected to the SPI interface of the CAN controller via its P1 port, and the SPI interface protocol is implemented using software algorithms. The CAN bus transceiver TJAl050 serves as the interface between the MCP2510 and the physical bus. If further improvement in the system's anti-interference capability is required, an opto-isolator can be added between the MCP2510 and TJAl050. The schematic diagram of the intelligent node circuit is shown in Figure 4. 2.1 Software Design Before the MCP2510 can operate normally, it needs to be correctly initialized, including setting the data transmission rate of the SPI interface, the baud rate of CAN communication, the MCP2510's receive filter and shield, and the transmit and receive interrupt enable flags. Unlike the SJAl000, the microcontroller's operation of the MCP2510's receive buffer and transmit buffer must be completed through the SPI interface using the MCP2510's built-in read and write commands. The timing diagrams of its read and write commands are shown in Figures 5 and 6. In this paper, the MCP2510 mainly adopts interrupt mode for receiving and transmitting bus data. The entire system provides two types of interrupts: timer interrupts and external interrupts. The timer interrupt subroutine is mainly responsible for processing A/D data from analog channels AINO~AIN7, sending a "data transmission request command" to the MCP2510, and transmitting data. The external interrupt subroutine mainly includes a CAN bus error handling subroutine and a data receiving subroutine. 2.2 Software Main Design Flow The software main design flow is shown in Figure 7. The following issues need to be noted during software design: ① Because the MCP2510 is in the default Configuration mode after initialization, it needs to be set to Normal mode after initialization. Otherwise, the MCP2510 will remain in Configuration mode and cannot work properly. Setting the MCP2510 to Normal mode can be achieved by using the built-in BitModify 4 instruction of the MCP2510 to write a 0 byte to the CANCTRL control word. ② Before performing any operation on the MCP2510, the microprocessor must output a low level to the chip select (CS) of the MCP2510 to enable it. ③ When performing a "read" operation on the MCP2510, after sending the read instruction and its address code, a clock signal still needs to be provided to the MCP2510 to receive the read data. This can be achieved by sending a 0 byte to the MCP2510. ④ After completing any operation on the MCP2510, a delay should be made to allow sufficient time to prepare for receiving the next operation command, preventing the MCP2510 from becoming "busy". 3 Conclusion The CAN bus is widely recognized as one of the most promising fieldbuses. Its high cost-effectiveness and simple implementation have made it increasingly popular among researchers. The intelligent node described in this paper can connect multiple distributed control systems, and its hardware and software circuit design methods are also suitable for node design in other distributed control systems based on the CAN bus.