# Sending queue from a ISR??

**URL:** <https://forums.freertos.org/t/sending-queue-from-a-isr/813>\
**Category:** Kernel\
**Created:** [May 19, 2010, 6:28am UTC](https://forums.freertos.org/t/sending-queue-from-a-isr/813 "2010-05-19T06:28:08Z")\
**Posts on this page:** 4\
**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:** [May 19, 2010, 6:28am UTC](https://forums.freertos.org/t/sending-queue-from-a-isr/813/1 "2010-05-19T06:28:08Z")

</div>

**[tjohansen](https://sourceforge.net/u/tjohansen/)** wrote on [Wednesday, May 19, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2517d49d/#7963):

Hallo

I have problems sending messages from a ISR to a task.  
Im using RTOS 5.1.2, KEIL and a LPC2478 MCU.

On a external interrupt I do have to invoke a task. The task is waiting on a massage with a xQueueReceive(). The message is send from the ISR with the xQueueSendToFrontFromISR() function. But the waiting task never gets invoked. The xQueueSendToFrontFromISR() returns pdPASS. See the code used below.

I know the task in running ok. Setting a timeout in the xQueueReceive() makes the function return on the expected time.

The first time I call xQueueReceive(), after a reset, the function right away with the status pdTRUE. But a message was never send? Next time the xQueueReceive() is called the function blocks. Any idea why?

Must I use another receive function when using xQueueSendToFrontFromISR???  
Is there a better way of getting a hardware interrupt to a task?

```
void ExternalInterruptInit(void)
{
  // Creating queue
  static xQueueHandle xExternal;
  xExternal= xQueueCreate( 1, sizeof(portCHAR) );
  // Init interrupt, GPIO etc.
  ....
  ...
}
/ ISR for external interrupt - Key pressed
void KeyPressedISRHandler (void) 
{
  portBASE_TYPE status;
  // Key state
  BYTE byKeyDown = 0;
  // Token
  portBASE_TYPE xHigherPriorityTaskWoken;
  // Send event	
  byKeyDown = 1;
  status = xQueueSendToFrontFromISR( xExternal, &byKeyDown, &xHigherPriorityTaskWoken );
  // Clear interrupt
  EXTINT = EINT0;
  // Acknowledge interrupt
  VICVectAddr = 0;
  // Did sending to the queue unblock a higher priority task?
  portEXIT_SWITCHING_ISR( xHigherPriorityTaskWoken );	
}
// Task for external interrupt events
static void ExternalIntTask(void *pvParameters)
{
     // Forever
    while(TRUE)
    {
        // Wait interrupt
       if( pdTRUE == xQueueReceive( xExternal, &byDummy, portMAX_DELAY) ) // Blocks....
      {
         // Do stuff here...
        .....
        .....
      }
   }
}

```

/Thomas

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 19, 2010, 6:20pm UTC](https://forums.freertos.org/t/sending-queue-from-a-isr/813/2 "2010-05-19T18:20:39Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Wednesday, May 19, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2517d49d/#6faf):

The code is hard to read because the formatting has been lost. It is possible to post using the ‘codify text’ tags to keep the indents.

ExternalInterruptInit() is creating a queue, but xExternal is static so cannot be accessed from outside of the function. I’m not sure how you access it in the interrupt handler.

xHigherPriorityTaskWoken should be initialised to 0 before it is used.

Other than that I cannot see anything wrong.

(just noticed the closing&nbsp; so don’t know where the formatting went)

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 22, 2010, 11:09pm UTC](https://forums.freertos.org/t/sending-queue-from-a-isr/813/3 "2010-05-22T23:09:37Z")

</div>

**[rgrover1](https://sourceforge.net/u/rgrover1/)** wrote on [Saturday, May 22, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2517d49d/#e1d9):

Hi,

I’m facing a similar problem using a binary semaphore to synchronize between an ISR and a task. It was suggested to me that I should set the priority of the ISR to be \<= configMAX\_SYSCALL\_PRIORITY; but in my case that did not help. Were you able to resolve your issue? if so, could you please mention how? Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 23, 2010, 5:51am UTC](https://forums.freertos.org/t/sending-queue-from-a-isr/813/4 "2010-05-23T05:51:12Z")

</div>

**[woops\_](https://sourceforge.net/u/woops_/)** wrote on [Sunday, May 23, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/2517d49d/#0141):

Look for FromISR in Demo\CORTEX\_LPC1768\_GCC\_Rowley\webserver\emac.c for examples.
