2024-07-10 05:38 AM
Hi,
When i use HAL_CAN_Transmit to send a CAN message on STM32F4, if say I am in error passive or bus off condition, what error does the API return? If I am in error passive, what is the best way to reset the error count to 0?
Where can i get the error flags related to this as the HAL_CAN_Transmit does not return the error status such as passive or bus off?
There are only two nodes on the bus.
Thanks in advance!
2024-07-10 10:32 AM
Hello,
Did you set the Automatic bus-off ?
i.e.:
CanHandle.Init.AutoBusOff = ENABLE;
2024-07-10 11:11 AM
Thanks for your reply, AutoBusOff is enabled. There are only two nodes on the bus and after some period of time (say days), one node is going into error passive (say when TEC exceeds 128). So when the other node requests some data, the second node is not able to respond for a long period of time. This leads to a communication loss. I wanted to know how to reset the error states in such conditions.
2024-07-10 11:35 AM - edited 2024-07-10 02:23 PM
Hello,
Each time you have a question, it's recommended to first refer to the documentation either the reference manual or the datasheet.
In your case you need to refer to RM0090:
Figure 345:
Page 1108:
As you see TEC and REC counters are read only bits. So you can't reset them by software but you need conditions described in the CAN standard to reset them.
See for example this link https://www.csselectronics.com/pages/can-bus-errors-intro-tutorial#:~:text=Specifically%2C%20every%20CAN%20node%20keeps,if%20the%20TEC%20exceeds%20255
Especially the section CAN node states & error counters
But as you have errors with only two nodes you need to check your hardware, your tranceiver, its power supply, your wiring, what about terminating resistors ? do you have any EMI issues? see this link.
2024-07-10 11:52 PM
Thank you for your reply. I will check the points you have explained and revert.