cancel
Showing results for 
Search instead for 
Did you mean: 

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

Erwan03
Associate III

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?

2 REPLIES 2
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

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