Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

xQueueReceive does not receive correct Data

Posted by Ozzy Smith on December 5, 2012
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


RE: xQueueReceive does not receive correct Data

Posted by Kaustubh on December 5, 2012
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

RE: xQueueReceive does not receive correct Data

Posted by Richard on December 5, 2012
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.

RE: xQueueReceive does not receive correct Data

Posted by Ozzy Smith on December 5, 2012
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

RE: xQueueReceive does not receive correct Data

Posted by Richard on December 5, 2012
“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.

RE: xQueueReceive does not receive correct Data

Posted by Lars von Wachenfeldt on December 5, 2012
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


RE: xQueueReceive does not receive correct Data

Posted by Ozzy Smith on December 5, 2012
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


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS