# xQueueReceive Blocks application on LPC2129

**URL:** <https://forums.freertos.org/t/xqueuereceive-blocks-application-on-lpc2129/726>\
**Category:** Kernel\
**Created:** [March 22, 2013, 2:08pm UTC](https://forums.freertos.org/t/xqueuereceive-blocks-application-on-lpc2129/726 "2013-03-22T14:08:45Z")\
**Posts on this page:** 5\
**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:** [March 22, 2013, 2:08pm UTC](https://forums.freertos.org/t/xqueuereceive-blocks-application-on-lpc2129/726/1 "2013-03-22T14:08:45Z")

</div>

**[dcgirish16](https://sourceforge.net/u/dcgirish16/)** wrote on [Friday, March 22, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/1ffa8144/#1db1):

i have an application where, a message is posted from an ISR using call “xQueueSendToBackFromISR” which is done successfully.&nbsp; but a task which is waiting on queue to receive the message posted from ISR, blocks the whole application once it receives the message posted from ISR and the application hangs.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 22, 2013, 2:30pm UTC](https://forums.freertos.org/t/xqueuereceive-blocks-application-on-lpc2129/726/2 "2013-03-22T14:30:55Z")

</div>

**[dcgirish16](https://sourceforge.net/u/dcgirish16/)** wrote on [Friday, March 22, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/1ffa8144/#0630):

following code shows the creation of task & queue, posting and receiving of queue.

Task waiting on queue: serialRecvTask  
Isr Posting message :&nbsp; UART0\_Recv\_Interrupt\_Handler  
Message Queue created: serialRecvQueue

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
typedef struct \_serialRecvQueue  
{  
unsigned char cmd;

}SERIAL\_RECV\_QUEUE;  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

/////##### Task ‘serialRecvTask’ and queue ‘serialRecvQueue’ are created here in main function.

################################&nbsp; Main function creating Task and queue #########################################  
int main(void)  
{  
&nbsp;&nbsp;&nbsp; APP\_SHARED\_DATA appSharedData;  
&nbsp;&nbsp;&nbsp; int i;

&nbsp;&nbsp;&nbsp; initTarget();

&nbsp;&nbsp;&nbsp; //xTaskCreate(ledTask, “NAME”, configMINIMAL\_STACK\_SIZE, (void \*)&appSharedData, mainLED\_TASK\_PRIORITY + 5, ( xTaskHandle \* ) NULL );  
//&nbsp; xTaskCreate(serialOutTask, “NAME”, configMINIMAL\_STACK\_SIZE, (void \*)&appSharedData, mainCHECK\_TASK\_PRIORITY, ( xTaskHandle \* ) NULL );  
//&nbsp; xTaskCreate(keyTask, “NAME”, configMINIMAL\_STACK\_SIZE, NULL, mainCHECK\_TASK\_PRIORITY + 7, ( xTaskHandle \* ) NULL );  
//&nbsp; xTaskCreate(adcTask, “NAME”, configMINIMAL\_STACK\_SIZE, (void \*)&appSharedData, mainCHECK\_TASK\_PRIORITY + 6, ( xTaskHandle \* ) NULL );  
//&nbsp; xTaskCreate(dummyTask, “NAME”, configMINIMAL\_STACK\_SIZE, (void \*)&appSharedData, mainCHECK\_TASK\_PRIORITY + 4, ( xTaskHandle \* ) NULL );  
&nbsp;&nbsp;&nbsp; xTaskCreate(serialRecvTask, “NAME”, configMINIMAL\_STACK\_SIZE, (void \*)&appSharedData, mainCHECK\_TASK\_PRIORITY + 8, ( xTaskHandle \* ) NULL );  
//&nbsp; xTaskCreate(canMsgProcessTask, “NAME”, configMINIMAL\_STACK\_SIZE, (void \*)&appSharedData, mainCHECK\_TASK\_PRIORITY + 9, ( xTaskHandle \* )&nbsp;&nbsp;&nbsp;&nbsp; NULL );  
//&nbsp; xTaskCreate(canControlTask, “NAME”, configMINIMAL\_STACK\_SIZE, (void \*)&appSharedData, mainCHECK\_TASK\_PRIORITY + 8, ( xTaskHandle \* ) NULL );

&nbsp; /\* Create Queue for Serial Input \*/  
&nbsp;&nbsp;&nbsp; serialRecvQueue = xQueueCreate(5, sizeof(SERIAL\_RECV\_QUEUE));  
&nbsp;&nbsp;&nbsp; if(serialRecvQueue == 0)  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putstr(“Could NOT create serialRecvQueue”);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putchar(’\n’);  
&nbsp;&nbsp;&nbsp; }  
}

//#####################################################################################

################&nbsp;&nbsp; Task waiting on Queue #####################################3

void serialRecvTask(void\* pvParameters)  
{  
SERIAL\_RECV\_QUEUE recvSerialCmd;  
unsigned char levelSensorVal = 0;  
unsigned char resistanceVal = 0;  
pvParameters = pvParameters;

while(1)  
{  
printf(“Serial Recv Task: Waiting on Queue\n”);  
//if(xQueueReceive(serialRecvQueue, (void \*)&recvSerialCmd, portMAX\_DELAY))//If can be taken off as task gets blocked  
if(xQueueReceive(serialRecvQueue, (void \*)&recvSerialCmd, 1000))//If can be taken off as task gets blocked  
{  
printf(“Serial Recv Task: Received Msg=%c\n”, recvSerialCmd.cmd);  
#if 0  
switch(recvSerialCmd.cmd)  
{  
case 0x31:{  
&nbsp; printf("%c%c", recvSerialCmd.cmd, levelSensorVal++);  
&nbsp; levelSensorVal = levelSensorVal % 253;  
&nbsp; break;  
&nbsp; }  
case 0x32:{  
&nbsp; printf("%c%c", recvSerialCmd.cmd, resistanceVal++);  
&nbsp; resistanceVal = resistanceVal % 253;  
&nbsp; break;  
&nbsp; }  
default:{  
printf("%c%c", recvSerialCmd.cmd, 0xFF);  
break;  
}  
&nbsp;  
}  
#endif  
}

&nbsp; vTaskDelay(10); // May not be required  
}

}

####################################################################################

//################ Interrupt posting Queue Message ##########################/  
void UART0\_Recv\_Interrupt\_Handler(void){

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned char recvdChar;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SERIAL\_RECV\_QUEUE recvdMsg;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portBASE\_TYPE xHigherPriorityTaskWoken;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xHigherPriorityTaskWoken = pdFALSE;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recvdChar = U0RBR;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recvdChar = ‘\0’;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recvdMsg.cmd = recvdChar;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(serialRecvQueue != 0)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //if(xQueueSendToBackFromISR(serialRecvQueue, (void \*)&recvdMsg, &xHigherPriorityTaskWoken) != pdPASS)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(xQueueSendToBackFromISR(serialRecvQueue, (void \*)&recvdMsg, pdFALSE) != pdPASS)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putstr(“UART0 ISR: Failed to send Message”);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putchar(’\n’);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putstr(“UART0 ISR: Message Queued Successfully”);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putchar(’\n’);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putstr(“UART0 ISR: Not Valid Queue”);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putchar(’\n’);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(“Received String : %s\n”, recvdChar);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VICVectAddr = 0; /\* Acknowledge Interrupt \*/  
}  
################################################################################33

---

<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:** [March 22, 2013, 2:44pm UTC](https://forums.freertos.org/t/xqueuereceive-blocks-application-on-lpc2129/726/3 "2013-03-22T14:44:17Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, March 22, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/1ffa8144/#324f):

Which version of FreeRTOS are you using (it makes a difference as to whether you can pass false as the last parameter to the xQueueSendFromISR() function).

What happens if you take all the calls to printf() out?

Are putstr() and putchar() safe to call from an interrupt?

Is the interrupt being cleared in the UART (it might happen automatically, I can see you clear it in the VIC).

Can you post the wrapper code from which UART0\_Recv\_Interrupt\_Handler() is called.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 22, 2013, 3:03pm UTC](https://forums.freertos.org/t/xqueuereceive-blocks-application-on-lpc2129/726/4 "2013-03-22T15:03:35Z")

</div>

**[dcgirish16](https://sourceforge.net/u/dcgirish16/)** wrote on [Friday, March 22, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/1ffa8144/#51f5):

I am using version 7.0,&nbsp; messaging is working fine with other things for example, posting & receiving messages between tasks, infact even message posted from an FIQ ISR&nbsp; is being received clearly with other task which i am using to receive switch input and a task…

removing prints/putstr/putchar… did not make any difference(this is just a function),&nbsp; commenting out other queues created for different purpose just made “xQueueReceive(serialRecvQueue, (void \*)&recvSerialCmd, portMAX\_DELAY);”&nbsp; to respond occationaly but still freezing the application.

with LPC2129, “VICVectAddr = 0; /\* Acknowledge Interrupt \*/”&nbsp; is normally what is done to clear the interrupt.&nbsp; took an example from Keil.

“UART0\_Recv\_Interrupt\_Handler()” is registered while initializing the serial port as below.

/##########################  
void init\_serial (void)&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* Initialize Serial Interface&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \*/

&nbsp; volatile char dummy;

&nbsp; PINSEL0 = 0x00050005;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* Enable RxD1 and TxD1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \*/

/\*UART1 \*/  
&nbsp; U1LCR = 0x83;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* 8 bits, no Parity, 1 Stop bit&nbsp;&nbsp;&nbsp;&nbsp; \*/  
//&nbsp; U1DLL = 97;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* 9600 Baud Rate @ 15MHz VPB Clock&nbsp; \*/  
&nbsp; U1DLL = 0XC2;  
&nbsp; U1LCR = 0x03;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* DLAB = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \*/

&nbsp; //RX Interrupt Enable  
/\*--------------------------INTERRUPT HANDLER---------------\*/  
&nbsp; VICVectAddr5 = (unsigned long)UART0\_Recv\_Interrupt\_Handler;  
/\*---------------------------------------------------------------\*/  
&nbsp; VICVectCntl5 = 0x20 | 6; /\* UART0 Interrupt \*/  
&nbsp; VICIntEnable = 1 \<\< 6;&nbsp;&nbsp; /\* Enable UART1 Interrupt \*/

/\* UART0 \*/  
&nbsp; U0LCR = 0x83;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* 8 bits, no Parity, 1 Stop bit&nbsp;&nbsp;&nbsp;&nbsp; \*/  
//&nbsp; U1DLL = 97;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* 9600 Baud Rate @ 15MHz VPB Clock&nbsp; \*/  
&nbsp; U0DLL = 0XC2;  
&nbsp; U0LCR = 0x03;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* DLAB = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \*/

/\*------------------------- I am doubting this statement but not sure if this is the cause---------\*/

&nbsp;&nbsp; dummy = U0IIR;&nbsp;&nbsp; /\* Read IrqID - Required to Get Interrupts Started \*/  
/\*------------------------------------------------------------------------------------------\*/  
&nbsp;&nbsp; U0IER = 0x01;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* Enable UART1 RX and THRE Interrupts \*/  
}

############################/

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 22, 2013, 6:33pm UTC](https://forums.freertos.org/t/xqueuereceive-blocks-application-on-lpc2129/726/5 "2013-03-22T18:33:29Z")

</div>

**[dcgirish16](https://sourceforge.net/u/dcgirish16/)** wrote on [Friday, March 22, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/1ffa8144/#5c00):

looks like problem with uart configuration and interrupt handler… looking into it
