Skip to main content
Graduate
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!

    This topic has been closed for replies.
    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

    Technical Moderator
    July 10, 2024

    Hello,

    Did you set the Automatic bus-off ?

    SofLit_0-1720632625468.png

    i.e.:

    CanHandle.Init.AutoBusOff = ENABLE;

     

    krishrAuthor
    Graduate
    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ƎALLEmAnswer
    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.