CAN bus entry tutorial for beginners (1)_CAN bus macro introduction

Reference article:

  1. Getting started with CAN bus (hardware part) . Comes from Remember Cheng Electronic Design, author Cheng Ge
  2. CAN primer. Renesas Electronics

1. What is CAN?

CAN is the abbreviation of Controller Area Network (hereinafter referred to as CAN), and is a serial communication protocol standardized by ISO.
In the current automotive industry, various electronic control systems have been developed for the requirements of safety, comfort, convenience, low pollution, and low cost. Because the data types and reliability requirements for communication between these systems are not the same, there are many situations where multiple buses are formed, and the number of wiring harnesses also increases. In order to meet the needs of "reducing the number of wiring harnesses" and "high-speed communication of large amounts of data through multiple LANs", in 1986, the German electrical company Bosch developed a CAN communication protocol for automobiles. Since then, CAN has been standardized through ISO11898 and ISO11519, and is now a standard protocol for automotive networks in Europe.
Now, CAN's high performance and reliability have been recognized, and it is widely used in industrial automation, shipbuilding, medical equipment, industrial equipment, etc.
The figure below is a schematic diagram of the car network. The development of communication protocols such as CAN enables multiple LANs to exchange data through gateways.
Insert picture description here

1.1 The role of CAN bus

In a car, the role of the CAN bus is to connect different components, and then these components implement the same set of standard protocols. This has the advantage of high compatibility, reliable sharing of information, and reducing the number of wiring harnesses in the entire vehicle.
Insert picture description here
Take a car such as a human body, the CAN bus is the nervous system, and the electronic control unit (ECU) is a part of the body. The body is composed of multiple ECUs. Each ECU communicates through the nervous system. The information sensed by one part can be Share with another part.

Simply put, CAN bus has the following advantages:

  1. Simple and low cost: ECU communicates through a single CAN system instead of direct communication with complex analog signal lines, which reduces errors, weight, wiring and costs.
  2. Completely centralized: CAN bus provides an access point that can communicate with all network ECUs, supporting centralized diagnosis, data recording and configuration.
  3. Stable: CAN bus has strong anti-electric interference and anti-electromagnetic interference capabilities, which is very suitable for applications with strict safety requirements (such as vehicles).
  4. Efficient: Prioritize CAN frames by ID, so that the data with the highest priority can immediately access the bus without causing interruptions to other frames.

1.2 CAN bus topology diagram

The figure below is the CAN bus topology.
Insert picture description here

1.3 CAN node hardware composition

There are two kinds of hardware composition schemes of CAN bus node:

  1. MCU controller + independent CAN controller + CAN transceiver: independent CAN controller such as SJA10000, MCP2515.
  2. MCU with CAN controller + CAN transceiver: Currently, MCUs with CAN controller on the market such as P87C591, LPC2294, C8051F340, etc.

The node composition of the two schemes needs to be connected to the CAN bus through a CAN transceiver. Commonly used CAN transceivers include PCA82C250, PCA82C251, TJA1050, TJA1040, etc.
The node composition of the two schemes has its own advantages and disadvantages:

  1. The CAN program written in the first scheme is aimed at an independent CAN controller, and the program can be transplanted well, and the written program can be easily transplanted to any MCU. However, due to the independent CAN controller, the I/O resources of the MCU are occupied, and the circuit becomes complicated.
  2. The CAN program written in the second scheme is aimed at the specific selected MCU. The CAN controller unit is integrated in the MCU controller, and the hardware circuit becomes simpler. But the program cannot be transplanted after it is written.

The hardware structure of CAN bus node is shown in the figure below.
Insert picture description here

1.3.1 The role of CAN controller

On the one hand, the CAN controller receives the data from the transceiver, parses it and sends it to the MCU; on the other hand, it receives the instruction data from the MCU and then sends it to the CAN transceiver.

1.3.2 The role of CAN transceiver

As the name implies, the transceiver can receive or send. Receive is to receive differential data on the CAN bus, convert the data to TTL level, and send it to the controller; send is to convert the TTL level signal of the CAN controller into a differential signal Perform bus data transmission.

1.4 The physical layer characteristics of CAN

The CAN controller judges the bus level according to the potential difference between CAN_L and CAN_H. The bus level is divided into dominant level and recessive level, the two must be one of them. The sender sends the message to the receiver by changing the bus level.
Insert picture description here
Dominant level corresponding logic: 0 (The difference between CAN_H and CAN_L is about 2V)
Recessive level corresponding logic: 1 (The difference between CAN_H and CAN_L is 0V)
Dominant level has priority, as long as one unit outputs dominant Level, the dominant level is on the bus. The invisible level has the meaning of tolerance. Only when all the units output the recessive level, the recessive level is on the bus (the dominant level is stronger than the recessive level).

1.4.1 The role of 120Ω terminal resistance

During high-frequency signal transmission, the signal wavelength is shorter than that of the transmission line, and the signal will form a reflected wave at the end of the transmission line, which will interfere with the original signal. Therefore, it is necessary to add a terminating resistor at the end of the transmission line to prevent the signal from being reflected after reaching the end of the transmission line.
For low frequency signals, it can work normally without the CAN bus. Both ends of the CAN bus must be connected with a terminal resistance. The terminal resistance should be the same as the impedance of the communication cable, with a typical value of 120 ohms. Its function is to match the bus impedance and improve the anti-interference and reliability of data communication. Sex. 
Insert picture description here
The terminal resistance is not all 120Ω, the following is the recommended value of the ISO 11898 protocol.
Insert picture description here

2. Features of CAN

2.1 Multi-master control

When the bus is idle, all units can start sending messages (multi-master control).
The unit that accesses the bus first can get the right to send (CSMA/CA mode).
When multiple units start sending at the same time, the unit sending the high priority ID message can get the right to send.

2.2 Sending of messages

In the CAN protocol, all messages are sent in a fixed format. When the bus is idle, all units connected to the bus can start sending new messages. When two or more units start to send messages at the same time, the priority is determined based on the identifier (hereinafter referred to as ID). ID does not indicate the destination address sent, but indicates the priority of the message to access the bus. When two or more units start to send messages at the same time, each bit of each message ID is arbitrated and compared one by one. The unit that wins the arbitration (determined as the highest priority) can continue to send messages, and the unit that loses the arbitration immediately stops sending and starts receiving.

2.3 The flexibility of the system

Units connected to the bus have no information like "address". Therefore, when adding units to the bus, the software, hardware and application layers of other units connected to the bus do not need to be changed.

2.4 Communication speed

According to the scale of the entire network, an appropriate communication speed can be set.
In the same network, all units must be set to a uniform communication speed. Even if the communication speed of one unit is different from that of the others, this unit will output an error signal, hindering the communication of the entire network. Different networks can have different communication speeds.

2.5 Remote data request

You can request other units to send data by sending a "remote control frame".

2.6 Error detection function, error notification function, error recovery function

Error detection function : All units can detect errors.
Error notification function : The unit that detects an error will immediately notify all other units at the same time.
Error recovery function : Once the unit that is sending a message detects an error, it will forcibly end the current sending. The unit that forcibly ends the transmission will repeatedly resend the message until it is successfully transmitted.

2.7 Fault closure

CAN can determine whether the type of error is a temporary data error on the bus (such as external noise, etc.) or a continuous data error (such as unit internal failure, drive failure, disconnection, etc.). With this function, when a continuous data error occurs on the bus, the unit that caused the fault can be isolated from the bus.

2.8 Too many connected nodes

CAN bus is a bus that can connect multiple units at the same time. The total number of connectable units is theoretically unlimited. But in fact, the number of units that can be connected is limited by the time delay on the bus and the electrical load. Reduce the communication speed, the number of connectable units increases; increase the communication speed, the number of connectable units decreases.

2.9 Fast speed and long distance

The highest speed is 1Mbps (distance <40m), and the
longest distance is 10Km (rate <5Kbps)

3. Error

3.1 Types of error status

3.1.1 Active error status

The active error state is a state where it can normally participate in bus communication.
When a unit in the active error state detects an error, it outputs an active error flag.

3.1.2 Passive error state

The passive error state is a state that easily causes errors.
Although the unit in the passive error state can participate in the bus communication, in order not to hinder the communication of other units, the error notification cannot be actively sent when receiving.
Even if a unit in a passive error state detects an error, and other units in an active error state do not find an error, the entire bus is considered to be error-free.
When the unit in the passive error state detects an error, it outputs a passive error flag.
In addition, a unit in a passive error state cannot start sending again immediately after sending. Before starting the next transmission, a "delayed transmission" (8 recessive bits) must be inserted during the interval frame.

3.1.3 Bus off state

The bus closed state is a state in which it cannot participate in communication on the bus.
The receiving and sending of information is prohibited.

3.1.4 State transition

These states are managed by the count of transmission errors and counts of reception errors, and the state is determined according to the count value.
The relationship between the error status and the count value is shown in Table 1 and Figure 4.
Insert picture description here
Insert picture description here

3.2 Error count value

The transmission error count value and the reception error count value change according to certain conditions.
The fluctuation conditions of the error count value are shown in the table below.
A data reception and transmission may satisfy multiple conditions at the same time.
The error counter starts counting at the time when the first bit of the error flag appears.
Insert picture description here

Guess you like

Origin blog.csdn.net/mahoon411/article/details/109739994