CAN bus / Habr

Short description

The CAN bus (Controller Area Network) is a twisted pair with a resistance of 120 ohms that consists of a high and low voltage line for data transfer. It has a speed up to 1mb/s for shorter lengths and 10kb/s for longer lengths. The bus is not sensitive to guidance and uses NRZ encoding, with a bit stuffing technique used to avoid desynchronization. Collision Resolution (CR) is used to prioritize transmitters and resolve collisions. The transfer protocol DATA FRAME consists of a starting bit, a unique message number, data length, data block, checksum, and confirmation bit. The CAN bus is recommended for those interested in electrical engineering and electronics.

CAN bus / Habr

Hello everybody! I am a beginner developer and I am interested in the Embedded side of the issue. The best way to remember information is to write an outline and share it. Below is my short summary about the CAN bus and data transfer through it:

CAN bus (Controller Area Network).

The bus is a twisted pair separated by resistors with a resistance of 120 Ohms. It consists of a high voltage line (H – high) and a low voltage line (L-low).

Brief characteristics:

Speed ​​1 mb/s for bus lengths up to 40 meters (Car or room).

The speed is 10 kb/s for bus lengths up to 1000 meters (building).

Receivers and transmitters are equal in the CAN bus.

When no one transmits a signal on the bus, both H and L are 2.5 volts each. When there is a signal – on H 3.5V and line L – 1.5V. By the difference between H and L, the transceivers understand that the transmission has started. Therefore, the CAN bus is not sensitive to guidance. The voltage on the twisted pair may be different – the bus understands the start of reception or transmission by the difference between L and H.

When zero is received at the input of the transmitter, the transmitter increases H voltage. All other receivers understand that the signal transmission has started. Encoding is performed in NRZ format:

Dominant bit – the state when H>L is on the bus – corresponds to the 1st.

Recess bit – the state when the line has no signal is perceived as zero.

The bit change occurs according to the frequency of the transmitter. The frequency of the receivers may differ slightly, so that a large sequence of repeating signals can lead to desynchronization. Therefore it is used

bit stuffing.

Bit stuffing – 5. If there are 5 identical bits, the transmitter sets the opposite bit. All receivers ignore this bit. If receivers see 6 identical bits in a row, they understand that an error has occurred and ignore the message.

Collision Resolution (CR) – if two transmitters start transmitting at the same time – priority is given to the one that transmits more units. Suppose two transmitters started talking at the same time. Both transmit 3 units, on 4 bits one of them does not display a signal, but detects that there is a drop on the bus – this way he understands that someone is transmitting the signal in parallel with him and shuts up.

CR is more effective than Collision Detection in ethernet, because in CD, if two transmitters are detected, both are silenced and start transmission after some random time interval.

Transfer protocol DATA FRAME. Data transfer when a device shares data.

S – starting bit – always Dominant bit. All receivers are synchronized in it. A zero is received at the input of the receiving transmitter and it applies voltage to the H bus, thereby creating a difference.
ID – Unique message (command) number. By it, the receivers understand whether they need this message or whether it is addressed to someone else. In the standard version CAN 11 bits, in CAN2.0b – 29 bits.

D length – Specifies the length in bytes of the data block.
Data – the message itself from 0 to 8 bytes.

CRC – A 2-byte checksum.

ACK. After transmitting the CRC, the receiver receives the message and sets the confirmation bit if the sum matches. The transmitter sees that the receiver received the message and then sets 7 bits of the Reces signal – EOF.

I recommend the channel to everyone who is interested in Electronics and Electrical Engineering Electrical engineering and electronics for programmers. If something is not clear or incorrectly explained – write and I will correct it. The original original source of the article – lecture 403 CAN bus – introduction.

Related posts