Primer
CAN in ten minutes
CAN (Controller Area Network) is how the boards in a car, a robot or a factory line talk to each other over two wires. This is what you played with in the meeting, in order.
The bus
Every node connects to the same pair of wires, CAN_H and CAN_L. A node sends a 0 by driving them apart (CAN_H to about 3.5 V, CAN_L to about 1.5 V). That's a dominant bit. A 1 is recessive: nobody drives, and both wires rest at 2.5 V.
Because a driven 0 always beats a resting 1, any node can pull the bus to 0 and every node sees it. Receivers read the difference between the wires, so noise that hits both equally cancels out.
The frame
A message is a frame. Classic CAN 2.0A frames carry an 11-bit identifier and up to 8 data bytes. Here is the one from the meeting, 331+hello, with its real CRC and stuff bits. Tap the fields and press play.
CAN 2.0A data frame
331+hello
- To
- 331 · 0x14B
- Bus
- 500 kbit/s
- ACK
- received by another node
Fields · tap one
Hover or tap a field to see what it does. The widths are to scale: each field is as wide as its bits.
- Framing
- Arbitration
- Control
- Data
- CRC
- ACK
Length and timing
174 µson the wire at 500 kbit/s
84 bits + 3 stuff = 87 bits, then 3 IFS
t = (44 + 8·5 + 3) / 500k
| Bitrate | Bit time | Frame time |
|---|---|---|
| 125 kbit/s | 8 µs | 696 µs |
| 250 kbit/s | 4 µs | 348 µs |
| 500 kbit/sthis bus | 2 µs | 174 µs |
| 1 Mbit/s | 1 µs | 87 µs |
On the wire
Playback shows 12 bits a second, about 41,667× slower than the real 174 µs.
- CAN_H
- CAN_L
- Dominant (0): H at 3.5 V, L at 1.5 V. Recessive (1): both at 2.5 V.
Bit sequence · stuff bits after five identical bits, SOF to CRC
Field table
| Field | Bits | Value |
|---|---|---|
| Start of frame | 1 | 0 |
| Identifier | 11 | 331 · 0x14B |
| RTR | 1 | 0 |
| IDE | 1 | 0 |
| Reserved | 1 | 0 |
| DLC | 4 | 5 bytes |
| Data | 40 | 68 65 6C 6C 6F |
| CRC | 15 +3 | 0x4160 |
| CRC delimiter | 1 | 1 |
| ACK slot | 1 | 0, dominant: acknowledged |
| ACK delimiter | 1 | 1 |
| End of frame | 7 | 1111111 |
| Interframe space | 3 | 111 |
Identifiers
In the playground the ID is the node you're sending to. On a real bus it names the message instead ("motor 3 current", "battery voltage"), and any node that cares about it listens. Nodes use an acceptance filter to ignore the rest.
The ID is also the priority. If two nodes start at once, they send their IDs bit by bit while listening. A node that sends a recessive 1 but hears a dominant 0 knows it lost and stops. The lowest ID always wins, and the winning frame goes through undamaged. That's arbitration.
Bitrate
Every node on a bus has to agree on how long a bit lasts. At 500 kbit/s a bit is 2 µs; at 125 kbit/s it's 8 µs. A frame takes
t = (44 + 8n + s) / bitrate
for n data bytes and s stuff bits. A node at the wrong bitrate can't read anything. On a real bus it starts sending error frames and disrupts everyone; the playground gives each bitrate its own bus instead, so you just hear silence.
CRC and bit stuffing
The 15-bit CRC is a checksum over everything from the start of frame through the data, using the polynomial 0x4599. Every receiver recomputes it. A mismatch means a bit flipped on the way.
There's no separate clock wire, so receivers resync on every edge. To guarantee edges, the sender inserts an opposite bit after five identical bits in a row, from the start of frame to the end of the CRC. Receivers strip them out. Six identical bits in a row there is an error.
ACK
The sender sends the ACK slot recessive. Any node that received the frame correctly pulls it dominant, all at the same moment. So an ACK means “someone got it”, not “the target got it”. If nobody else is on the bus, the slot stays recessive: an ACK error. Real controllers then resend the frame.
Beyond
Higher layers build on these frames. CANopen and J1939 define what the IDs and bytes mean in machines and trucks. ISO-TP splits long messages across frames, much like the playground's “1 of 3”. CAN FD keeps the same idea but allows 64 data bytes and a faster data phase.
Check yourself
QName four fields of a CAN data frame.
Any four of: start of frame, identifier, RTR, IDE, r0, DLC, data, CRC, CRC delimiter, ACK slot, ACK delimiter, end of frame.
QWhat does the DLC tell a receiver?
How many data bytes follow, from 0 to 8 in classic CAN.
QWhy does the CRC exist?
Every receiver recomputes the 15-bit checksum over the frame. If it doesn't match, a bit was corrupted on the way and the frame is rejected.
QWhy can't a node at 250 kbit/s talk to one at 500 kbit/s?
They disagree on how long a bit lasts. The 500k node samples twice per 250k bit, so it reads garbage. On a real bus that causes error frames.
QYou sent a frame to an ID nobody has and still got an ACK. Why?
ACK only means some node received the frame correctly. Every node on the bus checks every frame, whether it's addressed to them or not.
QWhy is a frame longer on the wire than on paper?
Bit stuffing: after five identical bits the sender inserts one opposite bit, so receivers always see edges to keep their clocks in sync.