cancel
Showing results for 
Search instead for 
Did you mean: 

Most proper way of detecting CAN BUS OFF condition?

David Wallén
Associate III

Dear ST community,

We are running a CAN network with a lot of nodes (>200) using the STM32F107VCTx chip (and MCP2551 transciever) all receiving instructions from a central linux embedded computer with a MCP2515 CAN Controller.

Sometimes the nodes stop replying on messages and we need to power cycle the nodes in order for communication to resume. We suspect the nodes have gone bus-off, but want a bit more information in order to be completely sure.  

From the STM32 manual it seems that the CAN error states can be derived from reading the TEC from the CAN_ESR register. 

I have two questions: 

 1. Is there any example code somewhere that showcase a separate driver accessing these registers?

 2. Is there any other more proper way track the CAN error states from my parts of the code, i.e. some HAL library "get_CAN_state" function I could call that handles the registry access and state translation for me?

Many thanks in advance!

BR,

David

1 REPLY 1
Ozone
Lead

This is part of the CAN bus spec, and implemented in the CAN peripheral (usually licenced directly from Bosch). The status (counters, error-passive, bus-off) is available in peripheral registers.

A unit counts bus errors, goes into the "error passive" state after a certain amount of successive errors (usually 128), and finally in the "bus-off" state (256 errors).

Each successful frame decrements this counter. Check the available specs and documentations.

If you get into bus-off, you have a serious problem in your network.

In our test setup, we use to short the CAN-H and CAN-L lines to provoke this error.