Hello All.
I’m trying to use can.read() when using can.attach() on MbedOS6.
I’ve already known it has the bug that it doesn’t work on ISR context, so I use thread and Event Queue.
This is my code.
#include "mbed.h"
void onReceive();
void CANreceive();
CAN can(PB_5, PB_6, 500000);
Thread t(osPriorityNormal, 2000);
EventQueue queue(32 * EVENTS_EVENT_SIZE);
int main(void)
{
can.attach(onReceive, CAN::RxIrq);
t.start(callback(&queue, &EventQueue::dispatch_forever));
while (1)
{
printf("loop\n");
}
return 0;
}
void onReceive()
{
queue.call(CANreceive);
}
void CANreceive()
{
CANMessage msg;
if (can.read(msg))
{
printf("data: %s,id:%d\n", msg.data, msg.id);
}
}
However, it doesn’t work. I can see only “loop”. I suspected that CANreceive() has a problem, so I put it on main(). Then, it starts to read messages. Does can.attach() really work? Can anyone teach me solutions?
=environments=
*nucleo-stm32f767zi
*mbedOS version 6.15
*mbedCLI2 version 7.33.0
*GCC_ARM