Skip to main content
Associate III
August 29, 2024
Solved

STM32F446RE: CAN hcan->State is always at listening state

Hello all,

 

I am working on a ECU system and using CAN protocol to communicate with peripheral.

The MCU i am using is a STM32F446re. I have a problem when trying to execute "HAL_CAN_Init(&hcan1)" function.

Indeed, the line "hcan->State = HAL_CAN_STATE_READY;" in this function, the State value becomes "HAL_CAN_STATE_LISTENING", "HAL_CAN_STATE_READY", although my PCB is link to the CAN bus.

Does anyone know how to fix it?

This topic has been closed for replies.
mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
August 29, 2024

I could use the exact same configuration and program a few weeks ago.

This problem has never happened before, and is happening right now, although i did not touch to the configuration nor to the program.


Since your application worked before and you didn't modify it, I suspect something in your HW.

Please check all the CAN HW part and check the connections and the wires continuity, the transceiver power etc ..

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

7 replies

mƎALLEm
ST Technical Moderator
August 29, 2024

Hello @Erwan03 ,

I didn't understand your issue. 

Mainly this statement:


Indeed, the line "hcan->State = HAL_CAN_STATE_READY;" in this function, the State value becomes "HAL_CAN_STATE_LISTENING", "HAL_CAN_STATE_READY", although my PCB is link to the CAN bus.

 

Could you please rephrase and give more details about the HW? provide schematics? 

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Erwan03Author
Associate III
August 29, 2024

ok sorry let me be explain myself.

 

Here is the schematic of my ECU prototype. I am using the CAN protocol to communicate with peripheral in the car.

The PCU on schem represents the F446RE

Erwan03_0-1724932834430.png

When i connect this guy onto the CAN bus, after setting the CAN transmission speed, setting the normal mode and enabling the interrupts, i am trying to debug my program.

Everything is fine until i reach the function of initialization of CAN "HAL_CAN_Init(&hcan1)". In this function, at the end, before the return value, the hcan->State variable should be set as "HAL_CAN_STATE_READY". This is ok but when i reach that line : "hcan->State = HAL_CAN_STATE_READY;" the expression of window shows me that the value is not set as HAL_CAN_STATE_READY, as expected, but as HAL_CAN_STATE_LISTENING. I don't know the reason.

 

Furthermore, here is the setting of the CAN on the .ioc file.

Erwan03_1-1724933330648.png

Erwan03_2-1724933361258.png

Erwan03_3-1724933384389.png

 

mƎALLEm
ST Technical Moderator
August 29, 2024

Hello,

Thank you for these details. Meanwhile you didn't provide the schematics but a sketch. What transceiver you are using?

Also, you didn't give details about CAN bus. What and how many nodes are connected to the bus? and how you connect your node to the bus? hot plug?

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