Revision History:
1. Function introduction
1.1 Model Description
This document applies to the following models:
ZQWL-CAN (FD) series products, USB communication using CDC class implementation, can be on the PC virtual out of a serial port, serial port parameters N, 8, 1 format, baud rate can be set as needed (range 9600~48000000bps), hardware automatic matching. This document describes the parameter configuration, data transmission and reception protocols for secondary development.
A series of high-performance USBCAN (FD) interface cards developed by ZQWL have the characteristics of multiple types, flexible installation methods, convenient and easy to use, and powerful functions. Interface cards support XP/Win7/Win10/Win11 and other operating systems.
Among them, ZQWL-UCANFD-200U, ZQWL-UCAN-201U, ZQWL-UCANFD-400U, ZQWL-UCAN-401U and other models, CAN (FD) channels are electrically isolated design, which can be applied to the harsh electromagnetic environment.
1.2 Product characteristics
● The USB interface conforms to the USB2.0 high-speed specification; the CAN interface supports the CAN2.0A and B protocols, and conforms to the ISO11898-1 specification;
● Optional CAN and CANFD protocols; CANFD supports ISO standards and non-ISO standards;
● Each channel can set the baud rate independently, the system not only presets the list of commonly used baud rates, but also supports custom baud rates; Supported baud rate range: CAN: 10Kbps~1Mbps, CANFD: 100Kbps~5Mbps;
● Maximum flow test:
● Each channel has 14 sets of hardware filters; Each group of filters can be set with a filter ID as well as a mask.
● Support continuous loop sending, group sending, scheduled sending, etc.;
● Support baud rate detection, support merging the same frame ID, support bus exception statistics, support transmission and reception rate statistics;
● Dual-channel CAN (FD) interface card supports trunking function;
● 200U, 201U, 400U, 401U CAN(F)-BUS circuit adopts DC 2500V galvanic isolation, which has strong anti-electromagnetic interference ability;
● Working temperature: -40~+85°C;
1.3 Typical applications
● Telematics system, power communication system;
● Coal mine remote communication;
● Industrial site control/;
● Remote monitoring and data collection;
2. Communication protocol
2.1 USB hardware descriptor
This series of devices is identified by the hardware ID (VID and PID) of USB, with the following characteristics:
For example (dual-channel CANFD type):
2.2 Parameter configuration
Each frame of data is 22 bytes long in hexadecimal format: including 2 byte frame headers (0x49, 0x3B), 1 byte function code, 1 byte read/write flag, 16 bytes of data, and 2 byte endings (0x45, 0x2E):
Note:
● When you need to read parameters, "read/write" fill in the 0x52; When it is necessary to write parameters, "read/write" fills in 0x57; Among them, the "Device Information" and "Device Serial Number" commands only support read commands (0x52).
● CAN channel number: the value is 0x00~0x03, corresponding to CAN0~CAN3;
● Custom baud rate flag: 0x00 to use "common baud rate code"; 0x01 is a custom baud rate; When the baud rate is customized (CAN3 only supports "common baud rate codes"), the actual baud rate is calculated by SJW, TSEG1, TSEG2 and BRP, and the calculation method is:
Baud = 60000000/(SJW+1 + TSEG1+1 + TSEG2+1)/BRP。
The value range of SJW: 0x00~0x03;
TSEG1 value range: 0x00~0x0F;
TSEG2 value range: 0x00~0x07;
BRP value range: 1~0x0400, BRP is 2 bytes in length, high byte first, low byte last.
Sample point calculation: SMP=(SJW+1 + TSEG1+1)/(SJW+1 + TSEG1+1 + TSEG2+1).
● Common baud rate codes: the upper 4 bits are the arbitrated domain baud rate (CAN), and the lower 4 bits are the data domain baud rate (CANFD)
Table of baud rate codes for arbitration domains:
Data field baud rate code correspondence table:
●Filter group number: each channel has 14 groups of hardware filters, and the group number value range is 0~13;
Group enable: 0x00 is to disable the group; 0x01 to open the group; Note that the device starts querying this bit from group 0, and when it encounters a group that is not 0x01, it exits the query, even if the group is enabled later.
●Filter frame type: 0x00 is a standard frame; 0x01 is an extended frame;
● Filter acceptance ID and mask:
Filter Acceptance ID: Used to compare the frame ID received by CAN(FD) to determine if the frame was received, hexadecimal.
Mask: Used to mask some bits in the filter acceptance ID to determine whether some bits of the acceptance code participate in the comparison (the corresponding bit is 0 does not participate in the comparison, 1 participates in the comparison), hexadecimal.
Example 1: Select "Standard Frame" for the filter frame type; "Filter Acceptance ID" fill in 001, "Mask" fill in 7FF;
Interpretation: Since the standard frame ID is only 11 bits, the filter acceptance ID and the last 11 bits of the mask are meaningful, and the last 11 bits of the mask are all 1, so the last 11 bits of the filter acceptance ID all participate in the comparison, so the above settings can make the standard frame with the frame ID 001 pass.
Example 2: Select "Standard Frame" for the filter frame type; "Filter acceptance ID" fill in 010, "filter shield code" fill in 7F0 Interpretation: In the same example 1, only 11 bits of the standard frame are valid, and the last 4 bits of the mask are 0, which means that the last 4 bits of the filter acceptance ID do not participate in the comparison, so the above settings can make a set of standard frames with frame IDs from 010 to 01F pass.
Example 3: Select "Extended Frame" for the filter frame type; "Filter acceptance ID" fill in 00 03 04 01, "mask" fill in 1F FF FF FF FF;
Interpretation: The extended frame has 29 bits, and the last 29 bits of the mask are all 1, which means that the last 29 bits of the filter acceptance ID all participate in the comparison, so the above settings can make the extended frame with the frame ID 00 03 04 01 pass.
Example 4: Select "Extended Frame" for the filter frame type; "Filter Acceptance ID" fill in 00 03 04 00, "Mask" fill in 1F F0 FF FF;
Interpretation: According to the above settings, a set of extended frames with frame IDs from 00 00 04 00 to 00 00 0F 04 00 can pass (note that only the 0 to F change in red, 04 00 is fixed).
● System control commands
The set parameters can be written to the device through this command (that is, the power is not lost).
Effective parameters: 0x00 is not effective (power off parameters are lost), 0x01 is effective (saved to flash, power off is not lost);
System reset: 0x00 system does not reset, 0x01 system reset;
CAN0 switch: 0x00 to turn off CAN0, 0x01 to turn on CAN0;
CAN1 switch: 0x00 is to turn off CAN1, 0x01 to turn on CAN1;
For example (using serial port assistant as a host computer):
(1) Read device information
Host computer send (Hex format): 49 3B 40 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 2E
(2) Read the serial number of the device
Host computer send (Hex format): 49 3B 41 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 2E
(3) Set CAN parameters
Set CAN0 parameters: the baud rate of the arbitration domain is 250 kbps and the baud rate of the data domain is 500 kbps
Host computer send (Hex format): 49 3B 42 57 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 2E
Note that after setting, you must also send the effective parameters and open the CAN0 command:
49 3B 44 57 01 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 45 2E
After turning on either CAN channel, the device starts sending heartbeat packets to the host computer.
2.3 Heartbeat pack
According to the number of channels of CAN (FD) of the device, heartbeat packets are divided into 2 formats: single and dual channel device heartbeat packets and 4-channel device heartbeat packets.
2.3.1 Single and dual channel heartbeat packet format
Single and dual channel heartbeat packets are packets sent by the device to the host computer, the length of the heartbeat packet is 17 bytes, and the meaning is as follows:
●The function code is 0xFF (note that the 4-channel function code is 0xFE).
● Device status: 1 byte, defined as follows:
Open flag: 0 is not turned on, 1 is on;
Bus status:
00: The bus is normal;
01: Bus warning
10: Bus passive error
11: The device is offline (at this point, CAN(FD) packets can no longer be sent)
2.3.24 channel heartbeat packet format
The 4-channel heartbeat packet is a packet sent by the device to the host computer, the heartbeat packet length is 32 bytes, and the meaning is as follows:
●The function code is 0xFE (note that the single and dual channel function codes are 0xFF).
●CAN0~1 device status: 1 byte, defined as follows:
●CAN2~3 device status: 1 byte, defined as follows:
Open flag: 0 is not turned on, 1 is on;
Bus status:
00: The bus is normal;
01: Bus warning
10: Bus passive error
11: The device is offline (at this point, CAN(FD) packets can no longer be sent)
2.3.3 Heartbeat packet parameter meaning
●Transmission rate: The number of CAN(FD) packets sent per second.
●Reception rate: The number of CAN(FD) packets received per second.
● Error Counter:
Includes send error counters and receive error counters, these states directly reflect the patency of the bus, and when the receive error counter value is greater than 127, the bus is almost paralyzed. When the error value is high (above 40), it means that the communication of the bus is seriously blocked, and it is necessary to adjust the baud rate value of the CAN (FD) network or increase the CAN (FD) bridge to improve the quality of the CAN (FD) bus. When bus communication is good, the error counter generally remains at 0.
When no data is sent to CAN(FD), the heartbeat packet is sent to the host computer every 1 second, and when there is data sent to the CAN(FD), the device immediately sends a heartbeat packet to the CAN(FD).
2.4 CAN (FD) data sending and receiving instructions
The command enables the sending and receiving of CAN (FD) messages in the following format:
● BYTE0: The frame header is fixed to 0x5A;
● BYTE1: frame information 1, including CAN channel and CAN (FD) message data length DLC;
Each bit of the byte has the following meaning:
When it is a CAN frame, the value range of DLC is 0~8;
When it is a CANFD frame, the DLC values are 0~8, 12, 16, 20, 24, 32, 48, and 64.
Note that BYTE1 is a heartbeat packet sent to the host computer when it is 0xFF or 0XFE, and you need to pay attention when receiving data.
●BYTE2: Frame information 2, including information such as transmission type, frame format, frame type, and whether it is accelerated, and the meaning is defined as follows:
Note: The CAN channel number is composed of 3 bits, from high to low bit: Bit4 of BYTE2, Bit3, and Bit7 of BYTE1. The value is 0x00~0x07, corresponding to CAN0~CAN7 channels.
Normal send: When ID arbitration is lost or there is an error in the send, the CAN controller automatically resends until the send is successful, or the send times out (timeout period of 1 second), or the bus is closed.
Single send: In some applications, automatic resend is meaningless when partial data loss is allowed, but transmission delay is not possible. In these applications, data is generally sent at regular intervals, and automatic retransmission will cause subsequent data to not be sent, resulting in transmission delays. With a single send, arbitration loss or send error, the CAN controller does not resend the message.
● BYTE3~6: CAN (FD) frame ID, a total of 4 bytes. In standard frames, only the lower 11 bits of BYTE5~6 are valid; When extending the frame, 29bit is valid.
Note that the highest bit of BYTE3 (Bit7) is the CAN protocol type flag:
0:CAN帧;
1: CANFD frame;
● Frame data: The length is DLC.
● End of frame: one byte, fixed to 0xA5
When the host computer sends CAN (FD) packets to the device, the device returns a heartbeat packet immediately after receiving it.