The idea: one pair of wires where a 0 always wins
A modern car has dozens of small computers, called ECUs (electronic control units): one for the engine, one for the brakes, one for the dashboard, and many more. CAN (Controller Area Network, made by Bosch in 1986) lets all of them share one twisted pair of wires, CAN_H and CAN_L. Each end of the pair has a 120 Ω terminator. There is no master. Any ECU may start a message when the bus is idle.
A node can put only two things on the pair. It can drive the wires apart: CAN_H goes to about 3.5 V and CAN_L to about 1.5 V. This is dominant, logical 0. Or it can let go: the terminators pull both wires to 2.5 V. This is recessive, logical 1. If one node drives dominant, the bus is dominant, whatever the others do. So the bus is the wired-AND of all outputs. The receivers look only at the difference CAN_H − CAN_L (2 V or 0 V), so noise that hits both wires the same way cancels out.
The page models classic CAN 2.0A (11-bit identifiers, ISO 11898-1) at 500 kbit/s, a common speed for a car's powertrain bus: one bit lasts 2 µs. Three ECUs each have a 2-byte message ready: the engine (ID 0x0C0, 3000 rpm), the brakes (ID 0x050, 500 kPa) and the dashboard (ID 0x3A0, lamps off). The timeline shows, bit by bit, what each ECU drives (its row), what is on the bus, and the CAN_H and CAN_L voltages.
Dominant, recessive and the wired-AND
The wired-AND is the same trick that the I2C bus gets from open-drain outputs and pull-up resistors. CAN does it with a differential pair, so it works over metres of cable in a noisy car instead of a few centimetres on a board. Every node also reads back each bit it sends. That read-back is what makes arbitration, the ACK and error detection work. A node that sends 1 and reads 0 knows that somebody else is driving the bus.
Arbitration: the lowest identifier wins, and nothing is lost
The identifier names the message, not the sender, and it sets the priority: a lower number wins. When several ECUs start at the same moment, they all send their ID bits, MSB first, and check each bit on the bus:
| ECU | ID | ID10 … ID0 | Result |
|---|---|---|---|
| brakes | 0x050 | 000 0101 0000 | wins, sends its frame |
| engine | 0x0C0 | 000 1100 0000 | loses at ID7 (sends 1, reads 0) |
| dashboard | 0x3A0 | 011 1010 0000 | loses at ID9 (sends 1, reads 0) |
In Demo: three ECUs at once all three send SOF together. At ID9 the dashboard sends 1 but the bus is 0, so it stops and becomes a receiver. At ID7 the engine does the same. The brakes ECU never notices: every bit it sent is on the bus, so its frame goes on and finishes in 130 µs. After the 3-bit intermission the engine and the dashboard try again; the engine wins (the dashboard loses at ID9 again) and sends at 136–264 µs, then the dashboard at 270–402 µs. The losers ACK the winner's frame like any other receiver.
This is why CAN arbitration is called non-destructive (CSMA with collision resolution). Compare it with Ethernet's CSMA/CD: there, two stations that send at once destroy both frames, both stop, and each waits a random backoff, so nobody gets through and the delay is random. On CAN the most important message always gets through at once, and no bus time is wasted. The price is that the bus must be short enough for a bit to reach every node and come back within one bit time; that is why CAN tops out around 1 Mbit/s at 40 m. Arbitration on I2C works the same way bit by bit, but it decides between masters by the slave address they happen to send; on CAN the ID is a planned priority, and two nodes must never send the same ID. The other way to share a bus is to give every node fixed time slots, as in TDMA and time-triggered buses.
The data frame, field by field
| Field | Bits | Brakes frame | What it is for |
|---|---|---|---|
| SOF | 1 | 0 | start of frame; every node syncs to its falling edge |
| identifier | 11 | 000 0101 0000 = 0x050 | message name and priority |
| RTR | 1 | 0 | 0 = data frame, 1 = remote request; last arbitration bit |
| IDE, r0 | 1 + 1 | 0 0 | IDE 0 = standard 11-bit ID; r0 reserved |
| DLC | 4 | 0010 | data length: 2 bytes (0 to 8) |
| data | 16 | 0x01 0xF4 | the value, here 500 kPa |
| CRC | 15 | 0x2093 | checks SOF through data |
| CRC delimiter | 1 | 1 | a recessive gap |
| ACK slot | 1 | sender 1, receivers 0 | any good receiver pulls it dominant |
| ACK delimiter, EOF | 1 + 7 | 1, 1111111 | end of frame |
The ACK slot uses the wired-AND again. The sender sends recessive 1 and listens. Every node that received the frame with a correct CRC pulls the bit dominant in the same bit time. The sender cannot tell who acknowledged, only that at least one node did. If it reads 1, nobody got the frame: that is an ACK error.
Bit stuffing
CAN has no clock wire. Every receiver keeps its bit timing by watching the edges between 0 and 1. A long run of equal bits would have no edges, so the clocks could drift apart. The rule: from SOF to the end of the CRC, after five equal bits in a row the sender adds one bit of the opposite value, a stuff bit. Receivers count the same way and drop it. The stuff bit itself counts as the start of the next run.
In the brakes frame, SOF and ID10–ID7 are five 0s, so a 1 is stuffed right there in the arbitration field (all senders still in the race stuff at the same place, because their bits are equal so far). Demo: bit stuffing in a frame of zeros sends the dashboard's 0x00 0x00: it needs 6 stuff bits, so its 60-bit frame grows to 66 bits (132 µs). The brakes frame has 5 (65 bits), the engine frame 4 (64 bits). In the worst case an 8-byte frame of 108 bits needs 24 stuff bits. Six equal bits in a row are therefore never part of a good frame, and CAN uses exactly that for its error flag.
CRC-15
The sender treats SOF, the ID, the control bits and the data (35 bits for 2 data bytes, stuff bits not counted) as a polynomial, divides it by the generator x15 + x14 + x10 + x8 + x7 + x4 + x3 + 1 (0x4599) and sends the 15-bit remainder. It is the same XOR long division as on the CRC page, done bit by bit in a shift register. Each receiver computes it again and compares:
| Frame | CRC-15 | Stuff bits | Length | At 500 kbit/s |
|---|---|---|---|---|
| brakes 0x050: 01 F4 | 0x2093 | 5 | 65 bits | 130 µs |
| engine 0x0C0: 0B B8 | 0x6017 | 4 | 64 bits | 128 µs |
| dashboard 0x3A0: 00 00 | 0x0CE5 | 6 | 66 bits | 132 µs |
(To check an implementation: CRC-15/CAN of the ASCII bytes "123456789" is 0x059E.) CAN's CRC finds any 5 or fewer flipped bits in a frame and any burst of up to 15 bits. Lengths above are SOF to EOF; between two frames there are 3 more recessive bits of intermission.
Errors and the error frame
Every node checks every frame in five ways:
| Error | Who sees it | When |
|---|---|---|
| bit error | the sender | it sends one value and reads the other (outside arbitration and the ACK slot) |
| stuff error | any receiver | six equal bits between SOF and the CRC |
| CRC error | any receiver | its own CRC differs from the received one |
| form error | anyone | a fixed bit (a delimiter, EOF) is dominant |
| ACK error | the sender | nobody pulled the ACK slot low |
A node that finds an error sends an error flag: six dominant bits. They break the stuffing rule (or a fixed field) on purpose, so every other node sees an error too and sends its own flag. Then comes an error delimiter of eight recessive bits. The frame is thrown away by everyone, and the sender sends it again on its own. In Demo: CRC error at the dashboard noise flips data bit D3 of byte 1 at the dashboard only, so it reads 0x09 instead of 0x01 and computes CRC 0x596C ≠ 0x2093. It does not ACK (the engine does, so the slot is still 0). After the ACK delimiter it sends its error flag. The others see a dominant EOF bit, a form error, and add their flags one bit later, so the bus is dominant for 7 bits. The retransmission starts at 152 µs and is good. Either all nodes accept a frame or none do: no ECU acts on a brake value the others never saw.
Fault confinement: TEC, REC, error-passive, bus-off
One broken node could send error flags forever and stop the whole car network. To prevent that, every node keeps two counters: the transmit error counter (TEC) and the receive error counter (REC). The page uses the main rules:
| Event | Counter |
|---|---|
| the sender's frame fails with an error | TEC + 8 |
| a receiver sees an error | REC + 1 |
| a frame sent without error | TEC − 1 (not below 0) |
| a frame received without error | REC − 1 (not below 0) |
Because an error costs the sender 8 and a good frame earns back only 1, a node whose own transceiver is faulty climbs fast, while a node that only sees rare noise stays near 0. In Demo: faulty dashboard, 16 errors every frame from the dashboard fails with a bit error: its transceiver puts a dominant 0 where it sent a recessive stuff bit. After 16 attempts its TEC is 16 × 8 = 128 > 127, so it is error-passive: its error flags are now recessive (they cannot destroy other nodes' frames), and it must wait 8 extra bit times after each frame it sends. The engine and the brakes have REC 16 and are still error-active. In Demo: 32 errors, bus-off the dashboard reaches TEC 256 > 255 and goes bus-off: it stops sending and even stops sending ACKs. The brakes then send a frame as usual; only the engine ACKs it, and its REC goes from 32 to 31. The rest of the car keeps working without the dashboard.
See also Modbus RTU and Modbus TCP, frame by frame, a factory bus where one master polls every slave instead of letting nodes arbitrate.
See also USB enumeration, a host-driven bus where the device only answers and a CRC error makes the host retry up to three times.
What the page leaves out
- Some fault-confinement details: a receiver that sees a dominant bit right after its own error flag adds 8, not 1 (the dashboard in the CRC demo would end at REC 9); an error-passive sender with an ACK error does not count it; a REC above 127 drops to between 119 and 127 after a good frame; error-passive receivers send a passive flag.
- Bit timing inside one bit: the sync, propagation and phase segments, the sample point, hard and soft resynchronization, and the resulting limit on bus length.
- CAN 2.0B extended frames (29-bit ID with SRR and IDE = 1), remote frames, overload frames, and CAN FD (up to 64 data bytes, a faster data phase, CRC-17/21) and CAN XL.
- The physical layer in detail: transceiver chips, common-mode range, stubs, sleep/wake-up, and fault-tolerant low-speed CAN; real ECUs' message databases (DBC files) and higher layers such as CANopen, J1939 and ISO-TP diagnostics.
- Worst-case response-time analysis of a set of periodic CAN messages, which uses the fixed priorities the same way as rate-monotonic scheduling.