cancel
Showing results for 
Search instead for 
Did you mean: 

CAN1 loopback does not work on STM32F427

Louis00
Visitor

Hello everyone,

I have recently been trying to get the CAN1 bus working on the STM32F427. So far, however, it has not worked in either loopback or normal mode. For the normal mode I had a CANCaseXL Analyzer available. The problem, however, is that not even the loopback works. I have attached the main.c file and the ioc project file.

When I call HAL_CAN_AddTxMessage(), I get HAL_OK back, so that seems to work. However, I have set a breakpoint in the CAN interrupt handler (HAL_CAN_IRQHandler() in file stm32f4xx_hal_can.c) and there I see that the TERR0 bit gets set. Accordingly, the transmission process has failed. I have already tried many other possibilities, which unfortunately did not work either.

Maybe someone has an idea. Many thanks in advance!

Louis

1 REPLY 1
SofLit
ST Employee

Hello,

At first check at your ioc file, I don't recommend these values for CAN bit timing:

 

hcan1.Init.Prescaler = 16;
hcan1.Init.TimeSeg1 = CAN_BS1_1TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;

 

BS1_1TQ and BS2_2TQ are very low. You need to increase them as much as possible by decreasing the prescaler as much as possible.

I recommend these values for 500kb/s:

SofLit_0-1720537708434.png

Also, we don't recommend HSI as clock source when using CAN in Normal mode. You need to use HSE with an external crystal otherwise you may face communication issues.

SofLit_0-1720537957478.png

 

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.