# Sam4s xQueueReceive / xQueueSendtoBackFromIsr uxMessagesWaiting incorrect

**URL:** <https://forums.freertos.org/t/sam4s-xqueuereceive-xqueuesendtobackfromisr-uxmessageswaiting-incorrect/6264>\
**Category:** Kernel\
**Created:** [October 11, 2016, 5:40pm UTC](https://forums.freertos.org/t/sam4s-xqueuereceive-xqueuesendtobackfromisr-uxmessageswaiting-incorrect/6264 "2016-10-11T17:40:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 11, 2016, 5:40pm UTC](https://forums.freertos.org/t/sam4s-xqueuereceive-xqueuesendtobackfromisr-uxmessageswaiting-incorrect/6264/1 "2016-10-11T17:40:37Z")

</div>

**[sasukenebe](https://sourceforge.net/u/sasukenebe/)** wrote on [Tuesday, October 11, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/d8589baa/#fe9a):

Hello,

The problem in a nutshell: My queue tells me there are no items, but the read/write pointers, as well as a debug counter tell me the buffer has 1-2 items left. Furthermore, looking at the raw uart traffic, it appears that some sort of corruption is possibly occuring with uxMessagesWaiting.

I am currently implementing a UART buffer using a freeRTOS queue. The bytes are received in an interrupt, and pushed to the back of the queue

if ( xQueueSendToBackFromISR(m\_UartQueue,(void \*)&InByte,  
&pxHigherPriorityTaskWoken) == pdTRUE )

where InByte is a uint8\_t.

They are being popped off the queue in another thread.

xQueueReceive(m\_UartQueue, (void \*)Byte, UART\_RECEIVE\_WAIT\_TIME);  
where byte is a uint8\_t pointer.

I am finding by creating my own debug counter to compare to uxMessagesWaiting that the value differs from what my debug counters say. Within the interrupt the uxMessagesWaiting is often reporting 1 less than what I would expect.

I have verified that the interrupt priority of the interrupt is appropriately set relative to configmax\_syscall\_interrupt\_priority.

Baud rate is 38400, the buffer size is 256. 39 byte packets are being received.

I am out of ideas. Any advice is appreciated.

Thanks,  
Gary

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 12, 2016, 4:47am UTC](https://forums.freertos.org/t/sam4s-xqueuereceive-xqueuesendtobackfromisr-uxmessageswaiting-incorrect/6264/2 "2016-10-12T04:47:53Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, October 12, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/d8589baa/#4ec2):

First - unless the bytes are arriving very slowing (for example, characters typed into a command console), then a queue is a very inefficient way of passing data out of an ISR. It would be better to use a DMA, or circular buffer and a direct to task communication to unblock a task when the buffer contains a complete message ([http://www.freertos.org/vTaskNotifyGiveFromISR.html](http://www.freertos.org/vTaskNotifyGiveFromISR.html))

Which chip are you using? Do you have [stack overflow detection turned](http://www.freertos.org/Stacks-and-stack-overflow-checking.html) on, and [configASSERT()](http://www.freertos.org/a00110.html#configASSERT) defined?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 12, 2016, 1:13pm UTC](https://forums.freertos.org/t/sam4s-xqueuereceive-xqueuesendtobackfromisr-uxmessageswaiting-incorrect/6264/3 "2016-10-12T13:13:09Z")

</div>

**[sasukenebe](https://sourceforge.net/u/sasukenebe/)** wrote on [Wednesday, October 12, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/d8589baa/#4ec2/11ac):

Thanks for the response. I am using the SAM4SD32C. I do have stack overflow detection turned on. I also have configassert defined. I will look into the alternative function you mentioned.
