cancel
Showing results for 
Search instead for 
Did you mean: 

Function to check EXT_0 or any EXT_X interrupt status?

Vu.Andy
Associate III
Posted on January 04, 2017 at 02:11

Does HAL library has any function that can check for the interrupt status on any given EXT line?  For example,

I have configured:

    HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);

    HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);

Now when an interrupt occurs, is there a HAL function to check whether EXTI0 or EXTI1 had caused the interrupt?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 04, 2017 at 04:00

If you are using the Interrupt callback function defined in the HAL reference manual, it passes the interrupt pin number to you in your callback function.  You just need to compare the passed parameter to determine the source of the interrupt.

View solution in original post

3 REPLIES 3
Posted on January 04, 2017 at 04:00

If you are using the Interrupt callback function defined in the HAL reference manual, it passes the interrupt pin number to you in your callback function.  You just need to compare the passed parameter to determine the source of the interrupt.

Posted on January 04, 2017 at 16:40

OK, I see. 

Here is the sequence I think should do what I want:

void EXTI0_1_IRQHandler(void)

{

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);

  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);

}

void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)

{

  /* EXTI line interrupt detected */

  if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)

  {

    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);

    HAL_GPIO_EXTI_Callback(GPIO_Pin);

  }

}

The user then implements the call back function:

HAL_GPIO_EXTI_Callback(GPIO_Pin)

{

    if (GPIO_Pin == GPIO_PIN_0) { ....}

    if (GPIO_Pin == GPIO_PIN_1) { ....}

}

Posted on January 04, 2017 at 17:09

HAL provides a callback that you can use:

0690X00000605uYQAQ.png

This routine is called when the HAL interrupt handler is called (the code you are looking at in the *_it.c file).  If you write your own routine like this:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){

   if(GPIO_Pin == GPIO_PIN_0){

      do stuff;

     }

   else if (GPIO_Pin == GPIO_PIN_1){

      do other stuff;

    }

it will do what you want.  This is in the GPIO section of the HAL reference manual.  I took the one from the F0 family but they are pretty much all the same.

You do not need to touch the interrupt code in the *_it.c file.  It will do what you want.