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?

7 REPLIES 7
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

 

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

Well, the tranceiver i am using is a MCP2551:

Erwan03_0-1724935313863.png

 

A battery management system, an engine, a cluster, and a DC/DC converter are connected to the bus. I am connecting this system to the bus using a connector i don't know the reference. See: 

Erwan03_1-1724935487645.png

 

 

 

1- The part of the transceiver schematics is not clear to me.

2- But still you didn't answer that question:

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? 

3- But according to this statement: 


A battery management system, an engine, a cluster, and a DC/DC converter are connected to the bus. I am connecting this system to the bus using a connector i don't know the reference.


the issue could be related to the bus load and the CAN of your MCU could not find a window of 11 recessive bits and the other nodes are taking the bus and monopolizing it.

 

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.

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

The problem you do not understand is that a line which does a = b; results in a = c; (insted of a being equal to b).

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

I don't have any detailed schematic to show you unfortunately...

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