2024-08-29 02:04 AM - last edited on 2024-08-29 02:12 AM by SofLit
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?
Solved! Go to Solution.
2024-08-29 07:24 AM
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 ..
2024-08-29 02:38 AM
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?
2024-08-29 05:09 AM
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
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.
2024-08-29 05:31 AM
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?
2024-08-29 05:45 AM
Well, the tranceiver i am using is a MCP2551:
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:
2024-08-29 06:18 AM
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.
2024-08-29 07:19 AM
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...
2024-08-29 07:24 AM
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 ..