|
| 1 | +USB-CAN Analyzer - USB to CAN Bus Serial Protocol Definition |
| 2 | + |
| 3 | +Posted by Wilfried Voss on September 19, 2018 - copperhilltech.com |
| 4 | + |
| 5 | +CAN Bus To USB Mini Converter |
| 6 | + |
| 7 | +The USB-CAN Analyzer, in combination with the corresponding Windows software, represents a very economical solution to run an effective CAN Bus Analyzer. It allows you to develop, test, manage, and maintain your own CAN Bus network, as well as receiving, sending, logging, and analyzing CAN Bus data. |
| 8 | + |
| 9 | +For the following, we need to point out that the device is manufactured in China, and documentation is sparse. And while this is a very affordable solution, there is naturally room for some improvement. In general, there is no application interface, or, to be more precise, the communication between the USB-CAN device and the host system, in this case a PC running Windows, is not documented. Consequently, there is currently no software support for Linux (e.g. SocketCAN), and it would be useful if users could write their own applications, regardless of the operating system they use. |
| 10 | + |
| 11 | +As a first step in this direction, we invested some efforts to analyze and document the USB communication protocol, which makes it easy developing an application interface. |
| 12 | + |
| 13 | +There has been a document, USB (Serial port) to CAN protocol defines, that was distributed online, claiming a documentation of the "Send and receive data packet format." However, after analyzing the protocol, we believe that the data frame architecture described therein represents the original intention. |
| 14 | + |
| 15 | +We believe that the architecture as described caused problems when it came to higher baud rates, specifically at 1 Mbps in combination with high busloads. Consequently, the firmware developers decided to optimize the data frame size. As a result, they cut the frame size from a static 20 bytes to a dynamic 6 to 16 bytes, depending on message ID length (11 or 29 bits) and number of data bytes. |
| 16 | + |
| 17 | +The following describes the serial protocol as we analyzed it, with a few unknowns remaining. However, the documentation includes all vital information for creating your own CAN Bus application. |
| 18 | + |
| 19 | +CAN Bus Data Frame |
| 20 | + |
| 21 | +The CAN Bus data frame format applies to both, send and receive. |
| 22 | + |
| 23 | +Both message ID lengths, 11-bit standard and 29-bit extended, use the first two bytes in the serial data frame. Depending on the message ID length, the remaining bytes will be filled differently. |
| 24 | + |
| 25 | +The data frame does not utilize a checksum check, most probably due to keeping the number of transmitted bytes to a minimum and cutting down on processing time. |
| 26 | + |
| 27 | +Byte Description |
| 28 | + |
| 29 | +0 0xAA = Packet Start |
| 30 | + |
| 31 | +1 CAN Bus Data Frame Information |
| 32 | + |
| 33 | + Bit 7 Always 1 |
| 34 | + |
| 35 | + Bit 6 Always 1 |
| 36 | + |
| 37 | + Bit 5 0=STD; 1=EXT |
| 38 | + |
| 39 | + Bit 4 0=Data; 1=Remote |
| 40 | + |
| 41 | + Bit 3…0 Data Length Code (DLC); 0…8 |
| 42 | + |
| 43 | +Standard CAN data frame continues: |
| 44 | + |
| 45 | +Byte Description |
| 46 | + |
| 47 | +2 Message ID LSB |
| 48 | + |
| 49 | +3 Message ID MSB |
| 50 | + |
| 51 | +x Data, length depending on DLC |
| 52 | + |
| 53 | +y 0x55 = Packet End |
| 54 | + |
| 55 | +Extended CAN data frame continues: |
| 56 | + |
| 57 | +Byte Description |
| 58 | + |
| 59 | +2 Message ID LSB |
| 60 | + |
| 61 | +3 Message ID 2ND |
| 62 | + |
| 63 | +4 Message ID 3RD |
| 64 | + |
| 65 | +5 Message ID MSB |
| 66 | + |
| 67 | +x Data, length depending on DLC |
| 68 | + |
| 69 | +y 0x55 = Packet End |
| 70 | + |
| 71 | +CAN Bus Data Frame Size |
| 72 | + |
| 73 | +Standard 11-bit 6 bytes with zero data bytes |
| 74 | + |
| 75 | + 14 bytes with eight data bytes |
| 76 | + |
| 77 | +Extended 29-bit 8 bytes with zero data bytes |
| 78 | + |
| 79 | + 16 bytes with eight data bytes |
| 80 | + |
| 81 | +CAN Bus Initialization Frame |
| 82 | + |
| 83 | +The CAN Bus initialization frame has a constant length of 20 bytes. |
| 84 | + |
| 85 | +Byte(s) Description |
| 86 | + |
| 87 | +0 0xAA = Frame Start Byte 1 |
| 88 | + |
| 89 | +1 0x55 = Frame Start Byte 2 |
| 90 | + |
| 91 | +2 0x12 = Initialization Message ID |
| 92 | + |
| 93 | +3 CAN Baud Rate (See table below) |
| 94 | + |
| 95 | +4 0x01=STD; 0x02=EXT; Applies only to transmitting |
| 96 | + |
| 97 | +5 – 8 Filter ID; LSB first, MSB last |
| 98 | + |
| 99 | +9 – 12 Mask ID; LSB first, MSB last |
| 100 | + |
| 101 | +13 Operation Mode (See table below) |
| 102 | + |
| 103 | +14 0x01; Purpose Unknown |
| 104 | + |
| 105 | +15 – 18 All 0x00 |
| 106 | + |
| 107 | +19 Checksum |
| 108 | + |
| 109 | +Note: The checksum is processed between bytes 2 and 18. |
| 110 | + |
| 111 | +CAN Bus baud rate |
| 112 | + |
| 113 | +0x01 1000k |
| 114 | + |
| 115 | +0x02 800k |
| 116 | + |
| 117 | +0x03 500k |
| 118 | + |
| 119 | +0x04 400k |
| 120 | + |
| 121 | +0x05 250k |
| 122 | + |
| 123 | +0x06 200k |
| 124 | + |
| 125 | +0x07 125k |
| 126 | + |
| 127 | +0x08 100k |
| 128 | + |
| 129 | +0x09 50k |
| 130 | + |
| 131 | +0x0A 20k |
| 132 | + |
| 133 | +0x0B 10k |
| 134 | + |
| 135 | +0x0C 5k |
| 136 | + |
| 137 | +Operation Mode |
| 138 | + |
| 139 | +0x00 Normal |
| 140 | + |
| 141 | +0x01 Loopback |
| 142 | + |
| 143 | +0x02 Silent (Listen-Only) |
| 144 | + |
| 145 | +0x03 Loopback + Silent |
| 146 | + |
| 147 | +CAN Controller Status Frame |
| 148 | + |
| 149 | +The format of the status request and status report frames are identical, where the request frame sends all zeroes between the frame header (frame start tokens plus frame ID) and the checksum, i.e. bytes 3 through 18 are 0x00. |
| 150 | + |
| 151 | +Byte(s) Description |
| 152 | + |
| 153 | +0 0xAA = Frame Start Byte 1 |
| 154 | + |
| 155 | +1 0x55 = Frame Start Byte 2 |
| 156 | + |
| 157 | +2 0x04 = Status Message ID |
| 158 | + |
| 159 | +3 Receive Error Counter |
| 160 | + |
| 161 | +4 Transmit Error Counter |
| 162 | + |
| 163 | +5 – 18 Unknown Purpose |
| 164 | + In case of status report, they may be filled with data |
| 165 | + |
| 166 | +19 Checksum |
| 167 | + |
0 commit comments