CAN Protocol in STM32

Harshdixit
5 min readJun 9, 2023

--

CAN( Controlled Area Network ) Protocol is a way of communication between different devices, but under certain rules. These rules must be followed when a message is transmitted over the CAN bus.

Shown below is the Standard CAN frame:

CAN Frame

here Identifier is the ID of the transmitting Device

. RTR ( Remote Transmission Request ) Specifies if the data is Remote frame or Data frame.

.IDE specifies If we are using Standard ID or Extended ID

. r is the Reserved Bit .

. DLC specifies the data length in Bytes .

. Data Field is where we can send the data, which should be upto 8 bytes

. Checksum and DEL are the CRC data and it’s Delimiter.

. ACK and DEL is the acknowledgment bit and it’s Delimiter

It was originally developed by Robert Bosch GmbH as a reliable communications bus for automotive system.

Due to its robust noise immunity, fault tolerance, and low cost, it is used extensively in modern automotive system. Due to its robust noise immunity, fault tolerance, and low cost, it is used extensively in Modern automobiles , heavy equipment, factory automation and sea-craft.

Digiview for CAN protocol

SOF is start of Frame which indicates that the new frame is entered in a network. It is of 1-bit.

Identifier A standard data format defined under the CAN 2.0 A specification uses an 11–bit message identifier for arbitration. this message identifier sets the priority of the data frame.

RTR RTR stands for Remote Transmission Request , which defines the data frame or remote frame . It’s a 1-bit.

Control Field It has user-defined functions.
IDE : An IDE bit in a control field stands for identifier extension. A dominant IDE bit defines the 11-bit standard identifier, whereas recessive IDE bit defines the 29-bit extended identifier .

DLC: DLC stands for Data length Code, which defines the data length in a data field. It is of 4-bits.

Data Field : The data field can contain upto 8 Bytes .

CRC Field : The data frame also contains a cyclic redundancy check field of 15-bit, which is used to detect the corruption if it occurs during the transmission time. The standard will compute the CRC before sending the data frame, and the reciever also computes the CRC and then computed CRC with the CRC recieved from the sender. If the CRC does not match, then the reciever will generate the error.

ACK Field: This is the reciever’s acknowledgement. In the other protocols, a seperate for an acknowledgement is sent after receiving all the packets, but in case of CAN protocol, no seperate packet is sent for an acknowledgement,

EOF EOF stands for end of frame. It Contains 7 Consecutive recessive bits known End of frame.

CAN Node

Host : A Host is a microcontroller or microprocessor which is running some applications to do a specific job.

CAN Controller : CAN Controller deals with the communication functions described by the CAN protocol. It also triggers the transmission, or the reception of the CAN message.

CAN Transceiver :
CAN transceiver is responsible for the transmission or the reception of the data on the CAN bus. It converts the data signal into the stream of data collected from the CAN bus that the CAN controller can understand.

CAN Characteristics

CAN Characterstics

It has two line CANH and CANL with the help of Differential Volatage , we will determine how 0 and 1 are transmitted through the CAN bus. The above figure is the voltage .

A zero volt on CAN bus is read by the CAN transceiver as a recessive or logic 1. A zero volt on CAN bus is an ideal state of the bus. When CAN high line is pulled up to 3.5 volt and the CAN low line is pulled down to 1.5 volt, then the bus’s actual differential voltage would be 2 volts. It is treated as a dominant bit or logic 0 by the CAN transceiver. If the bus state is reached to dominant or logic 0 then it would become impossible to move to the recessive state by any other node.

Key points learnt from the CAN characteristics

  • Logic 1 is a recessive state. To transmit 1 on CAN bus, both CAN high and CAN low should be applied with 2.5V.
  • Logic 0 is a dominant state. To transmit 0 on CAN bus, CAN high should be applied at 3.5V and CAN low should be applied at 1.5V.
  • The ideal state of the bus is recessive.
  • If the node reaches the dominant state, it cannot move back to the recessive state by any other node.

CAN Bus Logic

Wired-AND Logic

CAN communication

CAN Communication Path

We will see code and Example in CAN Part-II

--

--