Notes / Communication Protocols
CAN: how the vehicle bus works
On two differential wires, the message with the lowest ID goes first without collisions. Arbitration, frame structure, bit timing and error handling.
Physical layer
A differential signal on two wires, CAN_H and CAN_L. A difference of about 2 V is dominant (0) and almost 0 V is recessive (1). A 120 Ω termination resistor goes at each end of the bus (measuring 60 Ω across both together is normal).
Arbitration: deciding the order without collisions
When several nodes start sending at once, each one reads the bus while it sends its bits. Dominant (0) beats recessive (1), so a node that sent 1 but read 0 backs off immediately. As a result the message with the smallest ID number gets through undamaged first. So the ID is the priority.
Frame (standard)
| Field | Size |
|---|---|
| SOF | 1 bit |
| ID | 11 bits (29 extended) |
| Control (DLC) | Data length 0 to 8 |
| Data | 0 to 8 bytes |
| CRC | 15 bits |
| ACK | Any node that received it answers with a dominant bit |
Content is identified by message ID, not by address. A receiving node uses filters to accept only the IDs it cares about.
Bit timing
One bit is divided into time quanta (TQ) that make up the sync, propagation and phase segments, and the sampling point is usually placed at 75 to 87.5%. The bus is stable when all nodes have similar sampling points.
Error handling
A node that produces errors accumulates error counts and becomes Error Passive; with more, it goes Bus Off and removes itself from the bus. This keeps one faulty node from blocking the whole bus.
In a picture: arbitration
In CAN, 0 is the state where the bus is actively driven (dominant) and 1 is the released state (recessive). Each node reads the bus while sending; if it sent 1 and reads 0, it concludes another node is sending a more urgent message and stops at once. So collisions do not corrupt data, and the smaller the ID number, the higher the priority.
Frame structure
| Field | Length | Role |
|---|---|---|
| SOF | 1 bit | Start |
| ID | 11 bits (29 extended) | Message type and priority |
| DLC | 4 bits | Data length 0 to 8 |
| Data | 0 to 8 bytes | Content |
| CRC | 15 bits | Error detection |
| ACK | 1 bit | Any receiving node overwrites it with 0 to acknowledge |
The ID is not the receiver's address; it says "what this message is". Every node hears the engine-speed message, and only the nodes that need it pick it out with a filter.
3D labRun what you have read so far→Wiring: 120 Ω at both ends
The signal is the voltage difference between CAN_H and CAN_L. A 120 Ω termination resistor at each end of the bus keeps the signal from reflecting. With power off, measure the resistance between CAN_H and CAN_L: about 60 Ω is correct (two 120 Ω in parallel). 120 Ω means one end is missing, and 40 Ω means three are fitted.
Bit timing
All nodes must use the same speed and similar sample points. 500 kbps with a sample point around 80% is a common setting.
bit time = (1 + TSEG1 + TSEG2) × tq
sample point = (1 + TSEG1) / (1 + TSEG1 + TSEG2)
e.g. 16 tq: TSEG1 = 12, TSEG2 = 3 → 13/16 = 81.25%
Error handling and bus off
Each failed transmission raises the transmit error counter, and past 255 the node removes itself from the bus (bus off). This keeps one faulty node from blocking all communication.
Problems that come up in practice
- A lone node cannot transmit: with no other node to give an ACK, it keeps retransmitting the same frame. For testing you need at least two nodes, or loopback mode.
- One node at a different speed: error frames pour out and communication slows for every node.
- MCU pins wired directly without a transceiver: the CAN controller's TX/RX are logic signals. They must go through a transceiver chip.
- Ground not connected: even a differential signal needs a common ground reference.