Can write stops after 3 messages

Ties_van_Essen
Thu, 23 Nov 2023 09:40:07 +0000
Mbed OS

Hi All,

I am trying to write continuous can bus messages onto a bus (the same message to start out with and get familiar). But with my current code there are only 3 messages being sent before it stops (the if statement isn’t met, the code keeps running as it starts printing “failed to send msg”). Hopefully this is just a simple fix by me misunderstanding re-printing can bus messages. This is my code:

int main()
{
    while (1)
    {
            CANMessage msg;
    msg.id = 1333;
    msg.len = 8;
    msg.data[0]=0x1F;
    msg.data[1]=0x1F;
    msg.data[2]=0x1F;
    msg.data[3]=0x1F;
    msg.data[4]=0x1F;
    msg.data[5]=0x1F;
    msg.data[6]=0x1F;
    msg.data[7]=0x1F;

        if (can.write(msg)) {
            printf("Send: %d %d %d %d %d %d %d %d\n", msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]);
            // ThisThread::sleep_for(500ms);

        }
        else{
            printf("failed to send msg\n");
        }
    }

}

Hopefully any of you can help.

Kind regards,
Ties

4 posts - 2 participants