CAN Bus
This guide covers the physical and link layers for CAN interfaces used by the YOS communication system. The physical layer defines bus speed and timing. The link layer defines the device addressing and service identification. The construct can be used for the utility driver and common I/O API communication.
Physical layer configuration
The physical layer for CAN interfaces is configured through cfg0 and cfg1 of the msgconf command (interface number 3 for CAN, 4 for CANEXT).
Bus speed (cfg0)
cfg0 indirectly sets the speed of the interface. It is a prescaler of the maximum CAN speed — 2 Mbps:
cfg0 value | Speed |
|---|---|
| 1 | 2 Mbit/s |
| 2 | 1 Mbit/s — default setting in most releases |
| 4 | 500 kbit/s |
| 5 | 400 kbit/s |
| 8 | 250 kbit/s |
| 10 | 200 kbit/s |
| 16 | 125 kbit/s |
| 20 | 100 kbit/s |
Timing (cfg1)
cfg1 configures the CAN bit timing parameters:
Sample point (bits 0-3)
The lower nibble selects the sample point position within the bit period:
| Value | Sample point | BS1 (TQ) | BS2 (TQ) |
|---|---|---|---|
| 0, 5 | 72% (default) | 12 | 5 |
| 1 | 94% | 16 | 1 |
| 2 | 88% | 15 | 2 |
| 3 | 82% | 14 | 3 |
| 4 | 76% | 13 | 4 |
| 6 | 64% | 11 | 6 |
| 7 | 58% | 10 | 7 |
| 8 | 53% | 9 | 8 |
SJW — Synchronization Jump Width (bits 4-5)
Bits 4-5 set the resynchronization jump width, which defines the maximum number of time quanta the controller may shorten or lengthen a bit to resynchronize with the bus:
| Value | SJW (TQ) |
|---|---|
| 0 | 1 (default) |
| 1 | 2 |
| 2 | 3 |
| 3 | 4 |
For most applications, the default (cfg1 = 0) is appropriate. Adjust the sample point when interoperating with devices that expect a specific value (e.g. CANopen recommends 87.5%, use value 2).
Link layer — CAN ID composition
The link layer is configured through cfg2 and cfg3 of the msgconf command:
cfg2— configures the number of bits (n) used for the transmitter address in the CAN ID for unicast and multicast messages. If this value is set to0, a default value ofn = 3is used. See the CAN ID calculator to visualize how changingnaffects the CAN ID space.cfg3— reserved for further definition.
CAN ID
On CAN bus, the CAN ID encodes both the sender address and the SID. The receiver address (for unicast) is carried in the first data byte.
CAN_ID = (SID << n) + sender_address
Where n is the number of bits allocated for the sender address (default n = 3).
| CAN ID bits | Content |
|---|---|
| 0 to n-1 | Sender address |
| n to 10 (standard) or 28 (extended) | SID |
With the default n = 3, up to 8 devices can share a CAN bus, and each SID occupies a block of 8 consecutive CAN IDs.
Three address bits limit the CAN bus to 8 devices maximum. This limitation can be modified through:
- OEM firmware customization
- Configuring
cfg2withmsgconf, e.g.msgconf 3 2 0 4setsn = 4(16 addresses)
If you do not follow the link layer structure, use the sender address with all bits set to one (e.g. 0b111 for n=3).
SID remapping effect on CAN ID
When SID remapping is active, the offset is added to the SID before computing the CAN ID:
CAN_ID = (effective_SID << n) + sender_address
= ((SID + offset) << n) + sender_address
With offset = 100, sending PWR (SID 0) from address 5 (n = 3):
CAN_ID = ((0 + 100) << 3) + 5 = 805 = 0x325
For a complete table of CAN IDs occupied by the service and process protocols, see What CAN IDs are occupied?.
CAN ID / SID offset calculator
Use this calculator to compute the CAN ID from SID, offset, address, and the number of CAN address bits, or derive the SID offset from a known CAN ID.
0x0SID offset = 0x000 >> 3protoconf 3 255 0 0 0x00x000000FF0x0000x008 (offset 1)device.ini [IDs] section:; SID remap offset: 0 (matching protoconf = 0x000000FF on CAN)
[DETAIL.IDs.kvaser] ; (Or [DETAIL.IDs.pcan] for PEAK CAN interfaces, etc.)
resetID = 0
ID_ID = 3
bootloaderID = 4
bootloaderdataID = 5
FS_ID = 6
FS_DATAID = 7
RPC_ID = 8
RPC_DATAID = 9
streamID_rx = 10
streamID_tx = 11
MSG_SID_PLOT = 20
MSG_SID_PLOT_CONTINUE = 21
MSG_SID_PLOT_SETUP = 22J1939 compatibility example
With n = 8 (8 address bits), the CAN ID formula becomes:
CAN_ID (29-bit) = (effective_SID << 8) + source_address
This maps directly onto the J1939 extended CAN ID structure:
| CAN ID bits | J1939 field | Mapped from |
|---|---|---|
| 28 - 26 | Priority (3 bits) | cfg3 bits 2-4 |
| 25 | Reserved / EDP | cfg3 bit 1 |
| 24 | Data Page (DP) | cfg3 bit 0 |
| 23 - 16 | PDU Format (PF) | cfg2 |
| 15 - 8 | PDU Specific (PS) | cfg1 |
| 7 - 0 | Source Address (SA) | device address (n = 8) |
The protoconf offset bytes therefore correspond to J1939 fields:
cfg1= PDU Specific (PS) — destination address or group extensioncfg2= PDU Format (PF) — determines PDU1 vs PDU2 message typecfg3[4:0]= Data Page, Reserved, and Priority
To place service protocol messages in the J1939 Proprietary B range (PGN 0xFF00-0xFFFF) with default priority 6:
AM-felix#>protoconf 3 255 0 0xFF 0x18
configuring proto 3 as 1627389183 (0x18FF00FF)
(y/n) ?
y
AM-felix#>
cfg0 = 255— all services enabledcfg1 = 0x00— PS = 0 (base; services increment from here)cfg2 = 0xFF— PF = 255 (Proprietary B)cfg3 = 0x18— DP = 0, R = 0, Priority = 6 (bits 2-4 =0b110)
Resulting CAN IDs (from address 0):
- PWR (SID 0):
0x18FF0000 - FWD (SID 2):
0x18FF0200 - ID (SID 3):
0x18FF0300
To use the Proprietary A range (PGN 0xEF00, peer-to-peer) with PS = 0x40 as base:
AM-felix#>protoconf 3 255 0x40 0xEF 0x18
configuring proto 3 as 1626800383 (0x18EF40FF)
(y/n) ?
y
AM-felix#>
cfg1 = 0x40— PS = 64 (base offset in PDU Specific)cfg2 = 0xEF— PF = 239 (Proprietary A)cfg3 = 0x18— DP = 0, R = 0, Priority = 6
Resulting CAN IDs (from address 0):
- PWR (SID 0):
0x18EF4000 - FWD (SID 2):
0x18EF4200
CAN Message Data for Unicast datagram
Unicast messages contain the receiver address in the first byte of the frame, before payload starts:
| Byte | Description |
|---|---|
| 0 | Receiver address |
| 1 | Payload byte 0 |
| 2 | Payload byte 1 |
| 3 | Payload byte 2 |
| 4 | Payload byte 3 |
| 5 | Payload byte 4 |
| 6 | Payload byte 5 |
| 7 | Payload byte 6 |
CAN Message Data for Multicast datagram
Multicast messages include only sender address
| Byte | Description |
|---|---|
| 0 | Payload byte 0 |
| 1 | Payload byte 1 |
| 2 | Payload byte 2 |
| 3 | Payload byte 3 |
| 4 | Payload byte 4 |
| 5 | Payload byte 5 |
| 6 | Payload byte 6 |
| 7 | Payload byte 7 |