How does CAN handle errors?
Short answer: CAN has five error-detection mechanisms: bit monitoring (a transmitter checks that the bus level equals what it sent, outside arbitration and the ACK slot), bit stuffing check, form check (fixed-format fields such as delimiters and EOF), CRC check, and ACK check. A node that detects an error transmits an error frame, which makes all nodes discard the frame, and the sender retransmits automatically. Error counters confine faulty nodes so one bad node cannot block the bus forever.
Error confinement states
| State | Condition | Behaviour |
|---|---|---|
| Error active | TEC < 128 and REC < 128 | sends active error flags (6 dominant bits) |
| Error passive | TEC ≥ 128 or REC ≥ 128 | sends passive error flags (6 recessive bits), waits 8 extra bit times before retransmitting |
| Bus off | TEC ≥ 256 | stops transmitting; recovers only after 128 × 11 recessive bits (and usually a software request) |
TEC (transmit error counter) increases by 8 on a transmit error and decreases by 1 on success; REC increases by 1 (sometimes 8) on receive errors.
What firmware should do
- Monitor error counters and state changes (interrupts on error-passive and bus-off) and report them as diagnostics (DTCs in automotive).
- Decide a bus-off recovery strategy: automatic recovery with a delay, limited retries, or staying off and entering a safe mode.
- Remember that automatic retransmission means a message can be delayed but also that a misconfigured node (wrong bit rate) can cause continuous error frames until it goes bus-off.
Common causes of CAN errors: missing or wrong termination, wrong bit timing or sample point between nodes, oscillator inaccuracy, ground offsets, long stubs, and transceiver problems. Tools: CAN analysers (PCAN, Vector, Kvaser), and oscilloscopes with CAN decoding to look at the analogue signal.