How do I set the baud rate for the CAN bus?

Tim Rohaly

There is no method to directly set the baud rate - instead you must set the appropriate combination of bus timing parameters. The baud rate is calculated as:

baud rate (bits per second) = 18.432 x 10^6 / BRP / (1 + TSEG1 + TSEG2)
where 18.432 MHz is the frequency of the clock crystal on the TINI and where BRP, TSEG1, and TSEG2 can be set using methods in the com.dalsemi.comm.CanBus class:
  • setBaudRatePrescaler() changes BRP to values between 1 and 256
  • setTSEG1() changes Timing Segment 1 to values between 2 and 16
  • setTSEG2() changes Timing Segment 2 to values between 2 and 8
The steps to set the baud rate then look something like this:
    CanBus bus = new CanBus(CanBus.CANBUS0);
In order to comply with the CAN specification, the calculated baud rate must match the desired baud rate to within 0.5% in order for two CAN devices to properly communicate. Some combinations of BRP, TSEG1, and TSEG2 for commonly-used baud rates are:

10 Kbps88137
20 Kbps7157
20 Kbps44137
50 Kbps4135
50 Kbps23105
125 Kbps 7137

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact