7 years, 3 months ago.

STM32L4 GPIO Pullup with InterruptIn handler for user switch

I am using a simple button switch which calls an interrupt handler when pressed. This works, however sometimes the InterruptIn handler gets called without any switch presses. I verified this with signal recording on a scope.

The schematic is easy: (see picture link)

  • Switch connected between GND and PA0
  • In parallel a (100 Ohm with 100nF) to to debounce
  • The Code:

Switch

    static InterruptIn event(USER_BUTTON);
    event.fall(this, &MyApp::ButtonPressed);
    event.mode(PullUp);

/media/uploads/Helmut64/screen_shot_2017-01-10_at_21.37.42.png

The interrupt handler itself just sets a flag that the main event loop processes the signal without being on the interrupt handler.

Any ideas what is wrong with my design? Should I use an external resistor as a pullup instead of the MCU?

I can imagine in a very agressive environment with alot of electronic noise that the pull up resistor is not strong enough to prevent glitches. However with 100nF connected to it that should absorb alot of that also.

I don't know if on your board you can easily short the pin to supply to see if it is a software issue or hardware.

posted by Erik - 11 Jan 2017

Good idea, I will add an external pullup for testing. The second interrupt comes unexpected after a few seconds. There is no power stress on the board and the scope shows no signal change. I got this with all my three own prototype boards.

posted by Helmut Tschemernjak 11 Jan 2017

I added an external 10k Pullup the problem still exits. I will investigate further.

posted by Helmut Tschemernjak 11 Jan 2017

I got the problem further investigated, when a different InterruptIn (different GPIO port a magnometer connected to this.) receives a signal,l the button handler is called as well. I will investigate into it further.

posted by Helmut Tschemernjak 12 Jan 2017

1 Answer

7 years, 3 months ago.

Hello,

On STM32 devices, interrupt with the same number (PA0, PB0, PC0, ...PH0 for example) are all linked to the same interrupt vector.
This is due to the hardware implementation of the interrupts.

If your magnetometer interrupt is connected to another Px0 GPIO pin, the behavior you are seeing is normal.
You have 2 options here:

  • Try using another Pin
  • or check the pin state inside your interrupt routine to figure out which one generated the interrupt.

Best regards,
Maxime

Accepted Answer

Dear Maxime, thank you very much for this precise answer. Now I understand it.

PS: For the mbed implementation where InterruptIn is a higher level C++ object I feel that this kind of multiplexing should be done in the HAL layer, right?

Regards Helmut

posted by Helmut Tschemernjak 13 Jan 2017