Hello ChibiOS users!
I'm currently trying to read NMEA data from a GPS module (9600 baud 8N1) and have some trouble reading the data correctly. It seems that I am losing data from the serial port and I don't know why. My event listener thread looks like this:
static msg_t Thread6(void *arg)
{
(void)arg;
chRegSetThreadName("GPSdata");
// Activates the Serial driver 2, PA2(TX) and PA3(RX) are routed to USART2, 9600 8N1.
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
sdStart(&SD2, NULL);
EventListener elGPSdata;
flagsmask_t flags;
chEvtRegisterMask((EventSource *)chnGetEventSource(&SD2), &elGPSdata, EVENT_MASK(1));
while (TRUE)
{
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
chSysLock();
flags = chEvtGetAndClearFlagsI(&elGPSdata);
chSysUnlock();
if ( flags & 128 )
{
chprintf((BaseSequentialStream*)&SDU1, "%c", chnGetTimeout(&SD2, TIME_IMMEDIATE));
}
}
return 0;
}
As you can see I'm currently just reading the data from serial port 2 (USART2) one character at a time as soon as an event fires.
I'm a bit lost when it comes to the ChibiOS documentation as I have no idea how to really check what the value of flags should be when there is a character available. The value of 128 I got by observation (printing flags along with read character).
If this is because I don't understand the fundamental concepts of the events in ChibiOS then please feel free to educate me...
(BTW I couldn't register in the ChibiOS support forum, otherwise I would've asked there)