xQueueReceive does not receive correct Data

Hi, I am using      xQueueSendToBackFromISR(xButtonQueue, &button, &xHigherPriorityTaskWoken); to send a Button key Parameter to a task waiting with: while( xQueueReceive( xButtonQueue, &pcMessage, portMAX_DELAY ) != pdPASS ); I am seeing the same data being retreived from the queue even though the data being sent to it is changing in the ISR. I have to press the next button 3 times for it to start to receive the correct info in the queue. Here is my output terminal window: Button Press     (Actually pressed Mag Key)
Call Handle Magnification Key  (Correct) Button Press    (Pressed Camera Key)
Call Handle Magnification Key   (Wrong) Button Press   (Pressed Camera Key) 
Call Handle Magnification Key  (wrong) Button Press   (Pressed Camera Key)
Call Handle Camera Key  (Correct) Button Press    (Pressed Mag key)
Call Handle Camera Key  (wrong) Button Press   (Pressed Mag Key)
Call Handle Camera Key   (wrong) Button Press   (Pressed Mag Key)
Call Handle Magnification Key  (Correct) I double checked to make sure that the IRQ has the proper button key value and that this value is sent to the queue using fromISR. How does the Queue empty itself after I receive the previous data?  Do I have to flush the Queue? Perhaps I am missing a sequence. Thanks in advance,
Ozmit

xQueueReceive does not receive correct Data

Hello Ozmit, Have you verified that you are not received more than one interrupt from the _same_ button key. This could be the case if proper denouncing logic is not present for the key. - Kau

xQueueReceive does not receive correct Data

Ksashtekar has already pointed out the most obvious first thing to check.  You can easily verify this by having a simple counter in the interrupt to see how many times it has executed compared to how many times you press the key. You might also want to ensure that the queue was created with the correct item size.  For example, if you have created the queue to hold a 32-bit variable, but “button” (the variable being posted to the queue) is only 8-bits, then the values read out from the queue will be junk (because three bytes after the button variable will also be copied into the queue). Regards.

xQueueReceive does not receive correct Data

Richard, The size is:
/* Create the queue used to pass button info to vButtonTask. */
xButtonQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( char * ) ); where: #define mainQUEUE_SIZE ( 3 ) I think this is it because debouncing is being handled in this sample project by a double semaphore: /* For debouncing, wait a while then clear the semaphore. */
vTaskDelay( mainSHORT_DELAY );
xSemaphoreTake( xButtonSemaphore, mainNO_DELAY ); /* Wait for an interrupt. */
xSemaphoreTake( xButtonSemaphore, portMAX_DELAY ); Will test with queue size of 1. Thanks!
Ozmit

xQueueReceive does not receive correct Data

The size is:
/* Create the queue used to pass button info to vButtonTask. */
xButtonQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( char * ) );
Ok – what are the data types of your button and pcMessage variables used in your original code snippet?
I think this is it because debouncing is being handled in this sample project by a double semaphore:
/* For debouncing, wait a while then clear the semaphore. */
vTaskDelay( mainSHORT_DELAY );
xSemaphoreTake( xButtonSemaphore, mainNO_DELAY ); /* Wait for an interrupt. */
xSemaphoreTake( xButtonSemaphore, portMAX_DELAY ); I’m not sure what that code is doing.  Is it in the task?  If you are getting multiple interrupts because of bounces, and each interrupt places something into the queue, waiting on a semaphore (which is presumably given from the same interrupt?) is not going to prevent items being posted to the queue in the interrupt. Regards.

xQueueReceive does not receive correct Data

Hi Ozmit,
change sizeof( char * ) to sizeof( char ) in xQueueCreate. Now you get the size of a pointer to a char (4 bytes), not a size of a char itself (1 byte). (if that were what you wanted) br,
Lars

xQueueReceive does not receive correct Data

Richard, That fixed my problem.. I changed : #define mainQUEUE_SIZE ( 3 ) to #define buttonQUEUE_SIZE ( 1 ) And now Button presses are behaving as expected. Thanks!
Ozmit