| Mechanism | Where Applied | What It Catches |
|---|---|---|
| Bit Monitoring | Transmitter reads own transmitted bit | Driver failure, ground shift, short to CANH/CANL |
| Bit Stuffing | SOF through CRC field | Noise-corrupted bit stream, missing/extra bits |
| CRC Check | 15-bit CCITT polynomial over data+CRC field | Up to 5 random bit errors, all burst errors ≤15 bits |
| Frame Check | Fixed-format fields (EOF, delimiters, ACK) | Protocol violations, off-specification nodes |
| ACK Check | ACK slot (1 bit) | No receiver present, severe bus fault |
Five Error Detection Mechanisms
TEC and REC Counters
/* Read TEC/REC from CAN controller registers (STM32 example) */
#include "stm32f4xx_hal.h"
typedef struct {
uint8_t TEC; /* Transmit Error Counter */
uint8_t REC; /* Receive Error Counter */
uint8_t state; /* 0=Active, 1=Passive, 2=BusOff */
} CAN_ErrorStatus_t;
CAN_ErrorStatus_t CAN_GetErrorStatus(CAN_HandleTypeDef* hcan)
{
CAN_ErrorStatus_t status;
uint32_t esr = hcan->Instance->ESR;
/* TEC = bits [31:24], REC = bits [23:16] */
status.TEC = (uint8_t)((esr >> 24) & 0xFF);
status.REC = (uint8_t)((esr >> 16) & 0xFF);
/* State from EPVF (Error Passive) and BOFF (Bus Off) flags */
if (esr & CAN_ESR_BOFF) status.state = 2; /* Bus Off */
else if (esr & CAN_ESR_EPVF) status.state = 1; /* Error Passive */
else status.state = 0; /* Error Active */
return status;
}
/* Counter rules per ISO 11898-1: */
/* TEC: +8 on transmit error, -1 on successful transmit */
/* REC: +1 on receive error (but +8 if bit error during error flag) */
/* -1 on successful receive (min 0) */| Counter Event | TEC Delta | REC Delta |
|---|---|---|
| Transmit error (any type) | + 8 | — |
| Successful frame transmission | − 1 | — |
| Receive error (any type) | — | + 1 |
| Bit error during error flag transmission | + 8 | — |
| Successful frame reception | — | − 1 (min 0) |
Error Active, Passive, and Bus-Off States
Power On
│
▼
┌─────────────────────────────────────────┐
│ ERROR ACTIVE │
│ TEC < 128 AND REC < 128 │
│ Transmits 6-dominant Active Error Flag │
│ (disrupts erroneous frame for all nodes)│
└────────────────┬────────────────────────┘
│ TEC ≥ 128 or REC ≥ 128
▼
┌─────────────────────────────────────────┐
│ ERROR PASSIVE │
│ TEC ≥ 128 or REC ≥ 128 │
│ Transmits 6-recessive Passive Error Flag│
│ (other nodes may not notice the error) │
│ Waits extra 8-bit Suspend Transmission │
│ after own transmit before next attempt │
└────────────────┬────────────────────────┘
│ TEC > 255
▼
┌─────────────────────────────────────────┐
│ BUS OFF │
│ Node disconnects — stops all activity │
│ Recovery: 128 × 11 consecutive │
│ recessive bits (≥ 1.4 ms at 1 Mbps) │
└─────────────────────────────────────────┘💡 Error Passive Subtlety
An Error Passive node transmits a 6-bit recessive Error Flag instead of a 6-dominant Active Error Flag. Recessive bits can be overwritten by other nodes' dominant bits, so the passive error flag may be invisible to the rest of the bus. The error is still logged internally but does not disrupt the current frame for other receivers. This asymmetry is intentional — a struggling node degrades gracefully rather than continuously disrupting healthy traffic.
Fault Confinement in Practice
# CANalyzer CAPL equivalent: monitor TEC/REC via diagnostic message
# Most CAN controllers expose TEC/REC via proprietary CAN message or OBD service
# Using python-can to poll controller stats (Linux SocketCAN)
import can, time
bus = can.interface.Bus(channel='can0', bustype='socketcan')
notifier = can.Notifier(bus, [])
# Monitor for error frames (CANalyzer: Statistics window → Error Frames)
error_count = 0
start = time.time()
for msg in bus:
if msg.is_error_frame:
error_count += 1
print(f"t={msg.timestamp-start:.3f}s ERROR FRAME #{error_count}")
# Read TEC/REC from /sys/class/net/can0/statistics/
with open('/sys/class/net/can0/statistics/bus_error') as f:
bus_errors = int(f.read())
with open('/sys/class/net/can0/statistics/error_passive') as f:
passive_count = int(f.read())
if passive_count > 0:
print(f"WARNING: node entered Error Passive state ({passive_count} times)")
# Investigate: faulty transceiver, EMC issue, baud rate mismatchSummary
CAN's five-layer error detection catches over 99.999% of all single and burst transmission errors. The TEC/REC counter system automates fault confinement — a node generating errors is progressively isolated (Active → Passive → Bus-Off) without any software intervention. Monitor TEC/REC during system integration; a node reaching Error Passive state reliably indicates a physical layer issue (wiring, termination, power supply) rather than a software bug.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.