2017-08-05 11:12 AM
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 #hal2017-08-28 03:36 AM
bump... is it better to post these kinds of questions to stack-exchange?
2017-08-28 11:14 AM
Best wherever you can find HAL + FreeRTOS + CAN + F107 users. Bit outside my constituency, hence no response from me.
2017-08-28 11:35 PM
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.