AnsweredAssumed Answered

Can't seem to generate external interrupt

Question asked by Syed.Hasasn on Jan 19, 2016
Latest reply on Jan 20, 2016 by Clive One

On stm32f072xb (Discovery board), I am able to detect an interrupt on PA0.

Using the example provided, I configured the external interrupt as such.

   EXTI->IMR = 0x0001; /* (3) */
   EXTI->RTSR = 0x0001; /* (4) */
   EXTI->FTSR = 0x0001; /* (5) */

I enabled the interrupt

   /* Enable and set Button EXTI Interrupt to the lowest priority */
   HAL_NVIC_SetPriority((IRQn_Type)(EXTI0_1_IRQn), 0x03, 0x00);
   HAL_NVIC_EnableIRQ((IRQn_Type)(EXTI0_1_IRQn));

My IRQHandler function looks like this

void EXTI0_1_IRQHandler(void)
{
  BSP_LED_Toggle(LED_ORANGE);

  if ((EXTI->PR & 0x0001) != 0)  /* Check line 0 has triggered the IT */
  {
    EXTI->PR |= 0x0001; /* Clear the pending bit */
    BSP_LED_Toggle(LED_GREEN); /* Toggle green led on PC9 */
  }
  else /* Should never occur */
  {
     BSP_LED_Toggle(LED_ORANGE); /* Switch on orange led to report an error */
  }
}

I enabled all the peripheral clocks
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

When I connect a 5V supply to PA0, I can see the ORANGE and GREEN leds light up.

I am not clear why the example works. I don't see how the code knows that the interrupt is connected to PA0 and not PB0 or PC0. Let's ignore that for now.

*******

I am unable to detect an interrupt on a different pin of my choice.

I configured pin PB12 with Mode GPIO_MODE_IT_RISING_FALLING and GPIO_NOPULL
I modified the example to make it work for PB12

   EXTI->IMR = 0x1000;   /* I am thinking that this should point to pin 12 */
   EXTI->RTSR = 0x1000;
   EXTI->FTSR = 0x1000;

I enabled the interrupts and am using the same IRQHandler but after connecting 5V to PB12 pin, no LED lights up.

   /* Enable and set Button EXTI Interrupt to the lowest priority */
   HAL_NVIC_SetPriority((IRQn_Type)(EXTI4_15_IRQn), 0x03, 0x00);
   HAL_NVIC_EnableIRQ((IRQn_Type)(EXTI4_15_IRQn));

I then tried to use a different IRQHandler, but still no leds light up

void EXTI4_15_IRQHandler(void)
{
  BSP_LED_Toggle(LED_ORANGE);

  if ((EXTI->PR & 0x0001) != 0)  /* Check line 0 has triggered the IT */
  {
    EXTI->PR |= 0x0001; /* Clear the pending bit */
    BSP_LED_Toggle(LED_GREEN); /* Toggle green led on PC9 */
  }
  else /* Should never occur */
  {
     BSP_LED_Toggle(LED_ORANGE); /* Switch on orange led to report an error */
  }
}

Hope you can shed some light on this.

Thanks

Outcomes