cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get 250 kHz CAN Bus with STM32F042G6U6 using HSE 8 MHz and STM32CubeIDE generated code?

ZPrib
Associate II

When using HSI RC, everything works fine. After switching to HSE, Pinout&Configuration tab in STM32CubeIDE calculates a wrong TQ, as far as I can see. I use 250 kHz Bus, so 4 MHz clock results in TQ 250 ns. 16 TQ is 250 kHz.

For example, for PLLMult 4

0693W000001cTKAQA2.png

I get, for prescaler 2 62.5 ns, although the value should be 250 ns:

0693W000001cTKyQAM.png

I think that cannot be right, as my scope shows that frequency is 250 kHz:

0693W000001cTLNQA2.png

and the device works fine in 250 kHz bus. Therefore, the prescaler divides external 8 MHz frequency by 2 and 4 MHz is 250 ns. If I choose any other prescaler, I get a wrong frequency.

The way to do it is to generate code with setup in the first 2 pictures and then change

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;

into

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;

in the generated code.

If I try to choose multiplier 6, the IDE refuses to generate code as it calculates a wrong TQ.

Am I doing something wrong?

1 REPLY 1
ZPrib
Associate II

The problem was in external clock was 6 times slower than I thought. So, it was my mistake. I must nevertheless note that from some other manufacturers I got very helpful answers within 24 hours, that help me solve the problem. Here, 3 months and nothing.