STM32 - CAN bus baud rate and bit timing Detailed

I am using a microcontroller is STM32F407, similar to other types of microcontrollers, do reference!

First, the standard CAN protocol bit timing concept

Since CAN is an asynchronous communication, no clock signal lines connected between the serial asynchronous communication will be like the same bus as each node in the network, the nodes using the convention baud good communication.
Meanwhile, CAN also use the " bit synchronization " approach to interference, absorption error, the bus signal level to achieve correct sampling, to ensure normal communication.
To achieve this synchronization bit, CAN protocol the timing of each bit is decomposed into four: SS segment, PTS section, PSB1 section, PBS2 section. While the minimum time unit is defined: Tq, the length of the segment is represented by four x one Tq, add up to a bit sequence.

Use a diagram to represent the image may be a little, timing is shown a bit is 19Tq.

 

These are the standard protocols defined CAN bit timing, and the STM32 peripherals simplifies this standard.

 Two, STM32 the CAN bus bit timing concepts

Peripheral CAN bit timing STM32 contains only three segments: segment sync SYNC_SEG, BSl bit segment (the segment or merged PSB1 PTS) and bit segment BS2.

 

Wherein the length of the fixed SYNC_SEG 1Tq, two other lengths may be provided in CAN_BTR.

 

Here we should pay attention to detail, the length of the time period BS1 is actually equal to +1 value we write, the same segment BS2 is.

Third, the baud rate is calculated

After setting the length of the segment BS1 and BS2 section, we can determine the length of each data bit of the CAN.

BS1 period of time: Ts1 = Tq is * (TSI1 [. 3: 0] +. 1)
BS2 period of time:: Ts1 = Tq * (+ 1 TSI2 [0 2])
time of a data bit: T1bit = Ts1 + Ts2 is 1 TQ +

The time of one data bit found: Baud Rate = 1 / T1bit

This formula also an unknown quantity of Tq. 

In the CAN peripheral configuration and a parameter related to the baud rate is BRP (Baud Rate Prescaler)

         

 

CAN1 peripheral I use is mounted on STM32F407 APB1 bus, its default clock frequency 45M, Tpclk = 1 / 45M.

The BRP defined parameters: Tq is BRP = [. 9: 0] * TPCLK

Such value Tq even out, into the above formula can be determined baud rate the baud rate of the CAN bus transfer.

 

 

 

Guess you like

Origin www.cnblogs.com/Irvingcode/p/11802541.html