Introduction To CAN BUS Error Handler
In order to prevent malfunctioning nodes from disturbing, or even blocking, an entire CAN network system, the CAN protocol implements a sophisticated fault confinement mechanism. The CAN protocol is intended to be orthogonal, i.e. all nodes address faults in the same manner. Fault confinement is provided where each node constantly monitors its performance with regard to the successful and unsuccessful message transactions.
Each CAN controllers are having their own CAN BUS error handler. To handle this, each CAN controller is having two counter register nothing but two 8-bit buffer (memory). It can store 0 – 255 decimal value. This is called Transmit Error Counter (TEC) and a Receive Error Counter (REC) . If there are any error occurs among the 5 errors, it will increase the TEC or REC as per the type of error.
A micro-controller can have multiple CAN controllers. Each CAN controller works independently with a separate CAN network. Sometimes we say that a network or bus or channel. if any error or anything will happen that will affect or getting communicated with the network that is connected with that particular CAN controller.
Error Counter Registers In CAN Controller
A Transmit Error Counter (TEC) and a Receive Error Counter (REC) create a metric for the communication quality based on historic performance. Each node will act on its own bus status based on its individual history. As a result, a graceful degradation allows a node to disconnect itself from the bus i.e. stop transmitting.
This means that a permanently faulty device will cease to be active on the bus (go into Bus Off state), but communications between other nodes can continue unhindered. If the bus media is severed, shorted, or suffers from some other failure mode, the ability to continue communications are dependent upon the condition and the physical interface used.
What Is Fault Confinement In CAN Protocol
The fault confinement is the checking mechanism that makes it possible to distinguish between short disturbances (e.g. switching noise from the nearby power cable couples into the transmission media) and permanent failures (e.g. a node is malfunctioning and disturbs the bus). The manipulation of the error counters are asymmetric.
On a successful transmission or reception, of a message, the respective error counter is decremented if it had not been at zero. In the case of the transmit or receive an error, the counters are incremented, but by a value greater than the value they would be decrement by following a successful message transaction.
If the node detects a local error condition (e.g. due to local conducted noise, application software, etc.), its resulting error flag (primary error flag) will subsequently cause all other nodes to respond with an error flag too (secondary error flags). It is important that a distinction is made between the nodes that detected an error first and the nodes which responded to the primary error flag.
If a node transmits an active error frame, and it monitors a dominant bit after the sixth bit of its error flag, it considers itself as the node that has detected the error first. In the case where a node detects errors first too often, it is regarded as malfunctioning, and its impact on the network has to be limited.
Therefore, a node can be in one of the three possible error states:
- Error Active State.
- Error Passive State.
- Error Bus-Off State.
Error Active State In CAN Protocol
When a CAN device is powered on, it starts in the Error Active State. A device in the Error Active State can normally take part in the CAN communication. It also transmits an active error flag when an error is detected. This Active Error Flag (means the sequence of dominant 0 bits) causes the current frame transmission to abort, resulting in a subsequent retransmission of the same message.
Both of its error counters (TEC and REC) are less than 128 in Error Active State. It takes part fully in bus communication and signals an error by the transmission of an active error frame. This consists of a sequence of 6 dominant bits followed by 8 recessive bits, all other nodes respond with the appropriate error flag, in response to the violation of the bit stuffing rule.
Error Passive State In CAN Protocol
If either the Transmit Error Counter or the Receive Error Counter greater than 127, the CAN device transits into the Error Passive State. A device in Error Passive State can still take part in communication, but transmits a Passive Error Flag when any error detected. This Passive Error Flag (sequence of recessive 1 bits) generally does not abort the frames transmitted by other devices like Error Active Frames. Since the Passive Error Flags cannot prevail over any activity on the bus line, they are noticed only when the Error Passive Device is transmitting a frame. Thus, if the ECU or device which is in Error Passive State detects a receive error on a frame which is received successfully by other devices, the frame is not retransmitted.
Furthermore, an error passive node has to wait an additional time (Suspend Transmission Field, 8 recessive bits after Intermission Field) after the transmission of a message, before it can initiate a new data. The primary passive error flag consists of 6 passive bits and thus is “transparent” on the bus and will not “jam” communications.
A very special & excepetional condition in error passive case is that if the ECU detects an acknowledge, it does not increament its Transmit Error Counter (TEC). So the ECU does not enters into the Bus-Off state in this case. Thats why, you might have seen that in your working environment, when you didn’t connected any device into the network, your ECU will continuosly send the frames but does not detects bus-off & stays in Error Passive State.
Bus-Off State In CAN Protocol
If the Transmit Error Counter of the CAN controller exceeds 255, it goes into the bus off state. It is disconnected from the bus (using internal logic) and does not take part in the bus activities anymore. In simply we can say that physically connected and logically disconnected from the BUS. In order to reconnect the protocol controller, a so-called?Bus Off? recovery sequence has to be executed. This usually involves the re-initialization and configuration of the CAN controller by the host system, after which it will wait for (128 * 11) recessive bit times before it commences communication again.
Error Types In CAN Protocol
The CAN protocol is having the capability of detecting the error. But it can not correct the error if it happens. So if the error happens the detected node or ECU will send an error frame to the CAN network. So there are 5 types of error in CAN protocol that is explained in our new article CAN Protocol Error Types.
CAN Error Confinement Management Rules
- When a receiver detects an error, the REC will be increased by 1, except when the detected error was a Bit Error during the sending of an Active Error Flag or an Overload Flag.
- When a receiver detects a dominant bit as the first bit after sending an Error Flag, the REC will be increased by 8.
- When a transmitter sends an Error Flag, the TEC is increased by 8. Exception 1: If the transmitter is Error Passive and detects an ACK Error because of the not detecting a dominant ACK and does not detect a dominant bit while sending its Passive Error Flag. Exception 2: If the transmitter sends an Error the Flag because a Stuff Error occurred during arbitration, and should have been recessive, and has been sent as recessive but monitored as dominant.
- If the transmitter detects a Bit Error while sending an Active Error Flag or an Overload Frame, the TEC is increased by 8.
- If a receiver detects a Bit Error while sending an Active Error Flag or an Overload Flag, the REC is increased by 8.
- Any node tolerates up to 7 consecutive dominant bits after sending an Active Error Flag, Passive Error Flag, or Overload the Flag. After detecting the fourteenth consecutive dominant bit (in case of an Active Error Flag or an Overload Flag) or after detecting the eighth consecutive dominant bit following a Passive Error the Flag, and after each sequence of additional eight consecutive dominant bits, every transmitter increases its TEC by 8 and every receiver increases its REC by 8.
- After successful transmission of a frame (getting ACK and no error until EOF is finished), the TEC is decreased by 1 unless it was already 0.
- After the successful reception of a frame (reception without error up to the ACK Slot and the successful sending of the ACK bit), the REC is decreased by 1, if it was between 1 and 127. If the REC was 0, it stays 0, and if it was greater than 127, then it will be set to the value between 119 and 127.
- A node is Error the Passive when the TEC equals or exceeds 128, or when the REC equals or exceeds 128. An error condition letting a node become Error Passive causes the node to send an Active Error the Flag.
- A node is Bus Off when the TEC is greater than or equal to 256.
- An Error Passive node or ECU becomes Error Active again when both the TEC and the REC values are less than or equal to 127.
- A node which is Bus Off is permitted to become Error Active (no longer Bus Off) with its error counters both set to 0 after 128 occurrences of 11 consecutive recessive bits have been monitored to the bus.