Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 8 months ago.
Seeed Studios CAN-BUS Shield - How is the decision made to access either of the two buffers?
wrote:
Sophie, Thanks for the code write up for the can device. You have done a really great job on it. I would like to ask you a few questions if you dont mind. In your CAN library when both buffers are full during a read of the rx data. How is the decision made to access either of the two buffers. If the incoming messages are being received quickly will buffer1 be read out even if buffer0 holds the oldest message?
Hi Rob,
Thanks for your kind words.
Buffer 0 is checked first, buffer 1 is only checked if buffer 0 is empty:
// Check if there is a message the buffers if (status & MCP_RXSTAT_RXB0) { // Msg in Buffer 0? num = 0; } else if (status & MCP_RXSTAT_RXB1) { // Msg in Buffer 1? num = 1; } else { return 0; // No messages waiting }
You could use the 'interrupts' and/or 'interruptFlags' methods to see which buffers contain messages and continue to read messages as long as the 'RxAny' flag is true (can.interrupts(SEEED_CAN::RxAny)), but I don't provide a method that allows you to specify which buffer to read.
If messages come in more quickly than your program can read them you will only read messages from buffer 0 and it is possible that a message remains unread in buffer 1 forever. That is unless there are gaps between bursts of messages and the gaps are long enough that you can (perhaps only occasionally) read from buffer 1.
I hope I've answered your questions and I'll try to help out if you have more,
Sophie