Skip to main content
Associate II
July 10, 2024
Solved

HAL_CAN_Transmit behavior for CAN Bus OFF

  • July 10, 2024
  • 1 reply
  • 2165 views

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!

Best answer by mƎALLEm

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:

SofLit_0-1720636072735.png

Page 1108:

SofLit_1-1720636188592.png

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

SofLit_0-1720646594912.png

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.

 

1 reply

mƎALLEm
Technical Moderator
July 10, 2024

Hello,

Did you set the Automatic bus-off ?

SofLit_0-1720632625468.png

i.e.:

CanHandle.Init.AutoBusOff = ENABLE;

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
krishrAuthor
Associate II
July 10, 2024

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.

mƎALLEm
mƎALLEmBest answer
Technical Moderator
July 10, 2024

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:

SofLit_0-1720636072735.png

Page 1108:

SofLit_1-1720636188592.png

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

SofLit_0-1720646594912.png

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.

 

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