cancel
Showing results for 
Search instead for 
Did you mean: 

HAL CAN recovery example

DJC
Senior
Posted on August 05, 2017 at 20:12

Is there a good example on how to restart CAN after it turns off due to too-many bus errors?

I have a CAN bus with a lot traffic and its quite normal for a particuar device to fail on re-transmit a large number of times. 

When it happens, i would like the MCU to detect it and restart the node after a fixed time period. 

I dont have a requirement to adhere to any standards in my project.

Also i dont really understand how to '(128 occurrences of 11 consecutive recessive bits monitored on CANRX)' as per the standard documentation with respect to using the ABOM for this. 

Im running FreeRTOS and HAL on an STM32F107, but i guess any clue to an stm32 example would be great. 

#can #restart #hal
3 REPLIES 3
DJC
Senior
Posted on August 28, 2017 at 12:36

bump... is it better to post these kinds of questions to stack-exchange?

Posted on August 28, 2017 at 18:14

Best wherever you can find HAL + FreeRTOS + CAN + F107 users. Bit outside my constituency, hence no response from me.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Kraal
Senior III
Posted on August 29, 2017 at 08:35

Hi !

I don't know about the CAN peripheral in the F107, but it is the same as the one in the F042 then I can help you. And I'm not using the ABOM bit, I do everything manually (since in my system a bus OFF is very unlikely to happen).

When the bus OFF flag is set in the CAN->ESR register, it means that the peripheral has turned OFF because of too many errors on the bus. So if you want to detect that condition, you have to monitor the flag BOFF in the ESR register. Then the only way to recover is to put the CAN peripheral in initialization mode and then go back to normal mode, i.e. set the INRQ bit in CAN->MCR, monitor the INAK bit to be sure that the peripheral is initializing, reset the INRQ bit and again monitor the INAK bit to be sure that the peripheral is back to normal mode.

Now what I found not clear in the reference manual is that the BOFF flag will still be set as long the CAN peripheral has not monitored 128 occurrences of 11 consecutive recessive bits on CANRX. As soon as BOFF is cleared then the CAN is good to go.