Skip to content

Commit

Permalink
Fix for #295 to allow flexible bit rate either one of the 4 predefine…
Browse files Browse the repository at this point in the history
…d rates or a custom rate
  • Loading branch information
fastbike authored and aentinger committed May 3, 2024
1 parent 78b63e9 commit 30f0467
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libraries/Arduino_CAN/src/R7FA4M1_CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool R7FA4M1_CAN::begin(uint32_t const can_bitrate)

/* Calculate the CAN bitrate based on the value of this functions parameter.
*/
static uint32_t const F_CAN_CLK_Hz = 24*1000*1000UL;
static uint32_t const F_CAN_CLK_Hz = 24*1000*1000UL;
static uint32_t const TQ_MIN = 8;
static uint32_t const TQ_MAX = 25;
static uint32_t const TSEG_1_MIN = 4;
Expand All @@ -172,7 +172,7 @@ bool R7FA4M1_CAN::begin(uint32_t const can_bitrate)
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
util::calc_can_bit_timing(can_bitrate, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX);
init_ok &= is_valid_baudrate;

if (is_valid_baudrate) {
_can_bit_timing_cfg.baud_rate_prescaler = baud_rate_prescaler;
_can_bit_timing_cfg.time_segment_1 = time_segment_1;
Expand All @@ -187,6 +187,7 @@ bool R7FA4M1_CAN::begin(uint32_t const can_bitrate)
return init_ok;
}

////////////////////////
void R7FA4M1_CAN::end()
{
R_CAN_Close(&_can_ctrl);
Expand Down

0 comments on commit 30f0467

Please sign in to comment.