What's the right CAN bus settings for STM32F4-Disc for 250 kbit/s by using nanoFramework?

218 Views Asked by At

I'm trying to connect a Blue Pill board (set up by STM32CubeMX) with STM32F4-Discovery (set up by ChibiOS and nanoFramework).

The Blue Pill has these parameters:

  • APB1 peripheral clock: 24 MHz
  • Prescaler (for Time Quantum): 6
  • Time Quantum: 250.0 ns [as result]
  • Time Quanta in Bit Segment 1: 13 Times
  • Time Quanta in Bit Segment 2: 2 Times
  • Time for one Bit: 4000 ns [as result]
  • Baud Rate: 250 000 bit/s [as result]
  • ReSynchronization Jump Width: 1 Time

Clock configuration in ChibiOS for Discovery board (mcuconf.h):

#define STM32_SW            STM32_SW_PLL
#define STM32_PLLSRC        STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE    4
#define STM32_PLLN_VALUE    168
#define STM32_PLLP_VALUE    2
#define STM32_PLLQ_VALUE    7
#define STM32_HPRE          STM32_HPRE_DIV1
#define STM32_PPRE1         STM32_PPRE1_DIV8

My calculation for the APB1 peripheral clock of the Discovery board:

Fext_osc / PLLM * PLLN / PLLP / HPRE / PPRE1 = 8 000 000 / 4 * 168 / 2 / 1 / 8 = 21 MHz

I tried to set up CAN of the Discovery board in code:

var canSettings = new CanSettings(6, 11, 2, 1);

where

  • Bus baud rate prescaler: 6
  • [Time Quantum: 6 / 21+E6 = 285.71 ns as result]
  • Phase segment 1: 11
  • Phase segment 2: 2
  • [Time for one Bit: 285.71-E9 * (1 + 11 + 2) = 4000 ns as result]
  • [Baud Rate: 1 / 4-E6 = 250 000 bit/s as result]
  • Synchronization jump width: 1

The connection doesn't work.

If I use settings from some code sample for unknown speed—CanSettings(6, 8, 1, 0)—it works, but it's 350 kbit/s (for a 21 MHz APB1 clock).

How can I fix this?

1

There are 1 best solutions below

0
On

Here's the documentation about CanSettings. Make sure to pass those values to the constructor in the correct parameters.

I haven't validated if they are correct though. I suggest that you use one of STM calculators to make it easy.