Hardware manual
RX600 Series CAN Application Programming Interface
R01AN0339EU0203 Rev. 2.03 Page 11 of 29
Mar 23, 2013
R_CAN_SetBitrate
Sets the CAN bitrate (communication speed)
The baud rate and bit timing must always be set during the configuration process. It can be changed later on if reset
mode is entered.
Format
void R_CAN_SetBitrate(const uint32_t ch_nr);
Arguments
ch_nr 0,1,2,3 Which CAN bus to use. 1-4 channels may be available.
Return Values
-
Properties
Prototyped in r_can_api.h
Implemented in r_can_api.c
Comments
A Time quanta, Tq, is one bit-time of the CAN system clock, fcanclk. This is not the CAN bit-time but the internal
clock period of the CAN peripheral. This CAN system clock in turn is determined by (twice) the Baud Rate
Prescaler value and the peripheral bus clock, fclk, to create the CAN system clock.
Setting the baud rate or data speed on the CAN bus requires some understanding of CAN bit timing and MCU
frequency, as well as reading hardware manual figures and tables. The default bitrate setting of the API is
500kB, and unless the MCU clock or peripheral frequencies are changed, it is sufficient to just call the function.
One bit time is divided into a number of Time Quanta, Tqtot. One Time Quantum is equal to the period of the CAN
clock. Each bitrate register is then given a certain number of Tq of the total of Tq that make up one CAN bit
period.
Formulas to calculate the bitrate register settings.
PCLK is the peripheral clock frequency.
fcan = PCLK
The prescaler scales the CAN peripheral clock down with a factor.
fcanclk = fcan/prescaler
One Time Quantum is one clock period of the CAN clock.
Tq =1/fcanclk
Tqtot is the total number of CAN peripheral clock cycles during one CAN bit time and is by the peripheral built by
the sum of the “time segments” and “SS” which is always 1.
Tqtot = TSEG1 + TSEG2 + SS (TSEG1 must be > TSEG2)
The bitrate is then
Bitrate = fcanclk/Tqtot
SS is always 1. SJW is often given by the bus administrator. Select 1 <= SJW <= 4.
See CONFIG_R_CAN_RAPI.H for more details.
Example
/* Set bitrate as defined in config_r_can_rapi.h. */
R_CAN_SetBitrate(0);