2021-06-14 02:40 PM
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?
Solved! Go to Solution.
2021-06-18 07:05 AM
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.
2021-06-14 02:48 PM
2021-06-14 02:52 PM
I think it is a rounding error.
2021-06-14 03:10 PM
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)
2021-06-15 05:22 AM
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....
2021-06-18 07:05 AM
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.