Skip to main content
Firmware Stable

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 valueSpeed
12 Mbit/s
21 Mbit/s — default setting in most releases
4500 kbit/s
5400 kbit/s
8250 kbit/s
10200 kbit/s
16125 kbit/s
20100 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:

ValueSample pointBS1 (TQ)BS2 (TQ)
0, 572% (default)125
194%161
288%152
382%143
476%134
664%116
758%107
853%98

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:

ValueSJW (TQ)
01 (default)
12
23
34
tip

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).

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 to 0, a default value of n = 3 is used. See the CAN ID calculator to visualize how changing n affects 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 bitsContent
0 to n-1Sender 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.

note

Three address bits limit the CAN bus to 8 devices maximum. This limitation can be modified through:

  • OEM firmware customization
  • Configuring cfg2 with msgconf, e.g. msgconf 3 2 0 4 sets n = 4 (16 addresses)
info

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
Example

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.

Suggested SID offset for SID 0: 0 0x0
Address bits in the entered CAN ID: 0 of 7
SID offset = 0x000 >> 3
protoconf command (CAN, interface 3):
protoconf 3 255 0 0 0x0
Resulting protoconf register: 255 0x000000FF
This offset boundary (addr 0, down): 0x000
Next offset boundary (up): 0x008 (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 = 22

J1939 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 bitsJ1939 fieldMapped from
28 - 26Priority (3 bits)cfg3 bits 2-4
25Reserved / EDPcfg3 bit 1
24Data Page (DP)cfg3 bit 0
23 - 16PDU Format (PF)cfg2
15 - 8PDU Specific (PS)cfg1
7 - 0Source Address (SA)device address (n = 8)

The protoconf offset bytes therefore correspond to J1939 fields:

  • cfg1 = PDU Specific (PS) — destination address or group extension
  • cfg2 = PDU Format (PF) — determines PDU1 vs PDU2 message type
  • cfg3[4:0] = Data Page, Reserved, and Priority
Example — Proprietary B (PF = 0xFF, Priority = 6)

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 enabled
  • cfg1 = 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
Example — Proprietary A (PF = 0xEF, Priority = 6)

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:

ByteDescription
0Receiver address
1Payload byte 0
2Payload byte 1
3Payload byte 2
4Payload byte 3
5Payload byte 4
6Payload byte 5
7Payload byte 6

CAN Message Data for Multicast datagram

Multicast messages include only sender address

ByteDescription
0Payload byte 0
1Payload byte 1
2Payload byte 2
3Payload byte 3
4Payload byte 4
5Payload byte 5
6Payload byte 6
7Payload byte 7