How CAN Bus Bit Stuffing Preserves Synchronization
The Controller Area Network (CAN) bus protocol relies on a mechanism known as bit stuffing to maintain clock synchronization across all communicating nodes and detect transmission errors. Because CAN uses Non-Return-to-Zero (NRZ) bit coding, long sequences of identical binary values (consecutive 0s or 1s) lack the signal transitions needed for nodes to recalibrate their internal clocks. Bit stuffing solves this by automatically inserting a complementary bit after five consecutive identical bits, ensuring regular voltage transitions for synchronization while remaining transparent to the upper data layer.
The Synchronization Challenge in NRZ Encoding
In binary transmission using NRZ encoding, a logical ‘0’ (dominant state) and a logical ‘1’ (recessive state) maintain a constant voltage level for the entire duration of the bit. While NRZ is bandwidth-efficient, it does not include an embedded clock line.
Nodes on a CAN network rely on signal state transitions—specifically
the edges from recessive to dominant or dominant to recessive—to
resynchronize their internal clock oscillators. If a transmitter sends a
long sequence of identical bits, such as 00000000 or
11111111, the physical bus line remains at a static voltage
level. Due to minor oscillator tolerances and temperature variations
between microcontrollers, receiving nodes would gradually drift out of
sync, leading to bit-timing errors and data corruption.
How the Bit-Stuffing Mechanism Works
Bit stuffing operates automatically at the physical/data-link layer boundary during the transmission of CAN frames.
- Transmission (Stuffing): While generating the frame
fields (from the Start of Frame through the Cyclic Redundancy Check
sequence), the transmitter monitors the outgoing bitstream. If it
transmits five consecutive bits of the same logical polarity (e.g.,
11111or00000), the hardware automatically injects a sixth “stuff bit” of the opposite polarity (e.g.,111110or000001). - Reception (De-stuffing): The receiving node monitors the incoming bitstream. When it detects five consecutive bits of the same logical value, it checks the sixth bit. If the sixth bit is the opposite value, the receiver recognizes it as a stuff bit, uses the transition for clock resynchronization, strips the stuff bit from the sequence, and processes only the original data.
Preserving Synchronization in the Binary System
In the binary system used by CAN, bit stuffing guarantees that a signal transition occurs at least once every ten bit times (five identical bits followed by a stuff bit, potentially followed by another set of inverse bits).
When the voltage level changes at the stuff bit edge, the CAN controller’s bit-timing logic triggers “phase resynchronization.” The controller adjusts its internal Phase Buffer Segments (Phase_Seg1 and Phase_Seg2) to align the nominal sample point directly with the center of incoming bits. This continuous realignment ensures that every node samples the bus value accurately, regardless of payload length or clock jitter.
Error Detection and Frame Demarcation
Bit stuffing also provides an integrated error-checking feature:
- Stuff Errors: If a receiver detects six consecutive bits of the identical logical level within a stuffed field, the rule has been violated. The receiver immediately treats this as a “Stuff Error,” invalidates the frame, and broadcasts an active error frame on the bus.
- Fixed-Form Fields: Certain control sections of the
CAN frame do not use bit stuffing, including the CRC Delimiter, ACK
Slot, ACK Delimiter, and the End of Frame (EOF) field. The EOF consists
of seven consecutive recessive bits (
1111111). Because bit stuffing never allows seven consecutive identical bits during normal data transmission, the EOF reliably signals the absolute end of the frame without ambiguity.