cancel
Showing results for 
Search instead for 
Did you mean: 

Falling edge detection by hardware but without Interrupt

lowpowermcu
Associate II
Posted on January 11, 2014 at 13:49

Hi all,

I want to detect a falling edge on external pinn let's say PD13 by hardware but without using the interrupt capability (using EXTI + NVIC).

At first time I thought it is possible to do that using EXTI only by setting EXTI13 in event mode but I discovered that the interrupt pending bit is not set in event mode.

I want my code to be like:

while(1)

{

  if(fallingedge == 1)

  {

     /* Do something */

  }

  /* Application main processing */

}

Is there a trick to do that?

Thanks in advance.

3 REPLIES 3
trevor23
Associate III
Posted on January 11, 2014 at 18:17

From you code example you seem to want to detect it in software (despite the title), otherwise I don't understand what you are asking. Something like this would do it in software (for you to implement the specifics):

last_pin_state = pin_state = read_pin_state(); // initial state
while (1)
{
pin_state = read_pin_state();
if (!pin_state && last_pin_state)
{
// pin low but was high on last read so falling edge, do something

}
last_pin_state = pin_state;
// Application main processing
}

chen
Associate II
Posted on January 13, 2014 at 12:22

Hi

'' but I discovered that the interrupt pending bit is not set in event mode.''

The IRQ Pending bit will ONLY be set when the IRQ is enabled.

I do not think there is any hardware in the STM32 that does what you want/think.

As Trevor says - you pretty much polling the port bit.

If you are worried about not catching the bit change - bear in mind the processor speed.

You will be able to catch pulses down to 1us (microsecond) in SW polling.

Posted on January 13, 2014 at 12:51

> The IRQ Pending bit will ONLY be set when the IRQ is enabled.

More specifically, the bit in EXTI_PR register will be set only if respective bit in EXTI_IMR register is set. This still does not imply that the interrupt will be invoked, as it still can stay disabled in the NVIC.

> I do not think there is any hardware in the STM32 that does what you want/think.

Oh c'mon. Besides using EXTI, the timer capture inputs, for example.

JW