2016-01-14 07:43 AM
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 #can2016-01-14 10:07 AM
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