5.5.6Embedded Systems & Real-Time Software

CAN bus — frame format, arbitration, error handling — critical in aerospace

2,264 words10 min readdifficulty · medium3 backlinks

CAN = Controller Area Network. A robust, multi-master serial bus designed by Bosch (1986) for cars, now critical in aerospace, trains, medical, and industrial control. The genius of CAN is that many nodes share one pair of wires, decide who talks WITHOUT a master, and tolerate noisy environments — all in hardware.


[!intuition] The one-sentence soul of CAN

A polite committee of nodes shouting at once on a single wire. Whoever has the most urgent message (lowest ID) automatically wins the floor — and everyone else steps back without losing their message. No central referee needed.

WHY this matters in aerospace: wires are heavy and failure-prone. CAN lets dozens of sensors/actuators share two wires (CAN_H, CAN_L), self-prioritize life-critical messages (e.g. engine fire alarm beats cabin-light status), and detect + recover from bit errors automatically — exactly what a DO-178C / DO-254 certified system needs.


[!definition] Core vocabulary

  • Dominant bit : logic 0 on the bus. If any node drives 0, the bus reads 0.
  • Recessive bit : logic 1. The bus is 1 only if every node lets it float to 1.
  • Wired-AND : the electrical rule — bus value = AND of all transmitted bits. This is the physical foundation of arbitration.
  • Identifier (ID) : 11 bits (standard) or 29 bits (extended). Lower numeric ID = higher priority.
  • Bit stuffing : after 5 identical consecutive bits, transmitter inserts 1 opposite bit, so receivers can resynchronize their clocks.

WHY dominant=0? Because in an AND, a single 0 forces the result to 0. The node sending 0 "wins" without even knowing it's competing. This is the trick that makes arbitration free.


[!intuition] Picture the wire as a giant AND gate

If three nodes simultaneously send bits b1,b2,b3b_1, b_2, b_3, the bus shows bus=b1b2b3.\text{bus} = b_1 \wedge b_2 \wedge b_3. A node that sent recessive (1) but reads dominant (0) on the bus instantly knows: "someone with higher priority is talking — I'll back off." It stops, waits, and retransmits later automatically. Its message is never corrupted, just delayed.

Figure — CAN bus — frame format, arbitration, error handling — critical in aerospace

Frame format — derived field by field (Standard Data Frame)

We build the frame by asking: what does a receiver need, in order?

Field Bits WHY it exists
SOF Start of Frame 1 (dominant) Wakes & synchronizes all listeners on a falling edge.
Identifier 11 Message priority + content type.
RTR Remote Tx Request 1 0 = data frame, 1 = a request asking for data.
IDE 1 0 = 11-bit (standard), 1 = 29-bit (extended).
r0 reserved 1 future use, dominant.
DLC Data Length Code 4 number of data bytes (0–8).
Data 0–64 the actual payload.
CRC 15 + 1 delimiter error detection over all preceding bits.
ACK 1 + 1 delimiter any receiver pulls dominant to say "I got a valid frame."
EOF End of Frame 7 (recessive) marks the end.
IFS Inter-Frame Space 3 (recessive) gap before next frame.

HOW the ACK works (subtle!): the transmitter sends the ACK slot as recessive. Every receiver that passed the CRC check overwrites it with dominant. The transmitter then reads dominant → "at least one node heard me correctly." No individual acknowledgment, just a collective thumbs-up.


[!example] Arbitration: two nodes fight, nobody loses data

Node A wants to send ID 0b00010110000 (= 176). Node B wants to send ID 0b00010111000 (= 184).

Both start at SOF together. They transmit ID bits MSB→LSB. Watch bit by bit:

bit# A sends B sends bus(AND) result
10..4 same same same tie, keep going
3 0 1 0 B reads 0≠1 → B backs off
2..0 A continues alone A wins

Why this step? At bit 3, A drives dominant (0), B drives recessive (1). Wired-AND → 0. B's transceiver compares "I sent 1 but bus is 0" → loses arbitration, becomes a receiver, retries later. A's transmission was never interrupted. Lower ID (176 < 184) = higher priority = wins. ✅

This is non-destructive bitwise arbitration — the defining feature of CAN.


Error handling — the five guardians

CAN runs 5 independent error checks in hardware:

  1. Bit error — a transmitter reads back a bit different from what it sent (except in arbitration/ACK).
  2. Stuff error — 6+ identical bits seen (bit-stuffing rule violated).
  3. CRC error — computed CRC ≠ received CRC.
  4. Form error — a fixed-format field (delimiter, EOF) has wrong bit value.
  5. ACK error — transmitter sees no dominant ACK → nobody heard it.

When any node detects an error it sends an Error Frame (6 dominant bits = "active error flag"), which violates bit-stuffing on purpose so everyone notices and the frame is globally discarded + automatically retransmitted.

[!formula] Fault confinement — derived from counters

To stop a broken node from jamming the bus forever, each node keeps two counters:

  • TEC = Transmit Error Counter
  • REC = Receive Error Counter

Rules (the key numbers): Error-Active:TEC127 and REC127\text{Error-Active} : TEC \le 127 \text{ and } REC \le 127 Error-Passive:TEC>127 or REC>127\text{Error-Passive} : TEC > 127 \text{ or } REC > 127 Bus-Off:TEC>255\text{Bus-Off} : TEC > 255

  • On error: TEC += 8 (transmitter), REC += 1 (receiver).
  • On success: counters decrement by 1.

WHY +8 / −1 asymmetry? A node causing errors (transmitter) is punished 8× faster than it heals, so a faulty transmitter quickly silences itself (Error-Passive → Bus-Off) while a node merely witnessing others' errors barely climbs. This is fault confinement: the bus protects itself by isolating the offender. Critical for aerospace — one bad LRU can't take down the network.


[!mistake] Steel-manned misconceptions

Mistake 1: "The highest ID number has highest priority." Why it feels right: "high number = high importance" matches everyday intuition. The fix: It's the opposite. Lower ID = higher priority, because dominant=0 wins the wired-AND, and a smaller binary number has more leading zeros (dominant bits). Assign your fire alarm ID 0x001, not 0x7FF.

Mistake 2: "Arbitration loss corrupts or drops the message." Why it feels right: In Ethernet/CSMA-CD a collision destroys both frames → retransmit both. The fix: CAN is non-destructive. The winner's frame is untouched; the loser simply waits and retries. Zero data lost.

Mistake 3: "Bus-Off means the node is dead permanently." Why it feels right: "off" sounds terminal. The fix: A Bus-Off node can recover after observing 128 occurrences of 11 consecutive recessive bits (bus idle), then rejoins with counters reset. Recovery is part of the spec.

Mistake 4: "More data bytes = higher priority because it's a bigger message." The fix: Priority depends ONLY on the ID field during arbitration; DLC/data come later and never affect who wins.


[!recall]- Feynman: explain to a 12-year-old

Imagine a classroom where everyone can talk on one microphone at once. There's a rule: if anyone presses the "0 button," the speaker says 0; only if everybody presses "1" does it say 1. Each kid has a secret number. They all start counting out their number digit by digit. The moment a kid sees the mic say 0 while they pressed 1, they politely shut up and wait — they know someone more important is talking. The kid with the smallest number always wins and finishes their sentence perfectly, nobody gets garbled. And if a kid keeps making mistakes, a scorekeeper counts his fouls; after too many he benches himself so he can't ruin the class.


[!mnemonic]

"Dominant Drives Down, Lowest ID Leads."

  • Dominant = Down = 0 wins.
  • Lowest = Leads (highest priority). Frame order: "Some Idiots Read Data, Check ACK End"SOF, ID, RTR, DLC, Data, CRC, ACK, EOF.

Flashcards

What logic level is the dominant bit on a CAN bus?
Logic 0 (it overrides recessive via wired-AND).
Why does the lowest ID win arbitration?
Dominant=0 wins the wired-AND, and a lower binary ID has more/earlier dominant bits, so it stays on the bus while others read back a mismatch and back off.
What makes CAN arbitration "non-destructive"?
The winning frame is never interrupted; losers detect they sent recessive but read dominant, stop, and retransmit later — no data lost.
How does the ACK slot work?
Transmitter sends it recessive; any receiver that passed CRC overwrites it with dominant, signalling "at least one node received correctly."
Name the 5 CAN error types.
Bit, Stuff, CRC, Form, ACK error.
What is bit stuffing and why?
After 5 identical consecutive bits, insert one opposite bit, so receivers can resynchronize clocks (guarantees edges).
TEC/REC thresholds for Error-Active, Error-Passive, Bus-Off?
Active: TEC≤127 and REC≤127. Passive: TEC>127 or REC>127. Bus-Off: TEC>255.
Why is error count incremented by 8 on transmit error but only 1 on receive error?
To punish the likely-faulty transmitter 8× faster than a passive witness, achieving fault confinement so a bad node silences itself.
What is the SOF field for?
A single dominant bit that creates a falling edge to synchronize all listening nodes.
Standard vs extended identifier lengths?
Standard = 11 bits, Extended = 29 bits (selected by the IDE bit).
Can a Bus-Off node recover?
Yes, after observing 128 sequences of 11 consecutive recessive bits, then rejoins with reset counters.
Which field determines priority, and which never affects it?
The Identifier determines priority; DLC/Data length never affect arbitration.

Connections

  • Wired-AND logic and Open-collector buses — the electrical basis of dominant/recessive.
  • CSMA-CD (Ethernet) — contrast: destructive collision vs CAN's non-destructive arbitration.
  • CRC cyclic redundancy check — used in the CAN error check.
  • Bit stuffing and clock recovery — synchronization without a separate clock line.
  • DO-178C / DO-254 aerospace certification — why deterministic fault confinement matters.
  • Real-Time scheduling — CAN priority ≈ fixed-priority message scheduling (rate-monotonic on the wire).
  • ARINC 825 — the aerospace profile built on top of CAN.

Concept Map

reads 0 if any node sends 0

1 only if all float

enables

competes via

loser sends 1 reads 0

message intact

placed in

contains

contains

enables

allows

supports

prioritizes critical msgs

Wired-AND bus

Dominant bit = 0

Recessive bit = 1

Arbitration

Lower ID = higher priority

Node backs off

Auto retransmit later

Standard Data Frame

CRC field

ACK slot

Error detection

Bit stuffing after 5 equal bits

Receiver resync

Aerospace safety DO-178C

Hinglish (regional understanding)

Intuition Hinglish mein samjho

CAN bus ka core idea bahut elegant hai: ek hi pair of wires pe bahut saare nodes (sensors, ECUs) baithe hain, aur bina kisi master ke ye khud decide kar lete hain ki kaun pehle bolega. Trick ye hai ki bus ek "wired-AND" ki tarah behave karta hai — agar koi bhi node 0 (dominant) bhejta hai, toh bus 0 ho jaata hai; bus 1 (recessive) tabhi rehta hai jab sabhi 1 bhej rahe ho. Isi se priority milti hai: jiska ID number chhota hai (zyada leading zeros = zyada dominant bits), wo win karta hai.

Arbitration ka magic ye hai ki ye non-destructive hai. Do nodes ek saath start karte hain, ID ke bits MSB se bhejte hain. Jis node ne 1 bheja par bus pe 0 dikha, usko samajh aa jaata hai "koi mujhse important node bol raha hai" — wo chup ho jaata hai aur baad mein dobara try karta hai. Winner ka message kabhi corrupt nahi hota. Ethernet wali collision yahan nahi hoti — yahi reason hai ki CAN real-time aur aerospace systems ke liye perfect hai, kyunki fire-alarm jaise critical message hamesha pehle jaayenge.

Error handling bhi kamaal ka hai. 5 tarah ke checks hardware me chalte hain — Bit, Stuff, CRC, Form, ACK error. Koi bhi node galti detect kare toh Error Frame bhejta hai aur frame globally discard ho ke automatically retransmit hota hai. Aur ek "fault confinement" system hai: har node ke paas TEC aur REC counters hote hain. Transmit error pe counter +8 badhta hai par success pe sirf -1 ghatta hai — matlab jo node baar baar galti kar raha hai wo khud ko jaldi se Error-Passive aur phir Bus-Off kar leta hai, taki ek kharab unit poori bus ko jam na kare. Aerospace certification (DO-178C) ke liye yahi deterministic, self-healing behaviour chahiye hota hai.

Go deeper — visual, from zero

Test yourself — Embedded Systems & Real-Time Software

Connections