What happens after serial port data is converted to CAN data

What should I do if the MCU has no CAN or the number of CAN interfaces is not enough? At present, there are related modules or devices for serial port to CAN on the market, but do you know how the serial port to CAN is realized? What is the format of the converted frame? This article will introduce the CAN frame format and precautions after the serial port has been converted in detail.

What should I do if the MCU has no CAN or the number of CAN interfaces is not enough? At present, there are related modules or devices for serial port to CAN on the market, but do you know how the serial port to CAN is realized? What is the format of the converted frame? This article will introduce the CAN frame format and precautions after the serial port has been converted in detail.

Applicable scene

When does the serial port to CAN module need to be used? First, the old product is facing an upgrade and needs to use CAN bus communication, but the MCU in the hardware platform does not have a controller integrated with the CAN bus. Second, the selected MCU already contains the CAN bus interface, but the quantity cannot meet the project requirements. If the above two situations occur and the MCU has an idle serial port, the serial port to CAN module can be used to solve the problem.

What happens after serial port data is converted to CAN data

Figure 1 Application industry

Instructions

This kind of module can be easily embedded into the device with UART interface, and the device can obtain the CAN-bus communication interface without changing the original hardware structure, and realize the data communication between the device with UART and the CAN-bus network. . The industrial-grade conversion module also includes analog and digital devices, optocouplers, DC/DC converters, CAN-bus interfaces, etc., which are necessary to realize the CAN and UART conversion with isolation.

What happens after serial port data is converted to CAN data

Figure 2 Product Architecture

Conversion Instructions

CSM100 series modules provide 3 protocol conversion methods: transparent conversion, transparent label conversion, and custom protocol conversion. The following is a brief description of the transparent conversion format of the modules of the CSM100 series.

In this mode, the CSM100 immediately converts the data from one side of the bus and sends it to the other side of the bus. The module data conversion efficiency in this mode is the highest, and it can undertake the data transmission of large traffic. When the serial frame is converted to the CAN frame, the module directly packages the data from the serial port, and inserts the pre-configured CAN frame information and frame ID together and sends it to the bus as a frame of data. Similarly, the data from the CAN bus will be split into byte streams and sent to the serial port in sequence. The first few bytes of the byte stream are the information of the CAN frame.

What happens after serial port data is converted to CAN data

Figure 3 Conversion method

Speaking of this, everyone must have a doubt, how are the CAN frame information and CAN frame ID represented?

The frame information is mainly used to distinguish standard frames and extended frames, and the length is 1 byte. In “Custom Protocol Conversion”, the standard frame is fixed to 0x00, and the extended frame is fixed to 0x80; in “Transparent Conversion” and “Transparent Band Mark Conversion”, the standard frame is 0x0_, and the extended frame is 0x8_, where “_” represents each The length of the data field in each frame, ranging from 0 to 8.

The frame ID of the standard frame is split into 2 bytes, and the frame ID of the extended frame is split into 4 bytes. If only one byte is reserved for the frame ID during the actual configuration and the frame type is extended frame, and the direction is CAN frame to serial frame, then only the upper 8 bits of the frame ID will be obtained. If only one byte is reserved for the frame ID during the actual configuration and the frame type is extended frame, and the direction is serial frame to CAN frame, then the upper 8 bits of the frame ID are normally filled, and the other three bytes are filled with zeros.

What happens after serial port data is converted to CAN data

Figure 4 Frame ID conversion description

Assuming that the configured frame information of the converted CAN message is “standard frame”, the configured frame ID1 and ID0 are “0x01, 0x23” respectively, and the data of the serial frame is 01, 02, 03, 04, 05, 06, 07 , 08 has a total of 8 bytes, then the conversion format is shown in Figure 5. The frame ID of the CAN message is 0x0123 (user configuration), frame information: standard frame (user configuration), the data part in the serial frame will be converted into the CAN message without any modification.

What happens after serial port data is converted to CAN data

Figure 5 Serial frame to CAN frame

Assuming that the frame ID1 in the CAN message is 0x01, the frame ID0 is 0x23, and the data is 0x12, 0x34, 0x56, 0x78, 0xab, 0xcd, 0xef, 0xff, the CAN message and the converted serial frame are shown in Figure 6. The frame information (0x08) of the CAN message is converted to the first byte (0x08) in the serial frame, and the ID: 0x0123 in the CAN message is sequentially converted to the second byte (0x01) in the serial frame and 3rd byte (0x23). The data field of the CAN message will be converted into the data part of the serial frame without any modification.

What happens after serial port data is converted to CAN data

Figure 6 CAN frame to serial frame

Summarize

The above is the conversion method in the transparent format of serial port to CAN. In the future, the author will add the content of transparent band mark conversion, custom protocol conversion and moudbus conversion, please continue to pay attention.

What happens after serial port data is converted to CAN data

The Links:   FZ3600R17KE3_B2 NL2432HC22-50B