askvity

What is the Error Frame in CAN?

Published in CAN Protocol Error Handling 5 mins read

An Error Frame in CAN is a special type of message transmitted by a CAN node when it detects an error on the network. Its primary purpose is to signal to all other nodes that a communication error has occurred, causing the current data or remote frame transmission to be aborted.

According to the CAN protocol definition, an error frame is one of the four types of frames defined in the CAN protocol. Its primary purpose is to signal to other nodes on the network that the current data frame is erroneous. This ensures data integrity across the network by preventing nodes from processing corrupted messages.

Purpose of the CAN Error Frame

The fundamental role of the error frame is to act as an immediate network-wide alert system. When a node detects an error in a transmitted or received message, it intentionally violates the CAN protocol's bit-stuffing rule by sending a specific bit sequence – the error frame. This sequence is designed to be different from any valid CAN message structure, ensuring that all other nodes on the bus recognize it as an error condition.

Upon detecting an error frame, all active nodes discard the current message being processed and become aware that an error occurred. This mechanism ensures that inconsistent or corrupted data is not propagated across the network.

Structure of an Error Frame

An error frame consists of two main fields:

  1. Error Flag: This is sent by any node that detects an error. There are two forms:
    • Active Error Flag: Transmitted by a node in the 'Error Active' state (normal state). It consists of six consecutive dominant bits. This sequence violates the bit-stuffing rule (which allows a maximum of five consecutive identical bits), thus being recognized as an error by all nodes.
    • Passive Error Flag: Transmitted by a node in the 'Error Passive' state (a state indicating a higher error count). It consists of six consecutive recessive bits. Passive nodes do not disrupt bus communication as strongly, but their error flags are still followed by the error delimiter.
  2. Error Delimiter: This follows the error flag and consists of eight recessive bits. This field provides time for other nodes to check for errors and synchronize before the bus resumes normal communication.

Multiple nodes detecting the same error might transmit their error flags simultaneously. The dominant bits of active error flags will overlay any passive flags or recessive bits from other nodes, resulting in the dominant sequence being seen by all.

How Errors Trigger an Error Frame

Several types of errors can cause a node to transmit an error frame:

  • Bit Error: A transmitter sends a bit and monitors the bus, finding the bus value is different from the transmitted value (except during arbitration or when sending the ACK slot as a transmitter).
  • Stuff Error: More than five consecutive identical bits are detected in a message field that is subject to bit-stuffing (Start of Frame, Arbitration Field, Control Field, Data Field, CRC Field).
  • CRC Error: The calculated Cyclic Redundancy Check (CRC) value of a received message does not match the CRC value contained in the message's CRC field.
  • Acknowledgement Error: The transmitter does not detect a dominant bit in the ACK slot, meaning no receiver successfully received the message without error.
  • Form Error: A fixed-form field contains an illegal value (e.g., stuff errors in fields not subject to bit-stuffing like CRC Delimiter, ACK Delimiter, End of Frame).

Node Reaction to an Error Frame

When a node detects an error frame:

  • It aborts processing the current message.
  • It increments its internal error counters (Transmit Error Counter - TEC, and Receive Error Counter - REC).
  • Depending on its error state (Error Active, Error Passive, Bus-Off), it may attempt to retransmit the message that caused the error, provided it was the transmitter.

This retransmission mechanism, coupled with the error state management, is crucial for the self-healing capability of a CAN network.

Error States and Handling

CAN nodes manage their error status using TEC and REC counters. The values of these counters determine the node's error state:

  • Error Active: The normal state. TEC and REC are below 128. Nodes transmit Active Error Flags (6 dominant bits).
  • Error Passive: TEC or REC is between 128 and 255. Nodes transmit Passive Error Flags (6 recessive bits) and have limited participation in arbitration.
  • Bus-Off: TEC exceeds 255. The node is disconnected from the bus and cannot transmit or receive messages. It must wait for a certain number of events or be reset to re-enter the Error Active state.

The error frame is a vital component of the CAN protocol's robust error detection and fault confinement mechanisms, ensuring reliable data communication even in noisy environments.

Related Articles