Skip to main content
KiptonM
Senior III
June 14, 2021
Solved

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

  • June 14, 2021
  • 3 replies
  • 1672 views

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 topic has been closed for replies.
Best answer by KiptonM

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.

3 replies

KiptonM
KiptonMAuthor
Senior III
June 14, 2021

0693W00000BaxsrQAB.png

KiptonM
KiptonMAuthor
Senior III
June 14, 2021

I think it is a rounding error.

0693W00000BaxtkQAB.png

Tesla DeLorean
Guru
June 14, 2021

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 VenmoUp vote any posts that you find helpful, it shows what's working..
KiptonM
KiptonMAuthorBest answer
Senior III
June 18, 2021

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.