Controller Area Network (CAN)

Introduction


CAN is a serial communication protocol.

CAN is used in vehicles to communicate between different ECUs (Electronic Control Units) in the vehicle.

For example, 
  • If the vehicle door is open when the driver is trying to start the vehicle, Body Control Unit tells Engine Control Unit "Hey, door is open, do not start the vehicle". It sends the status of the door through CAN to engine control unit. Now, engine control unit understands that door is open and it prevents the start, to avoid unintentional start for passenger safety.
  • If an accident happen, airbag control unit opens the airbag and also tells the engine control unit to cut-off the fuel supply, to avoid fire risk.
  • If the road is icy or muddy and if tire is slipping, drag control module tells engine control module to reduce the torque, to increase the road grip.

CAN is basically invented to reduce the wiring harness in the vehicle with the growing number of electronics used and inter-communication between them in the vehicle. With reduced wiring harness, cost and complexity both are reduced.

This was the wiring required without CAN. (In-fact much much more wires than in picture)
 


With CAN, only 2 wires are enough to each ECU.


A typical car uses 4-5 different ECUs - engine control, transmission control, airbag unit, anti-lock braking system (ABS), body control, infotainment system etc.


Modern day cars contain up to 80 different ECUs, including telematics, brake control, suspension control, sun-roof control, battery management, speed control, climate control, seat control etc.




Layered structure of a CAN node / protocol

 



Physical Layer

Physical layer consists of twisted pair wires, connected between different ECUs. Each ECU is considered as a "Node".


  • Physical layer is responsible for converting digital signals (0 or 1) into electrical voltage levels to transmit on the bus.
  • It also converts analog voltage levels received from bus to digital signal, for further processing in transfer layer.



Transfer Layer & Object Layer

  • Transfer layer does message framing - i.e it constructs message from the bits received.
  • Does arbitration - Resolves conflicts between two messages trying to transmit on the bus at the same time.
  • Message validation - calculates CRC for the received message, and compares with the received CRC. If there is any difference, it raises error flag.
  • Acknowledgment - Indicates whether a message transmission or reception is successful or not.
  • Message filtering - Filters the unwanted messages for the node.
                                  Message Filtering

Application Layer

Application layer or software uses the received messages to take appropriate action in its functions, or it does frequently transmits messages which are required for other ECUs.


The CAN Protocol


There are 4 types of CAN frames.
  1. Data Frame
  2. Remote Frame
  3. Error Frame
  4. Overload Frame

1. DATA FRAME

Data frame is used to transmit the 'data' on the CAN bus.
Below is the structure of the data frame.


SOF - 1 bit
  • A dominant bit (Bit 0) in the field marks the start of frame. 
  • It is also used to synchronize the nodes on the bus.
  • Nodes wishing to transmit message are allowed to send SOF only during bus idle time.
  • Bus idle time is part of IFS (inter frame space(3bits) - time gap between 2 CAN frames on the bus).
Bus idle time is shown below.

Arbitration field - 11-bit or 29-bit
  • Contains message ID to determine which node has access to the bus (message prioritization)
  • If two or more nodes are trying to access the bus at the same time, the conflict will be resolved using the message ID. 
  • Identifiers with small number will win the bus arbitration and transmits the message on the bus.
  • First 7 bits of any message ID should not be all 1.
RTR - 1 bit - If any node in the network wants some message which is transmitted by other node, it will send a Remote Transmission Request, with the message ID which is same as message required by it.
  • RTR field in Remote Frames is 1.
  • RTR field in Data Frames is 0.
IDE - 1 bit - Identifier Extension. It is used to specify the frame format, 0 is for standard frame (11-bit message id) and 1 for extended frame (29-bit message id).
Control Field - 6 bits (1 bit r0 + 1 bit r1 + 4 bits DLC)
  • r0, r1 - Reserved bits.  Kept for future use.
  • DLC - 4 bits - Data Length Code - Indicates number of data bytes present in Data Field. Valid sizes are 0 to 8.
Data Field - 8 bytes - Up to 64 bits of application data can be transmitted in a single CAN frame.
CRC Field - 16 bits (15 bits + 1 bit delimiter) Cyclic Redundancy Check. 
  • It contains the checksum of the preceding application data. 
  • Used for error detection.
  • 1 bit CRC delimiter.

ACK field- 2 bits (1 bit acknowledgment + 1 bit delimiter) - 
  • Acknowledgement field contains ACK slot and ACK delimiter.
  • Transmitting message contains ACK bit = 1. 
  • If the data is received correctly by receivers, they will reply by sending 0 during ACK slot (time during which ACK should be sent)



EOF - 7 recessive bits (1) - Indicates the end of frame.

IFS - 3 recessive bits - Inter Frame Space


  • Contains intermission and bus-idle.
  • If the transmitted message is destroyed due to error flags raised by receivers, then suspended message will be re-transmitted during this time.
  • During INTERMISSION no node is allowed to start transmission.
  • During bus-idle time, nodes are allowed to send SOF and thereby getting the bus.

2. REMOTE FRAME

  • Remote frame is exactly same as data frame except it does not contain data field.
  • A node acting as a RECEIVER for certain data can initiate the transmission of the respective data by its source node by sending a REMOTE FRAME.
  • RTR bit of REMOTE FRAMEs is ’recessive’.
  • DLC can be any value between 0 to 8.
  • The polarity of the RTR bit indicates whether a transmitted frame is a DATA FRAME (RTR bit ’dominant’) or a REMOTE FRAME (RTR bit ’recessive’).

3. ERROR FRAME

The ERROR FRAME consists of two different fields. 
  • The first field is given by the superposition of ERROR FLAGs contributed from different nodes. 
  • The second field is the ERROR DELIMITER.

ERROR FLAG
There are 2 forms of an ERROR FLAG.
  • ACTIVE ERROR FLAG
  • PASSIVE ERROR FLAG - Raised by Error Passive nodes -
An 'error active' node detecting an error condition signals this by transmission of an ACTIVE ERROR FLAG, consisting of six consecutive 'dominant' bits. This violates the law of bit stuffing. As a consequence, all other nodes detect an error condition and on their part start transmission of an ERROR FLAG. So the sequence of 'dominant' bits which actually can be monitored on the bus results from a superposition of different ERROR FLAGs transmitted by individual nodes.

An 'error passive' node detecting an error condition tries to signal this by transmission of a PASSIVE ERROR FLAG, consisting of six consecutive 'recessive' bits (unless it is overwritten by dominant bits from other nodes). This makes error passive node can not destroy the message on the bus, but it can raise error flag.

ERROR DELIMITER
The ERROR DELIMITER consists of eight 'recessive' bits.

After transmission of an ERROR FLAG each node sends 'recessive' bits and monitors the bus until it detects a 'recessive' bit. Afterwards it starts transmitting seven more 'recessive' bits.

4. OVERLOAD FRAME

There are two kinds of OVERLOAD conditions, which both lead to the transmission of an OVERLOAD FLAG.
  1. The internal conditions of a receiver, which requires a delay of the next DATA FRAME or REMOTE FRAME.
  2. Detection of a 'dominant' bit during INTERMISSION.
It is same as error frame, consisting of Overload Flag & Delimiter.


Message Validation

Message is valid for transmitter if there is no error until the end of END-OF-FRAME.
If message is corrupted, then it will be retransmitted automatically once the bus is idle. Once again bus arbitration happens.

Message is valid for receivers if there is no error until last but one bit of EOF.

Error Handling

Error Detection

5 different errors can be detected.

1. BIT ERROR
During transmission of message, node that is sending a bit on the bus also monitors the bus. Bit error is reported when the bit value that is monitored is different from the bit value that is sent.

2. STUFF ERROR
If there are 6 consecutive bits of same polarity is detected in the data field, then stuff error is reported.

3. CRC ERROR -
If CRC caluculated by receiver, and that is sent by trasnsmitter are different, then CRC error is reported.

4. ACK ERROR -
ACK error should be detected by transmitter.
If dominant bit is not available on bus during acknowledgement slot, then ACK error is reported.

5. FORM ERROR -
When a fixed-form bit field contains one or more illegal bits, then form error is reported.

Error Signalling

  • A node detecting an error condition signals this by transmitting an ERROR FLAG.
  • Whenever a BIT ERROR, a STUFF ERROR, a FORM ERROR or an ACKNOWLEDGMENT ERROR is detected by any station, transmission of an ERROR FLAG is started at the respective node at the next bit.
  • Whenever a CRC ERROR is detected, transmission of an ERROR FLAG starts at the bit following the ACK DELIMITER.

Fault Confinement

For fault confinement, two error counters are implemented in each node.
1. Transmit Error Count (TEC) - Number of consecutive messages transmitted incorrectly.
2. Receive Error Count (REC) - Number of consecutive messages received incorrectly.

A CAN node may be in one of the  below 3 states -



  • Error Active - Normal operating mode. Node can transmit message or can receive message or can raise Active Error Flag.
  • Error Passive - For a node, if TEC or REC is more than 127, then node is error passive. Node can take part in bus communication. i.e can transmit or receive message. But can not raise Active Error Flag. Instead, it raises Passive Error Flag, containing 6 consecutive RECESSIVE bits. Error passive node can become error active node when both TEC and REC are less than 128.
  • Bus-off - For a node, if TEC is more than 255, then node is bus-off. A node which is 'bus-off'  is permitted to become 'error active' with its error counters both set to 0 after 128 occurrence of 11 consecutive ’recessive’ bits have been monitored on the bus. 

Bit Timing

A CAN Seminar From ESD Electronics -



J1939 Protocol with 29-bit CAN id

 

Questions

  1. What is CAN ?
  2. Why CAN ? Why not use Ethernet or any other communication protocols ?
  3. How CAN works in physical ? Explain Physical Layer of CAN.
  4. What is the Difference between Message based protocol and Address based protocol ?
  5. What are the functions of CAN transceiver chip ?
  6. Why CAN has 120 ohm resistance at each end ?
  7. What is the maximum speed of CAN network ?
  8. How many nodes can be present in a CAN network ?
  9. What are different standard baud rates used for CAN communication ?
  10. Difference between Standard CAN and Extended CAN ?
  11. Explain CAN frame.
  12. What are the different types of CAN frames ?
  13. How much data can be transmitted in a single CAN frame ?
  14. What if I want to transmit more than 8 bytes of data ?
  15. What is the functionality of Data Link Layer in CAN ?
  16. What is the digital logic used in CAN message transmission ? (Wired AND logic)
  17. What is CAN arbitration ? Why arbitration is required ? How it works ?
  18. Why CRC is required ?
  19. Why Acknowledgement field is require ?
  20. Why is Acknowledgement slot ? What is its significance ?
  21. What is intermission field ? Why is it required ?
  22. What are the different types of errors that might be detected ?
  23. What happens when a receiver detects error in the transmitted message?
  24. Explain Error Frame.
  25. What are transmit and receive error counters ?
  26. Error Active node Vs Error Passive node ?
  27. What is bus-off condition ? When it happens ?
  28. How to recover from bus-off condition ?
  29. What is bit stuffing ? Why it is required ?
  30. How synchronization between different nodes happens in the CAN network ?
  31. Hard synchronization Vs Soft synchronization ?
  32. What are different segments in a bit ? Explain bit timing in CAN.
  33. What happens if two nodes send the message with same ID at the same time?
  34. What happens if until end of arbitration two nodes have same address ?
  35. What if a higher priority message is continuously sent on bus ? What happens to lower priority messages?
  36. What happens if a node is shorted to Ground always sending 0 on bus ?
  37. What happens if only transmitter is there in the network ?













* All image sources - Google.com

No comments:

Post a Comment