9 years, 5 months ago.

Using Extended can1.read returns 0

I need help as to why this wont work (code below).

When I use CANStandard it works perfectly. Using CANExtended this if statement is false. I do know the message is received and working. Meaning I create a filter and trigger an interrupt only when a specific Extended ID is received. Code functions correctly and my data for the rx ID i'm looking for is updated. When I check can1.read(canMsg) during that same cycle - it always returns false on extended but my variables are being updated with the correct data.

thanks, Rob

CAN read returns false on Extended


    CANMessage canMsg;
    if (can1.read(canMsg)) {
        printf(" ID%08x ", canMsg.id);
    }

Question relating to:

1 Answer

8 years, 8 months ago.

I am having exactly the same issue. Is there a fix for it?

EDIT:

I just figured it out.

This code should clarify it:

Extended ID:

while (!can1.write(CANMessage(msgid, reinterpret_cast<char*>(&payload), 8, CANData, CANExtended))){}

Standard ID:

while (!can1.write(CANMessage(msgid, reinterpret_cast<char*>(&payload), 8))){}Standard ID

Thanks!

Javier, I'm not sure I follow your example. Are you stepping out of your while loop when you read from the buffer?

posted by Rob Crain 27 Jul 2015