CANBus using ST Official Library on STM32F303RE
Posted: Wed Jan 08, 2020 1:09 am
I am trying to configure the CAN baud on my Nucleo F303RE, although all examples I see online do not match how Iv read to calculate them. From what I understand, the Clock rate for the ABP is 36Mhz, want a sample point of about 75-90% with a SJW of 1.
For example, using this site for the calcs for 1000kbit/s: http://www.bittiming.can-wiki.info/
We get..
Prescaler 2
Seg1 = 15
Seg2 = 2
tq = 15+2+1 =18
Now to calculate the baud using these details, we do:
36000000/ ((Swj+Seg1+Seg2)*Prescaler)
36000000/ 18*2 = 1,000,000b/s = 1000kb/s
Sample point = 15+1/18 = 88.9%
So.. this makes sense and works.. now using the exmaple from ST found here which is setup for 1000kbit/s also for a F3 device: https://github.com/eleciawhite/STM32Cub ... Src/main.c
It uses (See image below for clock setup):
CanHandle.Init.SJW = CAN_SJW_1TQ;
CanHandle.Init.BS1 = CAN_BS1_6TQ;
CanHandle.Init.BS2 = CAN_BS2_8TQ;
CanHandle.Init.Prescaler = 2;
So, this results in:
36000000/ (1+6+8)*2 = 36000000/30 = 1,200,000b/s = 1.2kb/s
Sample point would be Seg1+Sjw/Tq.. so this is 7/15 = 46.7%
Am I just really screwing up on the calculations.. or is the example out??
For example, using this site for the calcs for 1000kbit/s: http://www.bittiming.can-wiki.info/
We get..
Prescaler 2
Seg1 = 15
Seg2 = 2
tq = 15+2+1 =18
Now to calculate the baud using these details, we do:
36000000/ ((Swj+Seg1+Seg2)*Prescaler)
36000000/ 18*2 = 1,000,000b/s = 1000kb/s
Sample point = 15+1/18 = 88.9%
So.. this makes sense and works.. now using the exmaple from ST found here which is setup for 1000kbit/s also for a F3 device: https://github.com/eleciawhite/STM32Cub ... Src/main.c
It uses (See image below for clock setup):
CanHandle.Init.SJW = CAN_SJW_1TQ;
CanHandle.Init.BS1 = CAN_BS1_6TQ;
CanHandle.Init.BS2 = CAN_BS2_8TQ;
CanHandle.Init.Prescaler = 2;
So, this results in:
36000000/ (1+6+8)*2 = 36000000/30 = 1,200,000b/s = 1.2kb/s
Sample point would be Seg1+Sjw/Tq.. so this is 7/15 = 46.7%
Am I just really screwing up on the calculations.. or is the example out??