Design of CAN bus node based on MCP2502X/05X

Publisher:快乐心跳Latest update time:2011-05-30 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction
The CAN bus is widely used in the automotive industry, power substation automation, intelligent buildings and other systems due to its low cost, good real-time communication and strong error correction capabilities. The J1939 protocol was proposed by SEA in 1998 and is mainly used in large-scale transportation vehicles such as transportation, agricultural and forestry locomotives, and ships. The MCP2502X/2505X CAN I/O series expander launched by Microchip can be used as an independent CAN expansion node and implement different CAN protocols through configuration. This article uses J1939 as the communication protocol and designs a CAN expansion node based on this device to facilitate the front-end measurement and control functions of the car and connect it to the entire vehicle-mounted CAN network.


2 Introduction to MCP2502X/05X CAN I/O Expander
The MCP2502X/5X device can be used as an I/O expander for CAN systems, supports CANV2.0B Active, can perform protocol conversion between raw data and CAN messages, and has a bus rate of up to 1 Mb/s. The MCP2502X/5X device has multiple peripherals, including digital I/O, 4-channel 10-bit A/D converters, and PWM outputs that can automatically send messages when the pin state changes, including analog inputs that exceed preset thresholds, and provides 1 mask register and 2 acceptance filters, allowing maximum flexibility in the design of the system with respect to the device response identifier. The device can also be configured to automatically send a unique message at any time when one or more errors occur. The device can be pre-programmed in non-volatile memory so that the device can default to a specific configuration during the configuration process.


3 Extension Node Configuration
The CAN network based on MCP2502X/5X must have a CPU with a CAN interface as the master node. MCP2502X/05X can only be used as an extension node and complete the work through configuration. There are two ways to configure the device: pre-programming user registers and online configuration of CAN messages. The user E-PROM of the MCP2502X/05X device is blank when it leaves the factory, so it must be pre-programmed before power-on. The programming result is self-configured to the default configuration after power-on reset. In order to achieve communication based on the J1939 protocol with the master node, the CAN module registers are pre-programmed according to the J1939 identifier format before power-on. There are three ways to pre-program the user registers of the MCE2502X/05X device, namely, using the MPLAB IDE supporting PROMATE II programmer; in-circuit serial programming (ICSP); designing a special programming circuit based on the principle of ICSP, and pre-programming the device with Microchip's programming software MCP250XXProgrammer. The third method is used here.
3.1 Pre-programmed user registers
3.1.1 Pre-programmed circuit design
Programming requires two power supplies, VDD (2.0-6.0 V) and VPP (12-14 V), as shown in Figure 1. In Figure 1, the general-purpose switching regulator LM78S40CN outputs an adjustable 1.25-40 V stable voltage to generate the required VPPPC machine, which controls the on and off of VPP and VDD through the field effect transistor MTSF2P02 to implement the programming logic.

Figure 2 shows the programming data, clock logic circuit and the interface circuit between the programming circuit and the PC. The programming circuit is connected to the PC through the parallel port. After the programming circuit and the PC are connected, the device can be pre-programmed using the graphical interface software (MCP250X X Programmer) provided by Microchip.

3.1.2 Pre-programmed CAN-related registers
Pre-programmed CAN-related registers are to implement different CAN protocols and configure and operate other registers through CAN messages. Under the premise of realizing the control of the device itself, the MCP2502X/05X series devices allow users to configure the CAN module-related registers and design the specific content of the protocol according to the actual situation. The CAN protocol of the expansion node must match the CAN protocol of the main node. This design uses the J1939 protocol standard to configure the CAN module registers. Since point-to-point communication is required between the CAN expansion node and the main node, the PDU1 format is used. The meaning of each bit of its 29-bit identifier is shown in Figure 3.

In Figure 3, the upper 5 bits of the source address are programmable, and the lower 3 bits are associated with the expander hardware to implement specific CAN commands, such as writing "000" to the lower 3 bits of the message source address to read the register of the A/D converter. PS (PDU format) must be less than 240, and the other bits are determined by the application layer. Write the configuration register according to the protocol identifier format. The MCP2502X/5X device contains 3 independent transmit message IDs: TX-ID0, TXID1, and TXID2.
Configure the corresponding registers to predefine the data length code of each message in various output messages and directly input the data to be transmitted from the device peripheral register. The device transmits the message according to the predefined format. Configure the receive mask register to define the bits of the CAN ID compared with the programmable filter. In the 29-bit identifier format, the EID2:EID0 bits of the RXMEID0 register are set to don't care bits. The MCP2502X/5X defines 2 independent receive filters: RXF0 and RXF1. Among them, RXF0 is used for information request messages, while RXF1 is used for input messages. The filter is pre-programmed according to the predetermined identifier format, and each bit of the filter corresponds to a bit of the CAN ID. In order to receive a message, each bit in the CAN ID (when the corresponding mask bit is set to 1) must match the corresponding filter bit. Messages that do not meet the mask/filter conditions are ignored. At the same time, the expansion node is configured in automatic transmission mode, that is, it will automatically send information when the collected input signal changes or after a certain time interval.
3.2 Configuring the expander with CAN messages
Since the configuration registers are accessed through the CAN bus, in addition to using pre-programmed configuration of the expander, after communication is established, the master node configures the device through command messages and can also modify the configured registers online. The type of command message is determined by the lower 3 bits of the source address.


4 Hardware structure of expansion node and system network structure
Figure 4 shows the hardware structure of the expansion node. The MCP2502X/05X device is connected to the CAN bus through the CAN driver. Figure 5 shows the system network structure.

The CAN bus itself is a multi-master bus. In theory, each node can be used as a master node. However, in a CAN network based on MCP25132X/5X devices, there must be a CPU with a CAN interface as a master node to execute the control algorithm and make corresponding control decisions. The expansion node can only be used as a slave node. Other nodes communicate with the corresponding slave nodes through the master node.


5 Master node software design
In the master node software design process, the master node and its corresponding extended node are regarded as different CAs (controller applications) of the same ECU (electronic control unit), and the addresses can be arbitrated. The master node and the extended node communicate point-to-point. All ECUs on the bus follow the J1939 protocol for communication, and other ECUs access the extended node through the master node.
The master node software consists of three parts: main processing, receiving processing, and sending processing. Among them, the receiving processing is responsible for receiving messages that match the address of this ECU, and processing address declaration messages and address request messages, and filling application messages into the receiving buffer; the sending message is responsible for sending the data in the sending buffer to the CAN bus. Figure 6 shows the main processing software flow.

6 Conclusion
Designing CAN expansion nodes based on MCP2502X/05X devices does not require a lot of programming. You only need to configure the relevant registers and connect simple circuits to achieve communication with the main node. It is very flexible to expand a CAN node without a microcontroller, and the user can set the protocol content by himself. Its rich peripherals meet general measurement and control needs. Combining MCP2502X/05X devices with J1939 protocol can facilitate the design of the front-end measurement and control module of the car and connect it to the entire vehicle CAN network. This design scheme has a simple system structure, reduced costs, and improved signal transmission reliability. It has broad application prospects in vehicle CAN networks, especially in front-end measurement and control modules.

Reference address:Design of CAN bus node based on MCP2502X/05X

Previous article:In-circuit programming design based on MAX16031 system manager
Next article:Design of Web Application Framework Based on Model-View-Controller

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号