"Preface
The application of CAN bus seems to be more and more extensive now. Our equipment has been upgraded from the original ARM9 and ARM7 platform to cortex A8 and cortex m3 platform, and then to the current cortex M4 platform. A series of products have been developed around can. There is no doubt about the stability of CAN bus.
Physical structure and characteristics of CAN bus
Can bus network
Can bus network is mainly connected to can_ H and can_ 50. Each node realizes the serial differential transmission of the signal through these two lines. In order to avoid the reflection and interference of the signal, it also needs to be on the can_ H and can_ A 120 ohm terminal resistance is connected between L, but why 120 ohm? That's because the characteristic impedance of the cable is 120 ohms.
Can transceiver
The function of can transceiver is responsible for the conversion between logic level and signal level.
That is, the logic level is output from the can control chip to the can transceiver, and then the logic level is converted into differential signal and output to the CAN bus through the internal conversion of the can transceiver. The nodes on the CAN bus can decide whether they need the data on the bus. The specific definition of discipline is as follows:
Signal representation
The CAN bus adopts the non return to zero code bit filling technology, that is, the signal on the CAN bus has two different signal states, namely, dominant logic 0 and invisible logic 1. The signal does not need to return to the logic 0 level after each transmission.
Bit filling rule: as long as the transmitter detects that there are 5 consecutive bits with the same value in the bit stream, it will automatically insert supplementary bits into the bit stream.
Observe the following figure:
As can be seen in the figure above, when the first paragraph is recessive, can_ H and can_ The L level is almost the same, that is, can_ H and can_ When the L level is very close or even equal, the bus is recessive, while when the level difference between two line points is large, it is dominant. According to the definition:
CAN_ H-CAN_ It is recessive when l < 0.5V, and the logic signal is "" logic 1 "" - high level.
CAN_ H-CAN_ It is dominant when l > 0.9V, and the logic signal is "" logic 0 "" - low level.
The corresponding relationship between differential signal and explicit implicit signal is summarized in the following table:
state
Logic signal
Voltage range
Dominant dominants
0
CAN_ H-CAN_ L > 0.9
Recessive recessive
one
CAN_ H-CAN_ L < 0.5
From the above analysis, we can know:
Can bus adopts the rules of "" line and "" for bus blanking. I.e. 1 & 0 = 0; So 0 is dominant.
The implication of this sentence is that if only one node on the bus pulls the bus to the low level (logic 0), i.e. the dominant state, the bus will be in the low level (logic 0), i.e. the dominant state. No matter how many nodes on the bus are in the transmission recessive state (high level or logic 1), the bus will be high, i.e. recessive, only if all nodes are high (recessive).
Communication rate and communication distance
The following SAE j2411 is an American automotive standard.
type
standard
Maximum rate
describe
High speed can
CAN/ISO 11839-2
1mbit / S
The most common can bus type
Low speed can
ISO/ISO 11839-3
125kbit / S
Fault tolerant, it can still work when a bus is short circuited
Single line can
SAE J2411
50kbit / S
The high-speed mode can reach 100kbit / s, which is mainly used in automobiles, such as general motors
The maximum transmission distance of any two nodes on the CAN bus is related to its bit rate, as shown in the table below:
Bit rate / kbps
one thousand
five hundred
two hundred and fifty
one hundred and twenty-five
one hundred
fifty
twenty
ten
five
Maximum distance / M
forty
one hundred and thirty
two hundred and seventy
five hundred and thirty
six hundred and twenty
one thousand and three hundred
three thousand and three hundred
six thousand seven hundred
ten thousand
The maximum communication distance here refers to the distance between two nodes on the same bus. It can be seen that the lower the speed, the farther the communication distance, that is, the communication distance of CAN bus is inversely proportional to the baud rate. The maximum transmission distance is 10 km when the bit rate is 5 kilobits per second. The communication rate of 500K / S is commonly used in general engineering. This rate is also very reliable in the actual test.
If you want further transmission (greater than 10km); A device composed of multiple can controllers or interface chips with other communication protocols (such as 485 or TCP / IP) can be considered, so as to meet the needs of long-distance communication.
Key concepts of CAN bus
arbitration
As long as the bus is idle, any node on the bus can send messages. If two or more nodes start transmitting messages, there will be the possibility of bus access conflict. However, can uses the bit by bit arbitration method of identifier to solve this problem.
During arbitration, each transmitter compares the transmitted level with the monitored bus level. If the levels are the same, the unit can continue to transmit. If a "hidden" level is transmitted and a "explicit" level is monitored, the node loses arbitration and must exit the transmission state. An error event is generated if a mismatched bit does not occur during arbitration.
The smaller the frame ID, the higher the priority. Since the RTR bit of the data frame is the dominant level and the remote frame is the recessive level, when the frame format and frame ID are the same, the data frame takes precedence over the remote frame; Since the IDE bit of the standard frame is the dominant level and the IDE bit of the extended frame is the invisible level, the priority of the standard frame is higher than that of the extended frame for the standard frame and the extended frame with the same ID of the first 11 bits.
Can bus protocol
Can bus is a broadcast bus, so any node on the bus can monitor the data transmitted on the bus. In other words, the transmission on the bus is not point-to-point, but point-to-multipoint transmission. Multipoint here means all nodes on the bus. But how does the node on the bus know that the data is transmitted to itself? The hardware chip of CAN bus provides a function called local filtering. Through this local filtering function, we can filter out some irrelevant data and retain some information related to ourselves.
Can message mechanism
The can standard defines four message types. Each message is controlled to enter the CAN bus by a mechanism called bit arbitration, and each message is marked with priority. In addition, the can standard also defines a series of error handling mechanisms.
Four message types of can message:
Data frame: data frame transmits data from the transmitter to the receiver.
Remote frame: the bus unit sends a remote frame and requests to send a data frame with the same identifier.
Error frame: Any unit sends an error frame when it detects a bus error.
Overload frame: overload frame is used to provide additional delay between adjacent data frames or remote frames.
Data frame
The following figure shows the basic format:
There are two formats of standard frame and extended frame in CAN bus. The difference between the two formats lies in the format of arbitration domain. You can clearly see the difference between them by looking at the following two tables. The first table below is standard frame (CAN2.0 a) and the second is extended frame (CAN2.0 B):
The following is the extended frame format (CAN2.0B):
among
Sof is the start of the frame
SRR replaces the remote request bit with ''
IDE is an extended identifier bit
RTR is the remote transmission request bit
CRC delimiter is the CRC delimiter.
ACK delimiter is the response delimiter
We can see that the basic frame format in the figure above can be summarized into the following fields:
field
describe
Arbitration domain
The arbitration domain determines the priority when two or more nodes on the bus compete for the bus.
Data domain
Contains 0 to 8 bytes of data.
CRC domain
Contains a 15 bit checksum, which is used for error detection.
Reply slot
Any controller that has correctly received the message sends a reply bit at the end of each message. The transmitter checks whether there is a reply bit in the message, and if not, resend the message.
Remote frame
A station as a data receiver can start its resource nodes to transmit their respective data by transmitting a remote frame. The remote frame is very similar to the data frame, except that the remote frame has no data field.
The above figure is the frame format of the remote frame, which has no remote frame relative to the data frame. However, it should be noted that when sending the remote frame, the RTR bit should be set to 1, indicating that the remote frame is sent. This structure is more clearly shown in the figure below.
Error frame
An error frame is sent when a node of the bus detects an error, which will cause all nodes to detect an error. Therefore, when any node detects an error, other nodes on the bus will also send an error frame. A detailed error counting mechanism is designed for CAN bus to ensure that can bus will not collapse due to any node repeatedly sending error frames.
As shown in the figure above, the error flag and the error delimiter are composed. The high and low representatives represent recessive and explicit respectively. The error flag is the superposition of the error flags sent by all nodes. The following figure shows the distribution of data bits more clearly:
The definitions of each part are summarized in the following data structure block diagram:
There are two forms of error flags:
Active error flag, which is composed of 6 consecutive dominant bits 0. It is the error flag actively sent by the node.
Passive error flag, which consists of six consecutive recessive bits 1, unless covered by the dominant bits of other nodes.
Just now, it was said that detecting an error on a node will cause all nodes on the bus to detect an error and send an error flag. Why?
Because the error flag format on a single node violates the bit filling rule from the beginning of the frame to the CRC delimiter, and also destroys the fixed format of the ACK field or the end of the frame. The following is a brief description of the lower filling rules.
Bit filling rule: as long as the transmitter detects that there are 5 consecutive bits with the same value in the bit stream, it will automatically insert supplementary bits into the bit stream.
Note: the bit filling rule is only for data frames and remote frames, and the formats of error frames and overload frames are fixed.
Therefore, all other nodes will detect the error condition and start sending error flags. Therefore, the error frame is the result of superposition of different error flags of each station.
When a node sends an error frame (with an error flag), other nodes receive the error frame and detect the error condition, they will prompt the error by sending the error frame of "passive error flag".
Error delimiter:
After transmitting the error flag, each station sends a hidden bit, monitors the bus until a hidden bit is detected, and then starts sending the remaining 7 hidden bits.
Overload frame
Overload frame is a frame used by the receiving node to inform the transmitting node of its receiving ability.
Overloaded frame means that a receiving node has no time to process the data and wants other nodes to send data frames or remote frames slowly, so tell the transmitting node that I have no ability to process the data you sent.
The structure of overload frame is similar to that of error frame, including overload flag and overload delimiter. There are three situations that will cause overload:
The internal reason of the receiver is that it needs to delay the next data frame or remote frame.
A dominant bit is detected in the first and second bits of the intermittent field (see the inter frame space below) (both intermittent fields are recessive bits)
If the CAN node samples an explicit bit logic 0 in the eighth bit (last bit) of the error delimiter or overload delimiter, the node will send an overload frame and the error counter will not increase.
The above figure clearly shows that the overload flag consists of 6 dominant bits, and the superposition part is the same as the "active error" flag. The overload flag destroys the fixed format of the intermittent domain. Therefore, other nodes detect the overload condition and issue the overload flag together.
Overload delimiter:
That is, the overload terminator in the figure above. After the overload flag is transmitted, the node will always monitor the bus until it detects a jump from the dominant bit to the recessive bit. When such a jump is detected from the bus, it indicates that each node has completed the transmission of its own overload flag and starts to send the remaining 7 hidden bits at the same time.
Interframe space
Inter frame space is simply the interval between frames, but this interval only exists in data frames and remote frames in can frames. Other frames are not necessarily separated by inter frame space, but in other forms, or there is no interval directly. For example, there is no inter frame space between overload frames and error frames. There is a space between overload frames, but there is no space between frames.
The inter pin space mentioned here includes the bit fields of "intermittent" and "bus idle". If it is the station that sends the "passive error" of the previous message, it also includes a bit field called "pending transmission".
If it is not the station with "passive error" or the station as the receiver of the previous message, the inter frame space format is as follows:
If the station with "passive error" wants to send 8 hidden levels, when sending other frames, the inter frame space format is as shown in the figure below, including pending transmission,
Can see
The intermittent field has 3 hidden bits.
In particular, during the intermittent period, all nodes are not allowed to transmit data frames and remote frames. The only thing is to mark an overload condition.
Bus idle:
As long as the bus is idle, any node can send data to the bus, and it is the first time after the interval
Our other product: