cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to understand the CAN1 BaudRate. Why can't I have a baud rate of exactly 1 Mbps?

KiptonM
Lead

I have a STM32F446 core and the Peripheral clock is 45 MHz.

I am looking at the RM0390 Rev 6 Section 30.7.7 Bit Timing

I am looking at the documentation Figure 395. Page 1063/1347

I want a bit rate of 1 million bits per second (Mbps)

In my calculation using the definitions in Figure 395, BRP = 14, TS1 = TS2 = 0 gives me exactly 1 Mbps.

But the Configuration Tool says the prescaler should be 16 (BRP = 15) which gives a Time Quantum of 355.555555555554 and with Time Quanta in Bit Segment 1 = 1 Time (TS1 = 0)

and Time Quanta in bit Segment 2 = 1 Time (TS2 = 0) The time for 1 bit is 1066.66 ns and the Baud Rate is 937500 bit/s

When I try to change the Prescaler (for Time quantum from 16 to 15 (BRP from 15 to 14) The Time Quantum is 333.3333333333...

the time for 1 bit is 999.99 ns (there is a truncation as opposed to rounding) and the Baud Rate is 1,000,000 bit/s

Am I getting hit with a floating point rounding error? And it thinks it is more than 1000000 bit/s as opposed to exactly 1000000 bit/s?

Can someone explain why it does not work with 15 (BRP 14) for the Prescaler (for the Time Quantum?

Is there more documentation on this in addition to RM0390?

This discussion is locked. Please start a new topic to ask your question.
1 ACCEPTED SOLUTION

Accepted Solutions
KiptonM
Lead

Found the solution. there was a Java bug in the calculation. I upgraded STM32CubeMX to the latest version from 6.1.1.20201209 to 6.2.1.20210324 and it now gives me Time for 1 bit 999.99 ns and Baud Rate 1000000 bit/s.

View solution in original post

5 REPLIES 5
KiptonM
Lead

0693W00000BaxsrQAB.png

KiptonM
Lead

I think it is a rounding error.

0693W00000BaxtkQAB.png

Pretty sure the goal is not to have a 1+1+1 solution, but rather that you prescale by 3 and then have the timings add to 15 (SJW + BS1 + BS2)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I had the same problem, i fixed it by rising the peripheral clock frequency.

I also think this is a java rounding bug from cubemx.

You can always try to set the time quantas you want after the code is generated by cubeMX.

Overwrite them before can_init and take your chances....

Available for consulting/freelancing , hit me up in https://github.com/javiBajoCero
KiptonM
Lead

Found the solution. there was a Java bug in the calculation. I upgraded STM32CubeMX to the latest version from 6.1.1.20201209 to 6.2.1.20210324 and it now gives me Time for 1 bit 999.99 ns and Baud Rate 1000000 bit/s.