Queue Communication not working
Hi i am trying to send an array from one task to another task.. but it is not working.
here is my pseudo code:
~~~
int main(void)
{
xQueue = xQueueCreate( 2, sizeof(unsigned int) );
if ((xTaskCreate(vTask0, (const char )”Task0″, configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+2, &xHandle) != pdPASS) ||
(xTaskCreate(vTask1, (const char *)”Task1″, configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+2, &xHandle1) != pdPASS))
{
printf(“xTaskCreate() failed to create a task.n”);
}
else
{
/ Start scheduler */
printf(“Starting scheduler.n”);
vTaskStartScheduler();
}
}
~~~
~~~
void vTask0(void *pvParameters)
{
TickType_t xNextWakeTime;
unsigned int data[2];
uint16_t samplecount = 0;
const TickType_t xFrequency =10;
xNextWakeTime = xTaskGetTickCount();
while(1)
{
if (xQueueReceive(xQueue, &data,(portTickType)2))
{
printf(“received = %d n”, data[0]);
printf(“received1 = %d n”, data[1]);
}
vTaskDelayUntil(&xNextWakeTime, xFrequency);
}
}
~~~
~~~
void vTask1(void *pvParameters)
{
TickType_t xNextWakeTime;
unsigned int data[2];
const TickType_t xFrequency = 10;
xNextWakeTime = xTaskGetTickCount();
while(1)
{
data[0]=3;
data[1]=4;
xQueueSendToBack(xQueue, &data, 0);
vTaskDelayUntil(&xNextWakeTime, xFrequency);
}
}
~~~
Sorry i am new to RTOS, i want to send both data[0] and [1] to another task.. if i change the priority it will receive some random number. can anyone tell me what mistake i have done?
Queue Communication not working
xQueueCreate( 2, sizeof(unsigned int) );This creates a queue where each space can hold 1 unsigned int, so
xQueueSendToBack(xQueue, &data, 0);sends one unsigned int, not two. Plus you are sending the address of the array not the array contents. Change ‘&data’ to just ‘data’ in both the xQueueReceive and xQueueSendToBack calls.