Open
Description
Following on from #295
Here's another small code change to the CAN baud rate calculation to support the allowable error between the theoretical bit rate and the calculated bit rate to be an absolute value.
Current behaviour for a theoretical bus speed of 16,666.666' shows the following states:
- CAN.begin(16666) succeeds - the absolute error is 0.003200128
- CAN.begin(16667) fails - even though the absolute error is smaller at 0.001599968
Code change is required in CanUtil.cpp ...
/* If the fractional part is sufficiently close to zero, we have
* found a valid prescaler configuration.
*/
if (brp_fract < 0.01)
... it should be checking either side of the desired rate
/* If the fractional part is sufficiently close to zero, we have
* found a valid prescaler configuration.
*/
if (brp_fract < 0.01 || brp_fract > 0.99)