CAN Bus recovery
When the CAN BUS goes bus-off, what are the necessary steps to recover the module?
There is a note in the HRM, but it's not very clear as to the actual steps needed to perform this operation:
During the bus-off recovery sequence, the configuration mode request CAN_CTL.CCR bit is set by the internal logic, and the CAN core module does not automatically come out of the bus-off mode. The CAN_
CTL.CCR bit cannot be reset until the bus-off recovery sequence has completed.
NOTE: This behavior can be overridden by setting the CAN_CTL.ABO bit. After exiting the bus-off or configuration modes, the CAN error counters are reset.
can bus
cm408
Hi Claudio,
Which processor you are using? The CAN module on ADI DSPs conforms CAN2.0B (active) standard. And as per CAN spec, "An node which is 'bus off' is permitted to become 'error active' (no longer 'bus off') with its error counters both set to 0 after 128 occurrences of 11 consecutive 'recessive' bits have been monitored on the bus".
That mean, after CAN bus off condition, the node has to wait for 128 occurrences of 11 consecutive recessive bits. Following this, the node can be re-initialized and continue the normal operation.
If you set CAN_CTL.ABO bit, DSP CAN module will take care of this recommended sequence and will put device error active mode. If you want to implement this wait in software, you can do that either by setting CAN_CTL.ABO=0
-pg
Hi Claudio,
I am not sure why are going for automatic bus recovery. Is there any reason in implementing software based recovery logic? If you suspect incorrect baud-rate configuration at your end, then you can make use of GP Timer (which is multiplexed with CAN_RX pin) configured in width capture mode, to check baud rate received on CAN_RX pin.
BTW, about your question "When the CANBUS stops working, the CAN1_STAT() ISR gets called, but I don't know what to do. Do I put CAN_CTL.ABO=0 in the ISR?"
>> ABO bit should be configured (0/1) at the start (i.e. before coming out of configuration mode).
Also just want to add that, CAN Status interrupt is a shared interrupt between different error interrupts such as bus-off, Error warnings, Rx message lost and many, as described in HRM. So, you should not simply clear all the interrupt flags by writing 0xFFFF into it. You can check the status one-by-one and take appropriate action.
-pg
Hi, Prashaant,
Thanks for getting back to me. I've never used the CANBUS before. I might need your help to implement the protocol recovery on my CM408F chip. I use my own firmware to control the CANBUS.
I can capture the status bits with my own ISR:
#pragma call_graph_root
__root void CAN1_STAT()
{
StatusFlags = *pREG_CAN1_GIF;
*pREG_CAN1_GIS = 0xFFFF;
asm("NOP");
}
When the CANBUS stops working, the CAN1_STAT() ISR gets called, but I don't know what to do. Do I put CAN_CTL.ABO=0 in the ISR?
Hi, Prashant,
So, to give you some background. I have 2 custom CM408F boards that communicate via CANBUS. The bus is working and I can send bi-directional data along the CANBUS. It's very reliable and I like it a lot.
Sometimes, when I am debugging and programming the first board, the CANBUS enters BUS-OFF on the second board (I guess the second boards detects that the first's boards CANBUS is not there).
Right now, I press RESET on the second board to recover the CANBUS. When the boards are in the field, they won't be able to hit the reset button if for some reason the CANBUS enters BUS-OFF. So, I just want to be able to automatically recover the bus (as these boards will be in operatorless environments).
Again, I am new to the CANBUS so I don't know what are the appropriate actions needed to recover the BUS. :-)
Thanks,
Claudio
Hi Claudio,
If you want to automatically recover the bus from bus-off state, set the CAN_CTL.ABO bit when configuring the CAN module of dsp. So due to error conditions, if CAN node enters the bus-off mode, the module will take care of bus recovery (will monitor CAN bus to detect 128 occurrences of 11-recessive bits).
I am not sure, but are you looking to implement this auto-recovery sequence (monitoring the CAN bus for 128 occurrences of 11-recessive bits) in the software? If so, is there any reason why you are looking to implement it software instead of using feature provided by CAN module?
-pg
This question has been assumed as answered either offline via email or with a multi-part answer. This question has now been closed out. If you have an inquiry related to this topic please post a new question in the applicable product forum.
Thank you,
EZ Admin
Please log in to reply.