Follow+Star Public Number, don’t miss exciting content
Author | strongerHuang
WeChat Official Account | strongerHuang
Recently, I saw some netizens discussing whether ‘CAN is more difficult than UART’ in a technical group. Some said CAN is easy, while others said it is difficult.
In fact, whether it is difficult or not mainly depends on your perspective. Some netizens may have a good foundation and have studied CAN, so they might find it simple. However, for beginners with a weaker foundation, CAN is indeed much more difficult than UART.
Here, I would like to share a platform for job information related to embedded systems:

For beginners, I would like to share some basics about the CAN bus, which is indeed much more extensive than UART. As for whether CAN is more difficult than UART, you will have the answer after reading this.
The CAN bus belongs toasynchronous communication, so there is a communicationbaud rate, and this baud rate generator is located inside the CAN controller. We don’t need to understand how it is generated, but we need to understand its meaning. This chapter explains the following two points for beginners.
1. Asynchronous Communication
In serial communication, it is mainly divided into asynchronous communication and synchronous communication.
Synchronous Communication: Communication where devices transmit data through a synchronization signal (CLK clock) is called synchronous communication. Communication protocols like I2C and SPI have a clock signal, and actually, USART in STM32 also has synchronous functionality, but most of us only use its asynchronous function.
Asynchronous Communication: Simply put, it is when communication devices send and receive data at agreed-upon times. This time will determine the baud rate discussed in this section.
Many engineers have not fully understood what baud rate is. Here, I will briefly explain its meaning in conjunction with UART baud rate.
In electronic communication, baud refers to the modulation rate, which indicates the rate at which valid data signal modulates the carrier, that is, the number of times the carrier modulation state changes per unit time. It is a measure of symbol transmission rate, 1 baud means transmitting 1 symbol per second.
UART transmits 240 characters per second, and each character format contains 10 bits (1 start bit, 1 stop bit, 8 data bits), at this time thebaud rateis 240Bd,bit rateis 10 bits * 240 per second = 2400bps.
From the description above, we can summarize:
Bit Rate: The number of binary bits transmitted per unit time;
Baud Rate: The number of symbols transmitted per unit time;
Only when each symbol represents one bit of information can the baud rate be numerically equal to the bit rate, but their meanings are not the same.
Having discussed baud rate, the size of the baud rate is determined by the bit timing discussed in this section. In the CAN standard, one bit can be divided into four segments:
-
Synchronization Segment (SS)
-
Propagation Time Segment (PTS)
-
Phase Buffer Segment 1 (PBS1)
-
Phase Buffer Segment 2 (PBS2)
These segments are composed of the smallest time unit called Time Quantum (Tq).
One bit is divided into four segments, and each segment consists of several Tq, which is called bit timing.
In the STM32 reference manual, the bit timing is divided into three segments, but it combines the propagation segment and bit segment 1 together, as shown in the figure below:
How many Tq are in one bit and how many Tq each segment consists of can be set arbitrarily for bit timing. By setting the bit timing, the baud rate for transmission is determined:
These parameters will be configured in future programming, thus determining the communication baud rate.
Regarding synchronization, there are hardware synchronization and re-synchronization operations. However, beginners do not need to understand too much; just grasping the basic content above is sufficient. More information about bit timing can refer to ISO 11898 standards.
Frame Types and Format Description
The CAN bus communicates through the following five types of frames:
Data Frame: Used for the sending unit to transmit data to the receiving unit.
Remote Frame: Used for the receiving unit to request data from the sending unit with the same ID.
Error Frame: Used to notify other units of an error when an error is detected.
Overload Frame: Used for the receiving unit to notify that it is not yet ready to receive.
Frame Interval: Used to separate data frames and remote frames from the previous frame.
Data Frames and Remote Frames have standard and extended formats. The standard format has an 11-bit identifier ID, while the extended format has a 29-bit ID.
As shown in the figure, the data frame consists of seven segments:
Indicates the segment where the data frame begins.
Indicates the segment that represents the priority of the frame.
Indicates the segment for the number of bytes of data and reserved bits.
Content of the data, can send 0 to 8 bytes of data.
Segment for checking transmission errors of the frame.
Indicates the segment confirming normal receipt.
Indicates the segment where the data frame ends.
To understand the meaning of the data frame, please carefully understand its definition: a frame used for the sending unit to transmit data to the receiving unit.
In general CAN bus communication, most of the communication on the bus is data frames. For example, in the CANOpen protocol, the most frequently used PDO (Process Data Object) is communicated via data frames.
Beginners can first understand the data frame, and then other concepts will be easier to grasp. Next, I will describe the details of the seven segments of the data frame.
The standard and extended formats are the same. It indicates the segment where the frame starts, a 1-bit dominant bit (as shown in the figure below):
For dominant and recessive levels, please refer to my previous article on differential signals.
There are dominant and recessive levels on the bus.
When performing a logical “AND” on the bus, the dominant level’s logic value is “0”, while the recessive level is “1”.
“Dominant” implies “priority”; as long as one unit outputs a dominant level, the bus is at a dominant level. Moreover, “recessive” implies “tolerance”; only when all units output a recessive level, the bus is at a recessive level (dominant level is stronger than recessive level).
The standard and extended formats differ in their composition. The arbitration segment indicates the segment that represents the priority of the frame, and the extended format has an additional 18-bit ID (as shown in the figure below):
RTR = 0 represents a data frame, RTR = 1 represents a remote frame.
The reason it is called the arbitration segment is that it determines which node has the priority to send on the bus via the ID. The smaller the ID (0 represents dominant), the higher the priority.
The standard and extended formats differ in their composition. The control segment consists of 6 bits (as shown in the figure below):
They all have 4 bits representing the Data Length Code (DLC), while the standard frame has an IDE (value of 0) bit and r0 reserved bit, and the extended frame has r0 and r1 reserved bits.
The reserved bits must all be sent at the dominant level. However, the receiver can receive any combination of dominant, recessive, and their combination levels.
The standard and extended formats are the same. The data segment indicates the content of the data being transmitted, starting from the MSB (Most Significant Bit), and can send 0 to 8 bytes of data, with the length determined by the preceding control segment.
The standard and extended formats are the same. The CRC segment is for checking errors in frame transmission, consisting of a 15-bit CRC sequence and a 1-bit CRC delimiter (used for separation).
Compared to communication like 485, the CAN controller has already performed CRC checking, so there is no need for your program to calculate it again, saving processor resources.
The standard and extended formats are the same. The ACK segment is used to confirm whether the reception is normal. It consists of an ACK slot (ACK Slot) and an ACK delimiter consisting of 2 bits.
A.The sending unit sends 2 bits of recessive bits in the ACK segment.
B.The unit that receives the correct message sends a dominant bit in the ACK slot (ACK Slot) to notify the sending unit that the reception is normal. This is called “sending ACK” or “returning ACK”.
The standard and extended formats are the same. The frame end indicates the segment that marks the end of the frame. It consists of 7 bits of recessive bits.
Compared to the data frame, the remote frame is used by the receiving unit to request data from the sending unit. Therefore, the remote frame does not have a data segment. Thus, the remote frame is composed of the following 6 segments:
Indicates the segment where the frame starts.
Indicates the segment that represents the priority of the frame. It can request a data frame with the same ID.
Indicates the segment for the number of bytes of data and reserved bits.
Segment for checking transmission errors of the frame.
Indicates the segment confirming normal receipt.
Indicates the segment that marks the end of the remote frame.
The six segments are basically the same in content as the data frame, so I won’t describe them one by one. Let’s talk about the differences between the remote frame and the data frame:
-
The RTR bit of the remote frame is a recessive bit, and there is no data segment.
-
The data frame without a data segment can be distinguished from the remote frame through the RTR bit.
Question 1: The remote frame has no data segment; how is the data length code represented?
The data length code of the remote frame is represented by the data length code of the requested data frame.
Question 2: What is the use of a data frame without a data segment?
For example, it can be used for periodic connection confirmation/responses between units, or when the arbitration segment itself contains substantial information.
Used to detect errors during message reception and transmission and notify errors. The error frame consists of an error flag and an error delimiter.
The error flag includes two types: active error flag and passive error flag.
-
Active Error Flag: 6 bits of dominant bits.
-
Passive Error Flag: 6 bits of recessive bits.
The error delimiter consists of 8 bits of recessive bits.
The overload frame is used for the receiving unit to notify that it is not yet ready to receive. The overload frame consists of an overload flag and an overload delimiter.
The composition of the overload flag is the same as that of the active error flag.
8 bits of recessive bits.
The composition of the overload delimiter is the same as that of the error delimiter.
The frame interval is used to separate data frames and remote frames. Data frames and remote frames can be separated from any previous frame (data frame, remote frame, error frame, overload frame) by inserting a frame interval.
No frame interval can be inserted before overload frames and error frames.
3 bits of recessive bits.
Recessive level, no length limit (0 is also acceptable).
In this state, it can be considered that the bus is idle, and the unit that wants to send can start accessing the bus.
(3) Delayed Transmission (Sending Temporarily Stopped)
8 bits of recessive bits.
Only included in the frame interval of a unit that is in a passive error state after sending a message.
———— END ————

● Column “Embedded Tools”
● Column “Embedded Development”
● Column “Keil Tutorial”
● Selected Tutorials from the Embedded Column
Follow the public account reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

Click “Read Original” to see more shares.