0

I am working on interrupt and thinking about it lately. see if i configure a pin for example say PA1 as my interrupt. then while in Handler it is handling from PA1-PA9 Handler. meaning single handler for all the pins from PA1 to PA7. However how does the ISR or MCU get to know this interrupt is from particular pin.

    void EXTI9_5_IRQHandler(void){
    /* USER CODE END EXTI9_5_IRQn 0 */

    HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8);

    /* USER CODE BEGIN EXTI9_5_IRQn 1 */
}

I am assuming there will be some MUX mechanism, which will trigger this. But still it is not clear. How does this will work in case of Multiple interrupt ?

5
  • Not sure to understand the question, but if you have a single ISR for a whole port (PA1..9) to know which pin actually triggered the interrupt, you can read the port, mask out the pins you already know are not interrupt enabled (if your MCU has this feature) and XOR with the previous reading. Commented Jun 12 at 5:44
  • 1
    This could depend quite a lot on the MCU in question. Commented Jun 12 at 5:50
  • 1
    Which micro-controller you are uisng? Commented Jun 12 at 5:55
  • @Dark Sorrow , I am using STM32F7 Commented Jun 12 at 7:09
  • 1
    Please edit your question to add clarification and new information. Comments are not for these, this site is not a forum. Commented Jun 12 at 9:07

1 Answer 1

3

From your example, I'll assume that EXTI9_5_IRQHandler() was auto generated by STM32CubeMX. The generated code calls HAL_GPIO_EXTI_IRQHandler() with a hardcoded parameter GPIO_PIN_8 because the generator knows you configured pin 8 as an external interrupt source in the STM32CubeMX project. If you enabled multiple pins as EXTI then there would be a call to HAL_GPIO_EXTI_IRQHandler() for each EXTI pin*.

Now look at the implementation of HAL_GPIO_EXTI_IRQHandler() in stm32xxxx_hal_gpio.c. (I took this from the STM32L4 HAL but I suspect STM32F7 HAL is the same.)

void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
{
  /* EXTI line interrupt detected */
  if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u)
  {
    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
    HAL_GPIO_EXTI_Callback(GPIO_Pin);
  }
}

It calls __HAL_GPIO_EXTI_GET_IT(GPIO_Pin) to determine whether an interrupt has occurred for the specified pin. (HAL_GPIO_EXTI_Callback() is where you would put your application specific interrupt handler code.) Now look at the definition of __HAL_GPIO_EXTI_GET_IT() in stm32xxxx_hal_gpio.h.

#define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__)         (EXTI->PR1 & (__EXTI_LINE__))

It reads the EXTI->PR1 register to check whether the bit corresponding to the pin is set.

The answer to your question is to check the EXTI->PR1 register to determine which pin out of multiple are indicating that an interrupt occurred. (Double-check your HAL because different STM32 families may implement __HAL_GPIO_EXTI_GET_IT() differently.)

*Consider that there could be more than one pin indicating an interrupt by the time the interrupt service routine gets around to checking.

Sign up to request clarification or add additional context in comments.

3 Comments

I see an issue, if multiple pins are configured for the same interrupt line, and the interrupting signal is a just long enough pulse. When the ISR starts, the signal is gone already. So one can look at such a configuration as an error.
The EXTI->PR1 bit is set and latched upon the edge of the interrupt event. The EXTI->PR1 bit gets cleared in the call to __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin)
OK. From the reference manual it looked as if these bits are just for the (accumulated) interrupt line, not the individual pin. Of course I know that registers store the triggered interrupt flag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.