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.
12 years, 1 month ago.
CAN transmit buffer status - how to read it properly?
In my program I need to send several CAN messages one after the other, and I know that there are only 3 transmitting buffers. I have been looking into the CAN registers, especially the global status register, but can't get it to successfully send more than 3 messages without using a wait(...) command.
I'm trying to access bit 2 of CAN2GSR using the following code, but it is not working:
CAN can(p30,p29);
unsigned int _gsr = 0;
char data8[8] = {0x10,0x27,0x28,0x3A,0x10,0x27,0x28,0x8A};
cmsg[1] = CANMessage(2,data8,8,CANData,CANStandard);
for(_stepper = 0; _stepper < 10; _stepper++)
{
while(1)
{
_gsr = LPC_CAN2->GSR;
if ((_gsr >> 2) & 0x1)
{
break;
}
}
cmsg[1].id = _stepper;
can.write(cmsg[1]);
}
This code runs, but on the other side only 3 messages are received.
Am I accessing the right register in the right way?
Any help would be appreciated.
Thanks,
Adam.
1 Answer
12 years, 1 month ago.
It looks like can.write() returns 0 if the call fails and 1 if it succeeds. Could you try something like:
CAN can(p30,p29);
char data8[8] = {0x10,0x27,0x28,0x3A,0x10,0x27,0x28,0x8A};
cmsg[1] = CANMessage(2,data8,8,CANData,CANStandard);
for(_stepper = 0; _stepper < 10; _stepper++)
{
while (0 == can.write(cmsg[1]));
}