Missing bytes when using queues

Hi I have a very simple UART application, which I have ported from another RTOS to FreeRTOS. But now I got problems: very simple task: – In my UART RX interrupt, i send byte to a queue. – In a task, I read the bytes from the queue. ISR: // Read byte from UART: u8UARTData = UARTReceiveByte(UART); // Send the byte to the queue: xQueueSendToBackFromISR(xByteQueue, &u8UART_Data, &xHigherPriorityTaskWoken ); In my receiving task, I wait for a byte in the queue: xQueueReceive( xByteQueue, &u8Receivedbyte, portMAXDELAY ); Extremely simple… My problem is that I sometimes looses a byte. Not many, but maybe 1 out of 10.000. The ISR receives EVERY bytes sent to it. But when reading the queue, some bytes are missing. By mistake, I used the NON-ISR xQueueSendToBack in the first version. When using this, I never lost any bytes, but entered HardfaultHandler once in a while. Anyone knows why I loose bytes between xQueueSend and xQueueReceive? thanks in advance! br Kaare

Missing bytes when using queues

Do you check the return value of xQueueSendToBackFromISR()? If it returns pdFALSE then the queue was full. Also, do you call portYIELDFROMISR( xHigherPriorityTaskWoken ) (or portENDSWITCHINGISR( xHigherPriorityTaskWoken ) – depending on the port) at the end of your interrupt handler. If not then adding it may allow the receiving task to drain the queue sooner. Generally it is not recommended to use a queue to send every received byte unless the data is very slow (like typed characters from a keyboard, as an example). It will be more efficient to store received bytes in a RAM buffer, then use a semaphore (or task notification in V8.2.0) to unblock a task when there is a whole message that needs processing. Regards.

Missing bytes when using queues

Thanks for quick response! I send 35 characters every second, so the data amount is very small. It is not typed, but, still, i should be able to handle them My interrupt never misses a character, and my queue is never full (set to 100 bytes length). When I check the queue free size, there are never more than 5 characters in the queue. I know it is not the most efficient way to do it, but it should be OK with this amount of data. portYIELDFROMISR and portENDSWITCHINGISR are not available. Only portYIELD is. br Kaare

Missing bytes when using queues

portYIELDFROMISR and portENDSWITCHINGISR are not available. Only portYIELD is.
which port are you using?

Missing bytes when using queues

I have added this: vPortYield(); And I have received more than 70.000 bytes without any missed bytes :o) I am using V8.0.1 with Rowley / GCC on an LPC1788

Missing bytes when using queues

On that chip the expected way of doing this would be to add portENDSWITCHINGISR( xHigherPriorityTaskWoken ). Alternatively you can expand the macro yourself and add if( xHigherPriorityTaskWoken != pdFALSE ) { vPortYield(); }

Missing bytes when using queues

portENDSWITCHINGISR() is not available. Should I include something, or enable something in the config file? I can’t find anything in the reference manual. Your alternative seems to work OK until now.

Missing bytes when using queues

portENDSWITCHINGISR() is defined in portmacro.h, so should be available if you have included FreeRTOS.h at the top of the file.

Missing bytes when using queues

Ah, yes it is. I think I’m getting a bit tired :o) It also works with this, so I am happy, and can close this week with a little succes! Thanks for your help! br Kaare