I am running some code on a MOD5234 that uses CAN. I've noticed that when debugging through NBEclipse, the CAN works perfectly until the debugger stops the program, and then after continuing execution I won't receive any more CAN messages. When I use taskscan or pause the debugger again, it tells me that the code is always waiting on the CAN fifo. This behavior occurs both when hitting a breakpoint and when using the Suspend button to halt execution. The code is still running, I can interact over the the serial port and access the hosted webpage just fine. Has anyone else experienced this issue or have any ideas for troubleshooting?
Here is the relevant code if it helps. It runs in its own task (prio=49).
I get the same with a Philips SJA1000 device I am using with a Rabbit processor. If I hit a breakpoint and delay too long, the CAN stops working.
What is happening for me is that the bus eventually goes OFF BUS because of too many errors or in my case, overflow of the receive buffer. I detect this in code and then clear the errors and restart the bus and then it works again.
You may have to do something similar. Check the ERROR states of the CAN controller and you may find it has gone off bus. Simply reset the errors and the bus should work again.
Good to know this though as I am about to start the development of CAN on my MOD5234 based system in the next few weeks.
Thanks for the suggestions, it led me to a solution that's a bit strange, but seems to work. The status registers still appeared to contain valid values after the CAN stopped working, but just the act of reading the registers was enough to snap it back into a working state. I narrowed it down to the timer register specifically, so instead of waiting forever on incoming CAN, I do this:
CanRxMessage canRaw(&fifo, TICKS_PER_SECOND);
int temp = sim.flexcan.timer; // kicks us back into run mode if we stopped during debug
if( canRaw.IsValid() )
{
// process CAN message
}
and it seems to do the trick.
Thanks again,
David
Edit: for anyone else who tries this, you need to #include <sim5234.h> to access sim.flexcan.timer