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.

A twisted pair CAN_H and CAN_L with a 120 ohm terminator at each end. Three ECUs hang on it: engine ID 0x0C0, brakes ID 0x050, dashboard ID 0x3A0, each through a CAN controller and a transceiver. A table: recessive 1 means CAN_H 2.5 V, CAN_L 2.5 V, difference 0 V; dominant 0 means CAN_H 3.5 V, CAN_L 1.5 V, difference 2 V. Bus = AND of all outputs: any dominant gives 0
Every ECU either drives the pair apart (dominant 0) or lets go (recessive 1), so one dominant node is enough to make the bus 0.

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:

ECUIDID10 … ID0Result
brakes0x050000 0101 0000wins, sends its frame
engine0x0C0000 1100 0000loses at ID7 (sends 1, reads 0)
dashboard0x3A0011 1010 0000loses 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

The CAN 2.0A data frame: SOF 1 bit, identifier 11 bits, RTR 1, IDE 1, r0 1, DLC 4, data 0 to 64 bits, CRC 15, CRC delimiter 1, ACK slot 1, ACK delimiter 1, EOF 7. Brackets mark the arbitration field (ID and RTR), the control field (IDE, r0, DLC), and the part from SOF to the end of the CRC where bit stuffing applies. For the brakes frame: 60 bits plus 5 stuff bits is 65 bits, 130 microseconds at 500 kilobit per second
From SOF to the end of the CRC the sender adds stuff bits; the delimiters, ACK and EOF are fixed bits.
FieldBitsBrakes frameWhat it is for
SOF10start of frame; every node syncs to its falling edge
identifier11000 0101 0000 = 0x050message name and priority
RTR100 = data frame, 1 = remote request; last arbitration bit
IDE, r01 + 10 0IDE 0 = standard 11-bit ID; r0 reserved
DLC40010data length: 2 bytes (0 to 8)
data160x01 0xF4the value, here 500 kPa
CRC150x2093checks SOF through data
CRC delimiter11a recessive gap
ACK slot1sender 1, receivers 0any good receiver pulls it dominant
ACK delimiter, EOF1 + 71, 1111111end 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:

FrameCRC-15Stuff bitsLengthAt 500 kbit/s
brakes 0x050: 01 F40x2093565 bits130 µs
engine 0x0C0: 0B B80x6017464 bits128 µs
dashboard 0x3A0: 00 000x0CE5666 bits132 µ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:

ErrorWho sees itWhen
bit errorthe senderit sends one value and reads the other (outside arbitration and the ACK slot)
stuff errorany receiversix equal bits between SOF and the CRC
CRC errorany receiverits own CRC differs from the received one
form erroranyonea fixed bit (a delimiter, EOF) is dominant
ACK errorthe sendernobody 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:

EventCounter
the sender's frame fails with an errorTEC + 8
a receiver sees an errorREC + 1
a frame sent without errorTEC − 1 (not below 0)
a frame received without errorREC − 1 (not below 0)
Three states. Error-active: normal, sends dominant 6-bit error flags. When TEC or REC goes above 127 it becomes error-passive: error flags are recessive, and it waits 8 extra bits before each new transmission. When both counters are 127 or less it goes back to error-active. When TEC goes above 255 it becomes bus-off: it sends nothing, and it may come back to error-active only after 128 times 11 recessive bits and a restart
Since a failed send costs 8 and a good one gains only 1, a node that keeps failing climbs to error-passive and then removes itself from the bus.

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.

On the mind map

Open the Computer Architecture mind mapComputerArchitectureAbstraction and numbers: layers and bit patternsAbstraction and numbersCombinational logic: output depends only on inputsCombinational logicSequential logic: state held by a clockSequential logicMIPS software: how C becomes machine wordsMIPS softwareThe processor: datapath plus controlThe processorPipelines and parallelism: more instructions at oncePipelines and parallelismMemory and I/O: small fast near, big slow farMemory and I/OMemory arraysMemory arraysdecoder picks wordline, bitlines readCPU cacheCPU cachetag, index, offset; hit or missCache address breakdownCache address breakdownsets = lines/ways; tag = rest of addressCache Write PoliciesCache Write PoliciesWrite-back sends dirty lines at evictionLoop tiling and interchangeLoop tiling and interchangeWalk rows; tile so reused data fitsMemory hierarchyMemory hierarchyAMAT = hit time + miss rate × penaltyDRAM timingDRAM timingopen row is fast, row change is slowMESI and false sharingMESI and false sharinga write invalidates other copiesVirtual memoryVirtual memoryTLB caches the page tableEmbedded I/OEmbedded I/Odevices are addresses; poll or interruptMCU startup to mainMCU startup to mainCopy .data, zero .bss, then mainButton debounce FSMButton debounce FSMTwo equal 10 ms samples = one pressI2C BusI2C BusWired-AND bus: ACK, stretch, arbitrateUSB enumerationUSB enumerationAddress 0, descriptors, SET_CONFIGURATIONCAN bus arbitrationDominant 0 wins: lowest ID sends unharmedModbus RTU and TCPModbus RTU and TCPone master asks; bad CRC means silenceTDMA time-triggered busTDMA time-triggered busFixed slots; FTA drops extremes, averagesAMBA AXI, AHB, APBAMBA AXI, AHB, APBVALID and READY both 1 on the edgePCIe TLPsPCIe TLPsRequests by address, completions by IDBus vs Crossbar vs NoCBus vs Crossbar vs NoCBus: one at a time; NoC: links in parallelADC and PWMADC and PWMSAR = binary search; duty = OC1RS/(PR2+1)PID ControlPID ControlI removes error; clamp stops windupOpen the Computer Architecture mind mapComputer Architecturesmall fast near, big slow farMemory and I/OMemory arraysMemory arraysdecoder picks wordline, bitlines readCPU cacheCPU cachetag, index, offset; hit or missCache address breakdownCache address breakdownsets = lines/ways; tag = rest of addressCache Write PoliciesCache Write PoliciesWrite-back sends dirty lines at evictionLoop tiling and interchangeLoop tiling and interchangeWalk rows; tile so reused data fitsMemory hierarchyMemory hierarchyAMAT = hit time + miss rate × penaltyDRAM timingDRAM timingopen row is fast, row change is slowMESI and false sharingMESI and false sharinga write invalidates other copiesVirtual memoryVirtual memoryTLB caches the page tableEmbedded I/OEmbedded I/Odevices are addresses; poll or interruptMCU startup to mainMCU startup to mainCopy .data, zero .bss, then mainButton debounce FSMButton debounce FSMTwo equal 10 ms samples = one pressI2C BusI2C BusWired-AND bus: ACK, stretch, arbitrateUSB enumerationUSB enumerationAddress 0, descriptors, SET_CONFIGURATIONCAN bus arbitrationDominant 0 wins: lowest ID sends unharmedModbus RTU and TCPModbus RTU and TCPone master asks; bad CRC means silenceTDMA time-triggered busTDMA time-triggered busFixed slots; FTA drops extremes, averagesAMBA AXI, AHB, APBAMBA AXI, AHB, APBVALID and READY both 1 on the edgePCIe TLPsPCIe TLPsRequests by address, completions by IDBus vs Crossbar vs NoCBus vs Crossbar vs NoCBus: one at a time; NoC: links in parallelADC and PWMADC and PWMSAR = binary search; duty = OC1RS/(PR2+1)PID ControlPID ControlI removes error; clamp stops windup
This page on the Computer Architecture mind map · 79 pages in 7 branches · open it to see the whole map and test yourself in recall mode.