cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Bus - how do I set baud rate on STM32F303x?

gbigden
Associate III
Posted on January 14, 2016 at 16:43

The default examples are for the Discovery board running at 72MHz. Mine is running at 65.536MHz, meaning that I need to adjust the baudrate to get the round number I desire eg 1M, 500k, 250k, 125k etc.

It is not obvious from the s/w how I do this.

#stm32 #can
1 REPLY 1
Posted on January 14, 2016 at 19:07

BAUD = (APB1CLK / PRESCALER) / (QUANTA SUMMED)

Presumably APB1 in your case is at 768 MHz, the real issue is that we are dealing with integer dividers. You'll have to build a fitter to take the desired baud rate, and input clock, and find the best combination of prescaler and bit quanta setting that get closest to your desired rate.

/* quanta 1+6+7 = 14, 14 * 24 = 336, 42000000 / 336 = 125000 */
/* CAN Baudrate = 125Kbps (CAN clocked at 42 MHz) Prescale = 24 */
/* Requires a clock with integer division into APB clock */
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; // 1+6+7 = 14, 1+14+6 = 21, 1+15+5 = 21
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler = RCC_Clocks.PCLK1_Frequency / (14 * 125000); // quanta by baudrate

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..