Understand the principle of CAN bus with one picture
According to Figure 1, the CAN bus is simply like two yellow lines. The principle of communication is like holding a conference call. Everyone dials in at the same time, and then there are various states, such as: one person speaks and others listen; Or multiple people want to speak at the same time, but one of them will speak first and the others will listen; another person will ask another person to speak; some will be disconnected, stuck, etc.
In order to ensure that every conference call is conducted correctly and effectively for the above situations, we need some rules or protocols that everyone should follow. CAN bus communication has similarities and differences with this form of teleconferencing. So what exactly is CAN bus communication?
CAN bus is a wire used for data transmission between different control units. The CAN bus protocol is an ISO internationally standardized serial communication protocol, consisting of two series: ISO-11898 and ISO-11519. Its definitions are:
·ISO-11898 defines a high-speed CAN communication standard with a communication rate of 125 kbps ~1Mbps. It is a closed-loop bus with a transmission rate of up to 1Mbps and a bus length ≤ 40 meters, as shown in Figure 2.
·ISO11519 defines a low-speed CAN communication standard with a communication rate of 10 to 125 kbps. It is an open-loop bus. When the transmission rate is 40 kbps, the bus length can reach 1,000 meters.
The CAN bus will have a terminal resistor, which is generally 120 ohms. In fact, during design, two 60 ohm resistors are connected in series, and there are usually two 120 ohm nodes on the bus. The terminal resistor has three functions:
1. Improve interference protection capabilities and quickly eliminate high-frequency and low-energy signals
2. Ensure that the bus enters the hidden state quickly so that the energy of the parasitic capacitor can be dissipated faster.
3. Improve signal quality by placing them at both ends of the bus to reduce reflected energy.
When learning the CAN bus, you often see that the levels of the CAN bus are divided into dominant levels and recessive levels. So what are dominant and recessive levels? What is the correspondence between explicit and implicit logical 0 and logical 1? CAN communication logic 0 and 1, explicit and implicit.
The transmission of electrical signals is carried out by distinguishing between high voltage and low voltage, just like CAN communication. The two signal lines of the CAN bus are CAN high (CAN_H) and CAN low (CAN_L). Regarding the logic 0 and logic 1 of CAN and the explicit and implicit aspects of CAN bus, the following diagrams have been compiled so that everyone can understand clearly.
Note 1: In actual development, the voltages of both lines fluctuate at default values, which is also the advantage of using differential transmission to reduce errors and noise interference;
Note 2: The CAN bus uses the "line sum" rule for bus arbitrage, that is, if multiple CAN signals are sent at the same time, some send 1 and some send 0. As long as there is 0, the current bus is 0 (1&0=0). Therefore, explicit planes on the bus are represented by logic "0", while implicit planes are represented by logic "1";
Although differential signals have better anti-interference capabilities, when transmitting long-distance signals, we usually use twisted pairs for data transmission to physically reduce the coupling of noise to the signal transmission process.
The above-mentioned potential difference (differential level) and logic level are realized through the CAN transceiver. During the transmission process, the CAN controller converts the signal transmitted by the CPU into logic levels. After the CAN transceiver receives the logic level, it converts it into a differential level and outputs it to the CAN bus.
During the reception process, the difference level transmitted on the CAN_H and CAN_L lines sent by the CAN transceiver is converted into a logic level and output to the CAN controller, and then the CAN controller converts the logic level into a corresponding signal and sends it to the CPU.
Simply put, this means that the transmitter changes the bus level through the CAN transceiver and transmits its information to the CAN bus. The receiver reads the information on the bus into its own CAN transceiver by monitoring the bus levels.
As shown above, the CAN bus has two architectures, two forms of CAN signals, and two processes for sending and receiving CAN signals.