2
votes

I have a digital input GPIO line where I need an interrupt whenever its input changes. In STM32CubeMX I set this pin to an EXTI line and set the interrupt to trigger on both rising and falling edges.

When, in response to either a rising or falling edge the function HAL_GPIO_EXTI_Callback() is called, is there a way to know whether it was a rising or falling edge that triggered the interrupt? Or will it be necessary to call HAL_GPIO_ReadPin() to infer this?

The prototype of the callback is:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
3

3 Answers

6
votes

You will have to call HAL_GPIO_ReadPin().

When you select Interrupt on both rising and falling edge, STM32CubeMX actually sets the corresponding bits in the Rising trigger selection register (EXTI_RTSRx) and in the Falling trigger selection register (EXTI_FTSRx).

When an interrupt occurs, only one bit is set in the Pending register (EXTI_PRx) for that interrupt line and therefore you don't know if it was a rising or a falling edge.

0
votes

Yeah, I did it like you said. But the code can not distinguish between rising and falling edges. Here is the code:

   void HAL_GPIO_EXTI_Callback (uint16_t GPIO_Pin)
    {
      if (GPIO_PIN_SET! = HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_11))
      {// THIS CONNECTION IS ADDED. THEN THE SET TUSUNA CAN BE PERFORMED UP AND UP DOWN PRIOR.
        if (GPIO_Pin == GPIO_PIN_4) // PA4 rising edge or falling edge cut.
        {// Let's say the LCD is inverted. DOWN.
          // if ((GPIO_PIN_RESET == HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_5)) && (GPIO_PIN_SET == HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_4)))
          // {

          // A UCU
          if ((GPIO_PIN_RESET == HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_5)) && (GPIO_PIN_SET == HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_4))) // While rising edge on PA4.
          {
            //tsHandle.tsButtonVariables.bButton_A_DusenKenar_B_Logic0 = 0;
            tsHandle.tsButtonVariables.bButton_A_YukselenKenar_B_Logic0 = 1;
            //tsHandle.tsButtonVariables.bButton_B_DusenKenar_A_Logic0 = 0;
            //tsHandle.tsButtonVariables.bButton_B_UpdateKenar_A_Logic0 = 0;
          }
          else if ((GPIO_PIN_RESET == HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_5)) && (GPIO_PIN_RESET == HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_4))) // PA4 when the falling edge is occurring.
          {
            tsHandle.tsButtonVariables.bButton_A_DusenKenar_B_Logic0 = 1;
            //tsHandle.tsButtonVariables.bButton_A_YukselenKenar_B_Logic0 = 0;
            //tsHandle.tsButtonVariables.bButton_B_DusenKenar_A_Logic0 = 0;
            //tsHandle.tsButtonVariables.bButton_B_UpdateKenar_A_Logic0 = 0;
          }
          else
          {

          }
     }
0
votes

Insert __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); in the HAL_GPIO_EXTI_Callback function.