CAN protocol: Understanding the controller area network

The Controller area network or CAN protocol is a method of communication between electronic devices embedded in a vehicle, such as the engine-management systems, active suspension, central locking, air conditioning, airbags, etc. The idea was initiated by Robert Bosch GmbH in 1983 to improve the quality and safety of automobiles, enhancing automobile reliability and fuel efficiency.

Bosch’s CAN protocol, first released in 1986, also provided advancements in communication. This was significant because developments in the electronics and semiconductor industries at the time led to new technologies but also challenges for engineers in the auto industry. For example, electronics offered more features and complexities, including the ability to “communicate” between devices. Auto engineers were often given the task of incorporating such devices, ensuring they worked without errors.

CAN simplified the process, whereby different electronic modules could communicate with each other by using a common cable.

The need for CAN
A vehicle contains a network of electronic devices that share data and information with one another. A spark-ignition engine, for instance, requires a spark to initiate the combustion chamber. Timing is important here. To ensure this occurs accurately, it “communicates” with the vehicle’s engine control unit, which chooses the ideal time for the ignition to provide the power and fuel efficiency.

Another example of communication between devices includes that of an automobile’s transmission-control unit. It automatically changes a vehicle’s gear in relation to its speed by using data from the engine control unit and various sensors in the system. Every electronic device has an ECU/MCU (electronic/microcontroller control unit) with its own set of rules to share and transfer information.

However, for two or more devices to interact, they must be equipped with hardware and software to properly communicate. Before CAN was used in vehicles, each electronic device was connected to another via wires (or, more specifically, point-to-point wiring). This worked effectively enough when the functions were basic. But one of the major problems for automotive engineers as electronics advanced was linking the ECUs of different devices so that real-time information could be exchanged. The CAN protocol was designed to address this problem.

The protocol set rules by which electronic devices can exchange information with one another over a common serial bus. It reduced the wiring connections and the overall complexity of the system.  

Algorithmic Diagram Showing Connectivity Between Various Devices Using CAN ProtocolAlgorithmic Diagram Showing Connectivity Between Various Devices Using CAN Protocol

The standard technology of the time — asynchronous transmitter/receiver — was unable to support multi-domain communication. A domain is a group of electronic devices that have similar requirements to work properly in the system. For example, a CD/DVD player, GPS, and monitors and displays form a single domain. Similarly, the dashboard, air-conditioning system (or climate control), wipers, lights, and door locks form another domain.

The electronic devices in a vehicle can be classified under different domains and CAN facilitates multi-domain communication, which is a great help to auto engineers.

Table Showing Multi-Domain Communication Supported By CAN ProtocolTable Showing Multi-Domain Communication Supported By CAN Protocol

How is the CAN protocol implemented?

The CAN protocol is a set of rules for transmitting and receiving messages in a network of electronic devices. It defines how data is transferred from one device to another in a network.

Interestingly, CAN was developed with a specific focus on the auto industry but its architecture and advantages have led several other industries (such as the railway, aircraft, and medical sectors) to adopt the protocol as well.

Every electronic device (or node) that communicates via the CAN protocol is connected with one another through a common serial bus, which allows for the transfer of messages. For this data exchange to occur, the nodes first require the necessary hardware and the software.

Graphical Image Showcasing Various Nodes Present In A CAN NetworkGraphical Image Showcasing Various Nodes Present In A CAN Network

As shown in the above figure, a typical CAN network consists of several nodes. Each device has a host controller (ECU/MCU), which is responsible for the function of a specific node, and the CAN controller and transceiver.

The CAN controller converts messages from the nodes per the CAN protocols, which are then transmitted via the CAN transceiver over the serial bus — and vice versa. The controller is a chip that’s embedded inside the host controller of the node or added separately.

The CAN protocol does not follow the master-slave architecture, which means every nodes has access to read and write data on the CAN bus. When the node is ready to send data, it checks the availability of the bus and writes a CAN frame onto the network. A frame is a structure that carries a meaningful sequence of bit or bytes of data within the network.

There are two types of protocols: address or message-based.

  • In an address-based protocol, the data packets contain the address of the device for which a message is intended.

  • In a message-based protocol, every message is identified by a pre-defined ID rather than an address.

The CAN transmitted frame is typically a message-based protocol. A message is a packet of data that carries information. A CAN message is made up of 10 bytes of data, which are organized in a specific structure (called a frame). The data carried in each byte is defined in the CAN protocol.

All nodes using the CAN protocol receive a frame and depending on the node’s ID, the CAN “decides” whether or not to accept it. If multiple nodes send the message at the same time, the node with the highest priority (so, the lowest arbitration ID) receives the bus access. Lower priority nodes must wait until  the bus is available.

Benefits

  • Low cost:

    Since a CAN serial bus uses two wires (with high-volume and low-cost production), it offers a good price-to-performance ratio.

  • Reliable:

    CAN offers excellent error-detection and error-handling mechanisms, which provides highly reliable transmission. It’s also largely immune to electromagnetic interference.

  • Flexible:

    CAN nodes are not limited by the protocol and can be easily connected or disconnected.

  • Fast:

    CAN supports a data rate of 1 MBit/s @ 40m bus length.

  • Multi-master communication:

    Any node can access the bus

  • Fault confinement:

    Faulty nodes do not disturb the communication.

  • Broadcast capabilities:

    Messages can be sent to one /many/all nodes.

  • Standardized:

    ISO has standardized the CAN protocol via ISO-DIS 11898 (for high-speed applications) and ISO-DIS 11519-2 (for low-speed applications). The CAN protocol is also standardized by industry organizations, such as the SAE-Society of Automotive Engineers.

CAN architecture

The CAN protocol uses the existing OSI reference model to transfer data between the nodes connected in a network. The OSI reference model represents a set of seven layers where data passes through during communication between connected devices. The seven-layered structure of the OSI model is reliable and widely used in several communication protocols. 

Each layer has its specific function that supports the layer above and below as described under-

·         Application layer

It serves as a window for users and application processes to access network services. The common functions of the layers are resource sharing, remote file access, network management, electronic messages and so on. 

·        Presentation layer

The most important function of this layer is defining data formats such as ASCII text, EBCDIC text BINARY, BCD and JPEG. It acts as a translator for data into a format used by the application layer at the receiving end of the station.

·         Session layer

It allows to establishing, communicating and terminating sessions between processes running on two different devices performing security, name recognition and logging. 

·         Transport layer

The transport layer ensures that messages are delivered error-free, in sequence, and without loss or duplication. It relieves the higher layer from any concern with the transfer of data between them and their peers.

·        Network layer

It provides end to end logical addressing system so that a packet of data can be routed across several layers and establishes, connects and terminates network connections.

·         Data link layer

It packages raw data into frames transferred from physical layer. This layer is responsible for transferring frames from one device to another without errors. After sending the frame it waits for the acknowledgement from receiving device. Data link layer has two sub layers:

{C1.       MAC (Medium Access Control) layer:  It performs frame coding, error detection, signaling, serialization and de-serialization.  

 LLC (Logical Link Control) layer: The LLC sub layer provides multiplexing mechanisms that make it possible for several network protocols (IP, Decnet and Appletalk) to coexist within a multipoint network and to be transported over the same network medium. It performs the function of multiplexing protocols transmitted by MAC layer while transmitting and decoding when receiving and providing node-to-node flow and error control.

·       Physical layer

The physical layer transmits bit from one device to another and regulates the transmission of bit streams. It defines the specific voltage and the type of cable to be used for transmission protocols. It provides the hardware means of sending and receiving data on a carrier defining cables, cards and physical aspects.

CAN protocol uses lower two layers of OSI i.e. physical layer and data link layer. The remaining five layers that are communication layers are left out by BOSCH CAN specification for system designers to optimize and adapt according to their needs.

Block Diagram Showing Various Layers Of a Nework Using CAN ProtocolBlock Diagram Showing Various Layers Of a Nework Using CAN Protocol

Fig. 7: Block Diagram Showing Various Layers Of a Nework Using CAN Protocol

Function of each part is shown with the figure below.

 

Block Diagram Showing Functions of Various Parts of A CAN Network Block Diagram Showing Functions of Various Parts of A CAN Network

Fig. 8: Block Diagram Showing Functions of Various Parts of A CAN Network 

The concept of the CAN protocol can be understood using the figure above. Every node has a Host controller also known as micro-controller which is a small and low-cost computer .Host controller implements application layer of OSI model. Micro-controller gathers information from other electronic control units like braking, steering, power windows etc. to communicate with other nodes and transfers it to CAN controller.  CAN controller incorporate logical link control and MAC medium access control of data link layer. LLC allows filtering of messages by using unique ID on each message then MAC sub layer frames the message.  Once, framing is done it is followed by arbitration, error detection and acknowledgement that all comes under MAC sub layer of data link. The frame is transferred to CAN trans-receiver, for encoding and decoding. Finally CAN trans-receiver synchronizes with the CAN bus to send the message to anther node.

Terms associated with CAN protocol.

BUS VALUES

Binary values in CAN protocol are termed as dominant and recessive bits.

 

·          CAN define the logic “0” as dominant bit.

·         CAN define the logic “1” as recessive bit.

In the CAN system dominant bit always overwrites the recessive bit.

Message based communication

A Message is packet of data that carries the information to be exchanged between the nodes. Each message in CAN has a unique identification number. The identification number is specified according to the content of the message and stored in message identifier. This identification number is also unique within the network so when the transmitting node places the data on the network for access to all nodes it checks unique ID number to allow the message to pass through the filter and rest are ignored. This is done to save the time spent on sorting. With message based protocol other nodes can be added without re-programming since the units connected to the bus have no identifying information like node addressing. So there is no change needed in the software and hardware of any of the units connected on the bus.

Diagram Showing Message Based Communication in A CAN Protocol Using NetworkDiagram Showing Message Based Communication in A CAN Protocol Using Network

Fig. 9: Diagram Showing Message Based Communication in A CAN Protocol Using Network

Message Framing

Messages in CAN are sent in a format called frames. A frame is defined structure, carrying meaningful sequence of bit or bytes of data within the network. Framing of message is done by MAC sub layer of Data Link Layer .There are two type of frames standard or extended .These frames can be differentiated on the basis of identifier fields. A  CAN frame with 11 bit identifier fields called Standard CAN and with 29 bit identifier field is called extended frame.

Standard frame

Figure Showing How Message Is Framed in A Standard CAN FrameFigure Showing How Message Is Framed in A Standard CAN Frame

Fig. 10: Figure Showing How Message Is Framed in A Standard CAN Frame

Various fields in standard CAN are as follows-

{C·         SOF – Start of Frame bit. It indicates  start of message and used to synchronize the nodes on a bus. A dominant bit in the field marks the start of frame.

·         IDENTIFIER – It serves dual purpose one, to determine which node has access to the bus and second to identify the type of message.

·       RTR – Remote Transmission Request. It identifies whether it’s a data frame or a remote frame .RTR is dominant when it is a data frame and recessive when it is a remote frame.

{C}{·         IDE – Identifier Extension. It is used to specify the frame format. Dominant bit is for standard frame and recessive for extended frame.

{C}·        R0 – Reversed bit.  Not used currently and kept for future use.

{C·        DLC – Data Length Code. It is 4 bit data length code that contains the number of bytes being transmitted.

{·          DATA– Used to store up to 64 data bits of application data to be transmitted.

{C}·        CRC– Cyclic Redundancy Check. The 16-bit (15 bits plus delimiter) cyclic redundancy check (CRC) contains the checksum of the preceding application data for error detection.

{·         ACK – Acknowledge (ACK) field. It compromises of the ACK slot and the ACK delimiter. When the data is received correctly the recessive bit in ACK slot is overwritten as dominant bit by the receiver.

{C}·         EOF– End of Frame (EOF). The  7-bit field marks the end of a CAN frame (message) and disables

Bit – stuffing, indicating a stuffing error when dominant.

{C}·         IFS – Inter Frame Space that specifies minimum number of bits separating consecutive messages. It provides the intermission between two frames and consists of three recessive bits known as intermission bits. This time allows nodes for internal processing before the start of next frame.

EXTENDED CAN

Extended CAN Network Parts and Their FunctionalitiesExtended CAN Network Parts and Their Functionalities

Fig. 11: Extended CAN Network Parts and Their Functionalities

It is same as 11-bit identifier with some added fields

{C·        SRR- Substitute Reverse Request. The SRR bit is always transmitted as a recessive bit to ensure that, in the case of arbitration between a Standard Data Frame and an Extended Data Frame, the Standard Data Frame will always have priority if both messages have the same base (11 bit) identifier. 

{·         R1- It is another bit not used currently and kept for future use.

Message frame

There are four different frames which can be used on the bus.

Data frames– These are most commonly used frame and used when a node transmits information to any or all other nodes in the system.  Data Frames consist of fields that provide additional information about the message as defined by the CAN specification. Embedded in the Data Frames are Arbitration Fields, Control Fields, Data Fields, CRC Fields, a 2-bit Acknowledge Field and an End of Frame.

 

Data Frames Used In A CAN NetworkData Frames Used In A CAN Network

Fig. 12: Data Frames Used In A CAN Network

·        Remote frames – The purpose of the remote frame is to seek permission for the transmission of data from another node. This is similar to data frame without data field and RTR bit is recessive.  For example, the microprocessor controlling the central locking on your car may need to know the state of the transmission gear selector from the power train controller.

·         Error frames – If transmitting or receiving node detects an error, it will immediately abort transmission and send error frame consisting of an error flag made up of six dominant bits and error flag delimiter made up of eight recessive bits.  The CAN controller ensures that a node cannot tie up a bus by repeatedly transmitting error frame.

Error Frames Used In A CAN NetworkError Frames Used In A CAN Network

Fig. 13: Error Frames Used In A CAN Network

·         Overload frame-It is similar to error frame but used for providing extra delay between the messages.  An Overload frame is generated by a node when it becomes too busy and is not ready to receive.

Overload Frame Present In A CAN NetworkOverload Frame Present In A CAN Network

Fig. 14: Overload Frame Present In A CAN Network

Arbitration

It is a mechanism which resolves the conflict when two or more nodes try to send the message at the same time. In this technique whenever the bus is free any unit can transmit a message. If two or more units starts transmitting at the same time access to the bus is conflicted, but this problem can be solved by arbitration using identifier. During arbitration every transmitter compares the value of transmitted bit with bit value on the bus. If the bit value is same, the node continues to send the bits. But at any time if transmitted bit value is different from bus value the dominant bit overwrites the recessive bits. The arbitration field of the CAN message consists of an 11- or 29-bit identi?er and a remote transmission (RTR) bit. The identifier having lowest numerical value has the highest priority. RTR simply distinguishes between remote frame for which RTR is recessive and data frame for which RTR is dominant. If both data frame and remote frame with the same identifier is initiated at the same time data frame will prevail over remote frame. With the concept of arbitration neither information nor time is lost.

 

CAN as a CSMA protocol

CSMA is a carrier sense, multiple-access protocol in which node verifies the absence of traffic before transmitting on a shared medium such as electrical bus.  In CSMA each node on a bus waits for a specific time before sending the message. Once this wait period is over every node has equal opportunity to send the message. Based on pre-programmed priority of each message in identifier field i.e. highest priority identifier wins the bus access. It is implemented on the physical layer of OSI model. Let us understand CSMA with an example. In a discussion every person gets an equal opportunity to voice their thoughts however when a person is talking others keep quiet and listens and waits for their chance to speak (carrier sense). But if two or more people start speaking at the same time then they detect the fact and quit speaking (collision detection).

Error Control

Error Checking and Fault Confinement

This is one of the attributes of CAN that makes it robust. CAN protocol has five methods of error checking, out of which three are at message level while other two are at bit level. Every frame is simultaneously accepted or rejected by every node in the network. If a node detects an error it transmits an error flag to every node and destroys the transmitted frame and the transmitting node resends the frame

Message level

CRC check

In this stage a 15-bit cyclic redundancy check value is calculated by transmitting node and is transmitted in the CRC field. This value is received by all nodes. Then all the nodes calculate CRC value and matches the results with the transmitted value. If values differ than an Error Frame is generated. Since one of the nodes did not receive the message properly it is resent.

ACK slots

When transmitting node sends a message, a recessive bit is sent in acknowledgement slot. After message is received acknowledge slot is replaced by dominant bit which would acknowledge that at least one node correctly received the message. If this bit is recessive, then none of the node has received the message properly.

Form Error

End of frame, Inter-frame space, Acknowledge Delimiter are fields that are always recessive, if any node detects dominant bit in one of these fields than CAN protocol calls it a violation and a Form Frame is generated and original message is resent after certain period.

Bit level

Stuff error

Bit stuffing – It is a very common technique used in telecommunication and data transmission to insert non -informative bits to have same  bit rates or to fill the frames .These extra bits are removed by data link layer to retrieve the original message. This same technique is used in bit error.CAN bus is never idle because it uses NRZ method. After five consecutive bits of the same value, a bit with a complement or opposite value is stuffed into the bit stream. If six bits of the same value are detected between SOF and CRC delimiter, error frame is generated. Upon detection of errors, the transmission is aborted and frame is repeated.  If errors continue, then the station or node may switch itself off to prevent the bus from being tied up.

Bit error

A node that is sending the bit always monitors the bus. If the bit sent by transmitter differs from the bit value on the bus then error frame is generated. But there is an exception in case of arbitration field or Acknowledge slot where a recessive bit is sent and a dominant bit is received. Then no Bit Error is occurs when dominant bit is monitored.

Conclusion

CAN protocol initially developed for in-vehicle networking of automobiles has expanded its applications in various other industries. The application started for luxurious cars is now being used in heavy duty vehicles like trucks, buses, trains and rail vehicles. The unique feature of CAN that allows various electronic units to communicate with each other made it important in healthcare domain. For example intensive care units and operating rooms where time and communication is of utmost importance. Entertainment industry also used CAN protocols to improve features in studios to control lights and door system and to control stage of theatres, event halls etc. Gambling machines and toys are other examples in entertainment field. In the field of science the high energy experiments and astronomical telescope use CAN in embedded network.

 

Next Article