Content originally posted in LPCWare by amrbekhit on Fri Jun 22 04:52:19 MST 2012
According to the user manual, you get a data overrun when you receive a new message and the CAN receive buffer is full. The CAN controller sets the DOS bit in the CANxGSR register and, if enabled, raises the data overrun interrupt. To clear the overrun, just set the CDO bit in the CANxCMR register.
Here are my thoughts on how to avoid overruns:
- If your CAN handling code is polled, then make sure that you are polling the CAN receiver fast enough so that it doesn't get full. Or even better, make your CAN handler interrupt driven.
- If your CAN handling code is interrupt driven, then maybe you need to look into how fast your ISR is and work on making it faster (for example, by just reading the messages into your own buffer in the interrupt and processing them in the main loop).
- Only configure your acceptance filters to accept as narrow a range of messages as possible. If you're only looking for messages with a small range of IDs, then set up your acceptance filters to accept only those IDs. That way, if your device is on a bus where lots of messages are being sent, it ignores all the messages except the ones your device is interested in, and doesn't get swamped trying to process unnecessary messages.