Skip to main content
Arman Ilmak
Senior
February 19, 2018
Question

Ecternal interupt occurs 2 times?

  • February 19, 2018
  • 12 replies
  • 1752 views
Posted on February 19, 2018 at 22:58

Hello guys.

I've started working with stm32f217zg series and i have a problem with external interupt.

I have programmed the mcu and after i push the button the interupt occurs two times instead of one.

I use cube mx to generate the code.

I attached the code so you can see it.

    This topic has been closed for replies.

    12 replies

    AvaTar
    Senior III
    February 20, 2018
    Posted on February 20, 2018 at 09:26

    Being no friend of Cube, I don't browse through megabytes of autogenerated code.

    But I suspect you configured an EXTI interrupt on both transitions (HL and LH), thus two interrupts.

    For push buttons, I would use only the interrupt applying to the release event.

    Arman Ilmak
    Senior
    February 20, 2018
    Posted on February 20, 2018 at 21:51

    AvaTar wrote:

    But I suspect you configured an EXTI interrupt on both transitions (HL and LH), thus two interrupts.

    For push buttons, I would use only the interrupt applying to the release event.

    I've set it for just falling edge.

    Andrew Neil
    Super User
    February 20, 2018
    Posted on February 20, 2018 at 10:19

    You do realise that mechanical switch contacts bounce - don't you?

    See:

    https://community.st.com/0D50X00009XkXPNSA3

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Arman Ilmak
    Senior
    February 20, 2018
    Posted on February 20, 2018 at 21:55

    Andrew Neil wrote:

    You do realise that mechanical switch contacts bounce - don't you?

    See:

    https://community.st.com/0D50X00009XkXPNSA3

    I've put a 500 ms delay after the interrupt occurs.This delay should fix this matter,doesn't it?

    henry.dick
    Associate II
    February 20, 2018
    Posted on February 20, 2018 at 22:53

    Does it fix the problem?

    Andrei Chichak
    Lead
    February 21, 2018
    Posted on February 21, 2018 at 01:24

    https://www.embedded.fm/blog/2016/11/10/discovery-debouncing

     

    Article for you

    Andrei

    Arman Ilmak
    Senior
    February 21, 2018
    Posted on February 21, 2018 at 12:29

    Thank you guys.Yeah the problem was the bounce of the push button i used.

    I put that delay after all the codes in the EXTI interrupt routine so when i used push button the bounce make the interrupt happens again.I just needed to put a 30 ms before clearing the exti flag clears.

    henry.dick
    Associate II
    February 21, 2018
    Posted on February 21, 2018 at 12:45

    There are much better ways to debouncing than to put a big fat delay routine in the isr, of all places.

    AvaTar
    Senior III
    February 21, 2018
    Posted on February 21, 2018 at 13:36

    Agree, delays inside of interrupt handlers, especially of this magnitude, tend to be deadly for serious applications.

    There are other, better ways to prevent EXTI from generating switch transition events.