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 engine management systems, active suspension, central locking, air conditioning, airbags, and more. The idea was proposed by Robert Bosch GmbH in 1983 to improve the quality and safety of automobiles and to increase their reliability and fuel efficiency.
Bosch's CAN protocol, first released in 1986, also provided advances in communications. This was significant because developments in the electronics and semiconductor industries at the time brought new technologies, but also challenges for engineers in the automotive industry. For example, electronics offer more functionality and complexity, including the ability to "communicate" between devices. Automotive engineers are often tasked with incorporating these devices to ensure they work without errors.
CAN simplifies this process, and different electronic modules can communicate with each other by using a common cable.
Demand for CAN Cars contain a network of electronic devices that share data and information with each other. For example, a spark ignition requires a spark to start the combustion chamber. Here, timing matters. To ensure this happens exactly, it "communicates" with the vehicle's engine control unit to select the ideal ignition timing for power and fuel efficiency.
Another example of device-to-device communication includes the communication of an automobile transmission control unit. It uses data from the engine control unit and various sensors in the system to automatically change the vehicle's gears in relation to their speed. Every electronic device has an ECU/MCU (Electronic/Microcontroller Control Unit) which has its own set of rules for sharing and transmitting information.
However, for two or more devices to interact, they must be equipped with hardware and software to communicate properly. Before CAN was used in automobiles, each electronic device was connected to another device by wires (or, more specifically, point-to-point wiring). This approach works well enough when the functionality is basic. But with advances in electronics, one of the major problems facing automotive engineers is how to connect ECUs from different devices so that information can be exchanged in real time. The CAN protocol is designed to solve this problem.
insert image description here

An example of a point-to-point wiring connection in the CAN protocol.
This protocol sets the rules by which electronic devices can exchange information with each other over a common serial bus. It reduces wiring connections and overall system complexity.
insert image description here

Algorithm diagram showing connections between devices using the CAN protocol.
Standard techniques for time-asynchronous transmit/receive cannot support multi-domain communication. A domain is a group of electronic devices that have similar requirements to function properly in a system. For example, CD/DVD players, GPS, and monitors and displays form a domain. Likewise, the dashboard, air conditioning system (or climate control), wipers, lights, door locks form another area.
The electronic equipment on the car can be divided into different fields, and the CAN bus facilitates communication in many fields, which is of great help to automotive engineers.
The electronic equipment on the car can be divided into different fields, and the CAN bus facilitates communication in many fields, which is of great help to automotive engineers.
insert image description here

Vehicle multi-domain communication supported by the CAN protocol.
The CAN protocol is a set of rules for sending and receiving messages in a network of electronic devices. It defines how data is transferred from one device to another in the network.
Interestingly, CAN was developed with a specific focus on the automotive industry, but its architecture and advantages have led to the adoption of the protocol in several other industries such as railways, aircraft, and the medical sector.
insert image description here

A simplified version of the CAN protocol.
Each electronic device (or node) that communicates via the CAN protocol is connected to each other via a common serial bus, allowing the transmission of messages. In order to carry out this data exchange, nodes first need the necessary hardware and software.
insert image description here

Various nodes in a CAN network.
As shown in the figure above, a typical CAN network consists of several nodes. Each device has a host controller (ECU/MCU) which is responsible for the functions of the specific node, as well as the CAN controller and transceiver.
The CAN controller converts messages from nodes according to the CAN protocol and then transmits them on the serial bus via the CAN transceiver, and vice versa. A controller is a chip embedded in the node's host controller or added separately.
The CAN protocol does not follow a master-slave structure, which means that each node can 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 CAN frames to the network. A frame is a structure that carries a meaningful sequence of bits or bytes of data in a network.
There are two types of protocols: address protocols or message-based protocols.
In address-based protocols, the data packet contains the address of the device for which the message is addressed.
In message-based protocols, each message is identified by a predefined ID instead of an address.
CAN transmission frames are usually a message-based protocol. A message is a packet containing information. CAN messages consist of 10 bytes of data organized in a specific structure called a frame. The data in each byte is defined in the CAN protocol.
All nodes using the CAN protocol receive a frame, and CAN "decides" whether to accept it or not based on the node's ID. If multiple nodes send messages at the same time, the node with the highest priority (ie, the node with the lowest quorum ID) will receive the bus access. Low priority nodes must wait until the bus is available.
benefit

  • Low cost: Since the CAN serial bus uses two wires (with high capacity and low cost of production), it offers a good price/performance ratio.
  • Reliability: CAN provides excellent error detection and error handling mechanisms, provides highly reliable transmission, and is largely immune to electromagnetic interference.
  • Flexible: CAN nodes are protocol independent and can be easily connected or disconnected.
  • Fast: CAN supports a data rate of 1mbit/s@40m bus length.
  • Multi-master communication: any node can access the bus
  • Failure Limits: A failed node does not interfere with communication.
  • Broadcast Capability: Messages can be sent to one/multiple/all nodes.
  • Standardization: ISO standardized the CAN protocol through ISO-dis 11898 (for high-speed applications) and ISO-dis 11519-2 (for low-speed applications). The CAN protocol is also standardized by industrial organizations, such as the Society of Automotive Engineers.
    CAN Architecture
    The CAN protocol uses the existing OSI reference model to transfer data between nodes connected in a network. The OSI reference model represents a set of seven layers through which data passes during communication between connected devices. The seven-layer structure of the OSI model is reliable and widely used in a variety of communication protocols.
    insert image description here

CAN architecture.
Each layer has its specific function and supports the layers above and below as described below
Application layer
It is the window for users and applications to access network services. Its common functions include resource sharing, remote file access, network management, electronic messaging, and more.
Presentation Layer
The most important function of this layer is to define data formats such as ASCII text, EBCDIC text BINARY, BCD and JPEG. It acts as a data converter, converting the data into the format used by the application layer on the receiving end.
Session layer
It allows 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 in-order, error-free, and without loss or duplication. It relieves the higher layers of any concern with data transfer between them.
Network layer
It provides an end-to-end logical addressing system so that a packet can be routed across multiple layers and establish, connect, and terminate network connections.
Data Link Layer
It packs raw data into frames that are transmitted from the physical layer. This layer is responsible for transferring frames from one device to another without errors. After sending the frame, it waits for an acknowledgment from the receiving device. The data link layer has two sublayers:
{ C1.MAC layer: It performs frame encoding, error detection, signaling, serialization and deserialization.
LLC (Logical Link Control) Layer: The LLC sublayer provides a multiplexing mechanism that enables multiple network protocols (IP, Decnet, and Appletalk) to coexist in a multipoint network and transmit over the same network medium. It completes the transmission and decoding functions of the multiplexing protocol transmitted by the MAC layer while receiving and providing node-to-node traffic and error control.
physical layer
The physical layer transfers bits from one device to another and regulates the transmission of the bit stream. It defines the specific voltage and cable type used for the transmission protocol. It provides a hardware method for sending and receiving data on a carrier that defines the cable, card and physical aspects.
The CAN protocol uses two lower OSI layers, the physical layer and the data link layer. The remaining five layers are communication layers, and the Bosch CAN specification provides system designers with communication layers that can be optimized and adjusted as needed.
insert image description here

Figure 7: Block diagram showing the layers of the network using the CAN protocol
The function of each part is shown in the figure below.
insert image description here

Figure 8: Block diagram showing the function of each part of the CAN network
The concept of the CAN protocol can be understood with the diagram above. Each node has a host controller, also called a microcontroller, which is a small, low-cost computer. The host controller implements the application layer of the OSI model. The microcontroller collects information from other electronic control units (such as brakes, steering, power windows, etc.), communicates with other nodes, and transmits to the CAN controller. The CAN controller combines the logical link control of the data link layer and the MAC medium access control. LLC allows filtering of messages using the unique ID of each message, and then MAC sublayer frames messages. Once the architecture is complete, arbitration, error detection and acknowledgment follow, all from the MAC sublayer of the data link. The frame is transmitted to the CAN transmit receiver for encoding and decoding. Finally the CAN transmit receiver synchronizes with the CAN bus and sends the message to another node.
Terminology related to the CAN protocol.
Bus value
The binary value in the CAN protocol is divided into dominant bits and recessive bits.
CAN defines a logic "0" as a master bit.
CAN defines a logic "1" as a recessive bit.
Dominant bits always override recessive bits in CAN systems.
Message-Based Communication
A message is a data packet that carries information exchanged between nodes. Every message in CAN has a unique identification number. The identification number is specified according to the content of the message and is stored in the message identifier. This identification number is also unique within the network, so when a transport node puts data on the network to visit all nodes, it checks for the unique ID number to allow the message to pass through the filter and ignore the rest. This is done to save time in sorting. Using a message-based protocol, other nodes can be added without reprogramming, because the units connected to the bus do not have identifying information like node addressing. Therefore, neither the software nor the hardware of any unit connected on the bus needs to be changed.
insert image description here

Figure 9: Schematic diagram of message-based network CAN protocol communication

information frame

Messages in CAN are sent in a format called a frame. A frame is a defined structure that carries a meaningful sequence of bits or bytes of data in the network. The MAC sublayer of the data link layer is responsible for framing the message. There are two types of frame standard or extension. These frames can be distinguished based on the identifier field. A CAN frame with an 11-bit identification field is called a standard CAN, and a CAN frame with a 29-bit identification field is called an extended frame.
standard framework
insert image description here

Figure 10: Diagram showing how information is constructed in a standard CAN frame.
The various fields in standard CAN are as follows -
{ c SOF - start of frame bits. It indicates the start of a message and is used to synchronize nodes on the bus. The dominant bit in the field marks the start of the frame.
IDENTIFIER - It serves two purposes, one to determine which node has access to the bus and another to identify the type of message.
Remote transfer request. It can identify data frame or remote frame. RTR is dominant in data frames and recessive in remote frames.
{ c }{ IDE - Identifier expansion. It is used to specify the frame format. Standard boxes are dominant bits, and extended boxes are recessive bits.
{ c } R0 - Reverse bit. Not currently in use and saved for future use.
{ c } DLC - Data Length Code. It is a 4-bit data length code containing the number of bytes being transferred.
{ c } DATA - Used to store up to 64 bits of application data to be transferred.
{ c } CRC - Cyclic Redundancy Check. The 16-bit (15-bit plus delimiter) Cyclic Redundancy Check (CRC) contains the checksum of the application data previously used for error detection.
ACK-Acknowledge (ACK) field. It takes into account ACK slots and ACK separators. When the data is received correctly, the receiver rewrites the recessive bits in the ACK slot to dominant bits.
c } EOF - End of Frame (EOF). The 7-bit field marks the end of the CAN frame (message) and disables
bit stuffing, indicating a stuffing error when dominant.
{ c } IFS-Interframe space, specifying the minimum number of bits to separate consecutive messages. It provides a pause between two frames and consists of three recessive bits called the pause bit. This time allows the node to do internal processing before the next frame starts.
Extended CAN
insert image description here

Figure 11: Extended CAN network components and their functions
It is the same as the 11-bit identifier with the addition of some fields
{ c SRR - instead of 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, if two messages have the same radix (11-bit) identifier, the standard data frame always has priority.
{ R1 - This is another bit that is not currently used, saved for future use.
Message Frames
There are four different frames that can be used on the bus.
Data Frame - This is the most commonly used frame and is used when a node transmits information to any or all other nodes in the system. A data frame consists of fields that provide additional information about the messages defined by the CAN specification. Arbitration field, control field, data field, CRC field, 2-bit acknowledgement field and frame end field are embedded in the data frame.
insert image description here

Figure 12: Data Frames Used in CAN Networks
Remote Frames - The purpose of remote frames is to seek permission for data transmission from another node. This is similar to a data frame without a data field, the RTR bit is recessive. For example, a microprocessor that controls a car's central locking may need to know the state of the transmission gear selector from the powertrain controller.
Error frame - If the sending node or the receiving node detects an error, it will immediately abort the transmission and send an error frame, which includes an error flag consisting of six dominant bits and an error flag delimited by eight recessive bits symbol. The CAN controller ensures that the node does not occupy the bus by repeatedly sending error frames.
insert image description here

Figure 13: Error Frames Used in CAN Networks
Overload Frame - It is similar to Error Frame but used to provide extra delay between messages. When a node becomes too busy to be ready to receive, it generates a reload frame.
insert image description here

Figure 14: Overload Frames in CAN Networks
It is a mechanism for resolving collisions when two or more nodes send messages at the same time. In this technique, any unit can transmit messages as long as the bus is free. If two or more units start a transfer at the same time, the bus accesses are conflicting, but this problem can be resolved by arbitration using identifiers. During arbitration, each transmitter compares the value of the transmitted bit on the bus with the value of the bit on the bus. If the bit values ​​are the same, the node continues to send bits. But at any time, if the transmitted bit value differs from the bus value, the dominant bit overrides the recessive bit. The arbitration field of the CAN message consists of an 11-bit or 29-bit identi?er and a remote transfer (RTR) bit. The identifier with the lowest numerical value has the highest priority. RTR simply distinguishes remote frames where RTR is recessive and data frames where RTR is dominant. If a data frame and a remote frame with the same identifier are started at the same time, the data frame takes precedence over the remote frame. With the concept of arbitration, neither information nor time is lost.
CAN for CSMA Protocol
CSMA is a carrier sense, multiple access protocol in which nodes verify that there is no traffic before transmitting on a shared medium such as an electronic bus. In CSMA, each node on the bus waits a specific amount of time before sending a message. Once this waiting period is over, each node has an equal chance to send a message. Bus access is granted based on the pre-programmed priority of each message in the identifier field, i.e. the identifier with the highest priority. It is implemented on the physical layer of the OSI model. Let us understand CSMA with an example. In discussions, everyone has an equal opportunity to express their ideas, but while one person speaks, the others remain silent, listening and waiting for their chance to speak. But if two or more people start talking at the same time, then they will find the truth and stop talking (collision detection).

error control

Error Checking and Fault Limiting
This is one of the properties of CAN that makes it more robust. The CAN protocol has five error detection methods, three at the message level and two at the bit level. Each node in the network accepts or rejects each frame simultaneously. If a node detects an error, it sends an error flag to each node and destroys the sent frame, the sending node resends the frame
Message Level
Cyclic Redundancy Check
At this stage, a 15-bit cyclic redundancy check is calculated by the sending node Check, then send in the CRC field. This value is received by all nodes. All nodes then calculate the CRC value and match the result with the transmitted value. If the values ​​are different, an error frame is generated. Since one of the nodes did not receive the message correctly, the message will be resent.
Acknowledgement Slot
When the sending node sends a message, it sends recessive bits in the acknowledgment slot. After the message is received, the acknowledgement slot is replaced by the master bit, which will confirm that at least one node received the message correctly. If this bit is recessive, then all nodes have not received the message correctly.
Form Error
End of Frame, Interframe Space, Acknowledgement Separator are fields that are always recessive, if any node detects a dominant bit in these fields, the CAN protocol calls it a violation and generates a form frame after a certain amount of time and resend the original message.
Bit Level
Fill Error
Bit Stuffing - A very common technique used in communications and data transmission to achieve the same bit rate or pad the frame by inserting non-information bits. These extra bits are removed by the data link layer to retrieve the original message. The Can bus will not be idle because the NRZ method is used. After five consecutive bits of the same value, bits with one's complement or the opposite value are filled into the bitstream. An error frame is generated if six bits of the same value are detected between the SOF and the CRC delimiter. After an error is detected, the transmission is terminated and the frame is repeated. If the error continues, then the station or node may shut itself down to prevent the bus from being bound.
bit error
The node sending the bit always monitors the bus. If the bit value sent by the sender is different from the bit value on the bus, an error frame is generated. However, in the arbitration field or acknowledgement slot, a recessive bit is sent and a dominant bit is received, which is an exception. Then no bit error will occur when monitoring the master bit.
The CAN protocol was originally developed for in-vehicle networking and has now been extended to various other industries. Limousine apps are already being used on heavy-duty vehicles such as trucks, buses, trains, and rail vehicles. The unique function of the CAN bus allows various electronic devices to communicate with each other, which makes it important in the medical field. For example in intensive care units and operating rooms, time and communication are paramount. The entertainment industry is also using the CAN protocol to improve the control of lighting and door systems in studios, and to control stages such as theaters and event halls. Gaming machines and toys are other examples in the entertainment sector. In the scientific field, CAN embedded networks are used in high-energy experiments and astronomical telescopes.

  • Mr. Bai Jilong has been engaged in the electronics industry for 15 years. He has developed more than 100 products so far, and most of them have been mass-produced. It took 5 years since 2018.

  • Concentrated on recording thousands of episodes of a series of practical-level electronic engineer courses, from components to core modules to complete products, Lao Bai's original intention is "I hope all engineers in the world will not take detours" Among them,

  • There are courses that explain MOS tubes and IGBTs in detail

Guess you like

Origin blog.csdn.net/m0_49011926/article/details/124151689