cancel
Showing results for 
Search instead for 
Did you mean: 

How to know if interrupt was triggered by Falling or Rising edge?

jvilaca
Associate II
Posted on May 02, 2012 at 02:51

Hi,

If while configuring the EXTI line I use:

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling

how can I know in my interrupt if a rising of falling triggered it?

void EXTI1_IRQHandler(void)

{

  if ( RisingEdge )

  {...}

  else if ( FallingEdge )

  { ....

   }}

How can I do anything similar to this?

Thank you for your time
9 REPLIES 9
frankmeyer9
Associate II
Posted on May 02, 2012 at 16:36

I think - naturally not.

The Ref. Manual says:

Rising and falling edge triggers can be set for the same interrupt line. In this configuration, both generate a trigger condition.

This is what you do. Within the interrupt, you just know a transition happened. You could poll the current state of the line that generated it. If you are not too late, it might have been the transition to this level.

edgarmedina20
Associate II
Posted on May 23, 2014 at 23:23

I have a similar problem, I used the IF inside the ''void EXTI0_IRQHandler(void)'' but it's not work, any idea?

void EXTI0_IRQHandler(void)

{

Delay_ms(10);//button PA0 stm32f4 discovery

if(EXTI_GetITStatus(EXTI_Line0) != SET)

{

GPIO_ResetBits(GPIOD, GPIO_Pin_13);

}

else

{

GPIO_

S

etBits(GPIOD, GPIO_Pin_13);

}

/* Clear the EXTI line 0 pending bit */

EXTI_ClearITPendingBit(EXTI_Line0);

}

Posted on May 23, 2014 at 23:42

a) You are testing an Interrupt status not a pin level

b) You are causing a race condition in the NVIC by placing the interrupt clearing as the last function, which will most likely cause immediate re-entry of the IRQ handler with the IT status as false.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
edgarmedina20
Associate II
Posted on May 24, 2014 at 00:12

ok, the questions are:

a) if I'm reading the status of interrupt, mmm... then I would have to read a status pin level, for select if a rising edge or falling edge. is it correct?

b) ok, then if I push the button, will the led turn on? and then will the led turn off? something like that. all that in one push of the button.

Andrew Neil
Evangelist III
Posted on May 24, 2014 at 20:34

''I would have to read a status pin level, for select if a rising edge or falling edge. is it correct?''

Yes.

''then if I push the button''

What button? The chip doesn't know about ''buttons'' - just the levels on its input pins.

''will the led turn on?''

What LED? Again, the chip doesn't know about ''LEDs'' - it just has output pins which can be set 'high' or 'low'

edgarmedina20
Associate II
Posted on May 24, 2014 at 21:09

thank you so much.

I learned much, including the aclaration about the chip.
Posted on May 25, 2014 at 00:34

void EXTI0_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line0) != RESET)
{
/* Clear the EXTI line 0 pending bit */
EXTI_ClearITPendingBit(EXTI_Line0);
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
GPIO_ResetBits(GPIOD, GPIO_Pin_13);
else
GPIO_SetBits(GPIOD, GPIO_Pin_13);
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hwang
Associate
Posted on September 11, 2014 at 06:51

I use

void EXTI0_IRQHandler(void)

{

  if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) {

// falling

  } else {

// rising

  }}

RafaelSTM32
Associate III

you need to be sure there are not bounce in your inputs to do that