Hello,
I would like to ask question about CAN bus.
My main software loop is 100ms (RTI interrupt). Every loop I am checking if there are any messages in box messages available.
while(1) { if (nextIterationFlag == true) { /* clear flag */ nextIterationFlag = false; newData = canGetData(canREG1, CAN_MESSAGE_BOX_1, canRxData_ptr); if (newData == TRUE) { /* there is new data, so decode data */ } } }
Everything works well unless messages are transmitted more often than 10Hz. If there is more messages on the bus (e.g. when transmitter transmit them every 20ms) I cannot read messages from this message box. I suppose buffer for current message box is overwritten or some how inaccessible. How can I fix it?
I suppose that I can use CAN interrupt and read the data immediately after the interruption. But is it the only way?
Is there any way to get last data from message box and do not care about previous data? I mean if data is overwritten, message box should accept new data without any errors and function canGetData() should works.
Thank you.