Introduction to Embedded CAN Bus (Low-Level Details) – Part 1

Source: Electric Control Knowledge Transporter
Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

1. Introduction

The CAN bus was developed by the German company BOSCH, with a maximum speed of up to 1Mbps. The fault tolerance of CAN is particularly strong, and the CAN controller has a powerful error detection and handling mechanism built-in.

Additionally, unlike traditional networks (such as USB or Ethernet), CAN nodes do not transmit large data blocks between each other. A single CAN message can carry a maximum of 8 bytes of user data, and the use of short packets allows the system to achieve better stability. The CAN bus has a bus arbitration mechanism, allowing for the establishment of multi-master systems.

2. CAN Standards

CAN is a serial communication bus defined by an international standards organization. Initially used in the automotive industry, it replaces the complex wiring in vehicles with two signal buses. The CAN bus features high anti-interference capabilities, self-diagnosis, and data error detection functions, making it widely used in various industrial applications, including building automation, medical, and manufacturing industries.

The CAN communication protocol ISO-11898:2003 standard describes how information is transmitted between devices on the network, as well as which layers conform to the Open Systems Interconnection (OSI) reference model. Actual communication occurs in the physical medium connecting the devices, with the characteristics of the physical medium defined by the physical layer in the model. The ISO11898 architecture defines seven layers, with the lowest two layers in the OSI model serving as the data link layer and physical layer, as shown in Figure 2-1.

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Figure 2-1: ISO 11898 Standard Architecture Layers
In Figure 2-1, the application layer establishes upper-layer application-specific protocols, such as the CANopenTM protocol communication link. This protocol is maintained by users and manufacturers worldwide under the CiA organization; for details, visit the CiA website: can-cia.de.
Many protocols are specialized, such as those for industrial automation, diesel engines, or aerospace. Another industrial standard example is the DeviceNetTM protocol, developed by KVASER and Rockwell Automation, which is based on CAN.
3. Standard CAN and Extended CAN
The CAN communication protocol is a carrier-sense multiple access protocol with collision detection and arbitration based on message priority (CSMA/CD+AMP). CSMA means that each node on the bus must listen to the bus before attempting to send a message, and can only send when the bus is idle.
CD+AMP means that collisions are resolved through programmed message priority arbitration bit by bit; the message priority is located in the identifier field of each message. Messages with higher priority identifiers always gain access to the bus, meaning that the message with the last logical high level in its identifier will continue transmission, as it has a higher priority.
The ISO-11898:2003 standard offers a maximum signal rate from 125Kbps to 1Mbps with an 11-bit identifier. Later revisions use an extended 29-bit identifier. The standard 11-bit identifier field is shown in Figure 3-1, providing 2048 different message identifiers, while the extended 29-bit identifier field is shown in Figure 3-2, providing 537 million different message identifiers.
3.1 Standard CAN
Standard CAN has only an 11-bit identifier, with each frame’s data length being 51 + (0~64) = (51~117) bits.
Note: Bit padding is not counted (bit padding will be described in Section 5 of this article).

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Figure 3-1: Standard CAN – 11-bit Identifier

· SOF – Frame start, dominant (logical 0) indicates the start of the message and is used to synchronize nodes on the bus.

· Identifier – Standard CAN has an 11-bit identifier used to determine the message priority. The smaller the value of this field, the higher the priority.

· RTR – Remote transmission request bit, when information is needed from another node, this bit is dominant (logical 0). All nodes can receive this request, but the frame identifier determines the designated node. The response data frame is also received by all nodes and can be used by interested nodes.

· IDE – The identifier extension bit being dominant indicates this is a standard CAN format; being recessive indicates this is an extended CAN format.

· r0 – Reserved bit (may be used in future standard revisions)

· DLC – 4-bit data length code indicating the number of bytes of data being transmitted; a single CAN frame can carry a maximum of 8 bytes of user data.

· Data0~8 – A maximum of 8 bytes of user data can be transmitted.

· CRC – 16-bit (including 1-bit delimiter) CRC checksum used to check the transmission data segment preceding the user data area (including the data area).

· ACK – 2 bits, including the acknowledgment bit and acknowledgment delimiter. In the sending node’s message frame, the ACK bits are recessive; when the receiver correctly receives a valid message, it sends a dominant bit back to the sending node during the acknowledgment period, indicating acknowledgment. If the receiver finds an error in this frame of data, it does not send an ACK acknowledgment to the sending node, which will then retransmit this frame of data later.

· EOF – 7-bit frame end flag, all recessive bits. If any of these 7 bits appear dominant, it will cause a bit stuffing error.

· IFS – 7-bit inter-frame spacing flag; the CAN controller requires some time to correctly place the received frames into the message buffer, and the inter-frame spacing provides this time.

3.2 Extended CAN
Extended CAN has a 29-bit identifier, with each frame’s data length being 71 + (0~64) = (71~135) bits.
Note: Bit padding is not counted (bit padding will be described in Section 5 of this article).

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Figure 3-2: Extended CAN – 29-bit Identifier
Extended CAN messages add the following content compared to standard CAN messages:

· SRR – Replaces the remote request bit and is recessive. Therefore, when standard frames and extended frames conflict and the basic identifier of the extended frame matches the identifier of the standard frame, the standard frame has a higher priority than the extended frame.

· IDE – The recessive bit indicates the flag for the extended frame, with the 18-bit extended identifier following the IDE bit.

· r1 – Reserved

4. CAN Messages
4.1 Arbitration
The basic principle of typical CAN is shown in Figure 4-1. From the figure, it can be seen that the bus logic state is opposite to the driver input and receiver output logic.
Under normal circumstances, a logical high level represents 1, and a logical low level represents 0; however, in the CAN bus, a logical high level represents 0, called dominant, while a logical low level represents 1, called recessive. Therefore, many transceiver driver inputs are equipped with pull-up resistors, so that when there is no input, the CAN bus appears recessive (logical low level).

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Figure 4-1: Inverted CAN Bus Logic
When the bus is idle, the node that first starts sending a message gains the right to transmit.
If multiple nodes access the bus simultaneously, CAN uses a non-destructive, bitwise arbitration method to determine which node uses the bus: each sending node begins arbitration from the first bit of the arbitration domain (identifier and RTR domain); the node that continuously outputs the dominant level (0) the most can continue sending.
Thus, the lower the identifier value of the CAN message, the higher the priority. A CAN message with an identifier value of 0 has the highest priority, as it outputs the most dominant levels.
4.2 Message Types
There are four different types of CAN messages: data frame, remote frame, error frame, and overload frame.
5. Bit Stuffing Mechanism
The start frame, arbitration domain, control domain, data domain, and CRC checksum domain are all encoded using the bit stuffing method. Bit stuffing means that whenever the sender detects five consecutive identical logical bits in the bit stream, it will automatically insert a complementary bit into the bit stream.
For example, if there are five consecutive dominant bits, a recessive bit will be automatically inserted after these five dominant bits. The receiver will automatically remove this inserted stuffing bit.
The remaining bit fields of the data frame or remote frame (CRC delimiter, acknowledgment domain, and frame end domain) are fixed in form and not stuffed. Error frames and overload frames are also not stuffed.
CAN network synchronization requires enough rising edges, which is one of the purposes of the CAN protocol’s bit stuffing. Other functions of bit stuffing include ensuring that data frames are not mistaken for error frames (which consist of six consecutive dominant or recessive bits) and ensuring correct identification of the frame end flag (seven consecutive recessive bits).
6. Error Detection and Fault Isolation
The CAN bus has high robustness, likely due to its multiple error-checking mechanisms. The CAN protocol specifies five error detection methods: three at the message level and two at the bit stream level.
If a data frame has an error, that frame will be discarded, and the receiving node will send an error frame. This will force the sending node to retransmit the erroneous message until the receiving node correctly receives it. If the same message repeatedly fails after a certain number of attempts, the sending node may disable its transmission function to reduce the impact on the bus.
Error detection at the message level includes CRC and ACK. The 16-bit CRC field contains 15 bits of checksum and 1 bit of delimiter. The ACK field includes 1 bit of acknowledgment and 1 bit of delimiter.
CRC error checking is easy to understand; it generates a CRC checksum for the data field and the bits preceding the data field. Since a single CAN message data stream is small (up to 8 user data), the 15-bit CRC error detection capability is excellent.
So, how does the ACK field work? This is specified by the CAN protocol: after the sending node sends a frame of data, the receiving node must respond to the sending node; if the sending node does not receive the acknowledgment signal from the receiving node, it will consider its transmission failed and retransmit the data.
The third error checking method at the message level is format checking. This check monitors those fields in the message that must be recessive bits; if any of these fields contain dominant bits, a format error is detected. These fields include the SOF, EOF, ACK delimiters, and CRC delimiters.
One of the error detection methods at the bit stream level is that each data bit sent to the bus is monitored; if the sent bit does not match the bit on the bus, a bit error occurs. This monitoring mechanism does not check the bits in the arbitration domain because when multiple nodes compete for the bus, the higher priority node may overwrite the bits in the arbitration domain.
Another error detection mechanism at the bit stream level is the bit stuffing rule: after five consecutive identical logical bits, if the sixth bit’s logic is still the same as the previous five, a bit stuffing error occurs.
7. Network Topology
CAN uses differential signaling, requiring a pair of signal lines, preferably twisted pair cables. The network topology is shown in Figure 7-1. Using differential signaling can suppress common-mode interference, increase system reliability, and allow for higher rates.
The high-speed ISO 11898 standard specifies a maximum transmission rate of 1Mbps for CAN; at this rate, the maximum transmission distance is 40 meters (with 30 nodes connected, and CAN signals are not isolated). The recommended maximum branch length for nodes is 0.3 meters, and it is recommended to use twisted pair cables with or without shielding, with a characteristic impedance of 120 ohms.

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Figure 7-1: CAN Bus Network Topology Diagram
8. Termination Matching
The size of the termination matching resistor equals the characteristic impedance of the transmission cable, which is provided by the cable supplier, generally approximated as Z=√(L/C). Where L is the inductance per unit length of the cable, and C is the capacitance per unit length of the cable.
Due to the structure of CAN transceivers, the transition from recessive to dominant is driven by transistors, so it is very steep; however, the transition from dominant back to recessive requires termination resistors to discharge; otherwise, due to the distributed capacitance of the wires, it will discharge slowly, leading to bit width errors. Therefore, the practice of not adding termination resistors for short-distance, low-baud rate CAN buses is incorrect.
RS485 is different from CAN bus; due to the built-in failure protection circuit in RS485 transceivers, it allows for the absence of termination matching resistors at short distances and low baud rates.
9. Cables and Wiring
CAN bus uses differential signal transmission; if twisted pair cables with shielding are used, the shielding layer should be grounded at a single point.
Figure 9-11 lists the analysis and connection examples of CAN cables with a single shielding layer.

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Figure 9-1: Cable Signal Distribution, Grounding, and Termination Matching
Generally speaking, the smaller the cable cross-sectional area, the greater its distributed capacitance, distributed inductance, and DC resistance. When the communication distance is long, capacitance, inductance, and DC resistance can cause signal attenuation, waveform distortion, and jitter.
In general, cable suppliers provide signal attenuation charts. The curve shown in Figure 9-2 illustrates the relationship between the attenuation of 24-AWG cables and frequency:

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Figure 9-2: Signal Attenuation
10. Differential Signal Voltage Amplitude
As shown in Figure 10-1, the two signal lines CAN_H and CAN_L are around 2.5V when static, indicating a recessive state (logical 1); when CAN_H is higher than CAN_L, it indicates a dominant state (logical 0), typically with CAN_H voltage at 3.5V and CAN_L voltage at 1.5V.

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Figure 10-1: CAN Voltage Levels
The CAN standard specifies that the differential voltage on the CAN bus must be >0.9V to be recognized as a dominant level, <0.5V to be recognized as a recessive level, and levels between 0.5~0.9 cannot determine the polarity. As shown in Table 10-1:

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Table 10-1: Relationship between Differential Voltage Amplitude and Level Polarity
In practical project wiring, it is easy to overlook or over-add termination matching resistors. We can assess whether termination matching resistors are missing or excessive by measuring the CAN differential voltage amplitude. If we disregard wire resistance, the termination resistance is fixed at 120 ohms, and the differential voltage of a single node CAN bus is shown in Table 10-2:

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Table 10-2: Relationship between Number of Termination Matching Resistors and Differential Voltage Amplitude
(To be continued)
(Images and text sourced from the internet)

Click the mini-program below to see more maintenance cases

Introduction to Embedded CAN Bus (Low-Level Details) - Part 1

Leave a Comment