In a simple project based on an STM32 microcontroller, I needed a couple of extra push buttons. So I connected each button between a pin on the STM32 and GND, configured the pins as input and activated the internal pull-up resistors.

It seemed to work well at first. Pushing the button pulls the pin to GND and triggers an interrupt. But a problem soon became apparent, which was that the setup was extremely sensitive to nearby electrostatic discharges. If I touched a piece of metal several feet away, it would cause the interrupts to trigger.

The STM32 is on a Discovery demo board which has a push button on it. That button does not have the issue, so I looked up the schematic (included below).

So there are 3 resistors, a cap and connections both to VCC and GND (and maybe the internal pull-up is used as well).

Will I need to add all that for my push buttons to be reliable? If not, which circuit do I need? What is the reason that the internal pull-up resistor is not enough for filtering out noise from nearby electrostatic discharges?

User & Wake-up Button Schematic

Update 1:

I have verified that the internal pull-up resistors are active. If I disable them, the buttons trigger randomly every few seconds. To activate the pull-ups, I use:

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

And to disable them:

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

Update 2:

I changed my push button circuit to match the schematic (with R20 and C22 removed, R22 replaced with wire) and disabled the internal pull-up. It did not change the sensitivity to electrostatic discharges.

Update 3:

Turns out that I was using the schematic for the wrong Discovery board. I've included the correct one below. This new one does have all the components fitted and the circuit is very likely to resolve the random triggering issues.

Corrected User & Wake-up Button Schematic

  • \$\begingroup\$ Would you please post the schematic for your switch circuit? It sounds like it should work (but worth checking the schematic), but maybe the pull-up isn't working. Often "N/A" means the part isn't fitted, so it might be worth checking on the board to see if the capacitor is on there. \$\endgroup\$
    – gbulmer
    Dec 16, 2015 at 21:30
  • \$\begingroup\$ I didn't post the schematic because it's simply pin - switch - gnd. No other components. \$\endgroup\$
    – Roger Dahl
    Dec 16, 2015 at 21:36
  • \$\begingroup\$ @gbulmer You're right, I examined the board and C22 is not fitted. The button on the board is working fine though. \$\endgroup\$
    – Roger Dahl
    Dec 16, 2015 at 21:43
  • \$\begingroup\$ Okay. So as I wrote in my answer, when C22 is not fitted, then R20 isn't doing anything either. R20 is a wire. So it is only 1 pull-down resistor and a switch. I think if the external resistor hasn't fixed it, you should post the circuit you believe is on your button. Maybe with the smallest program possible that has the problem. \$\endgroup\$
    – gbulmer
    Dec 17, 2015 at 14:43
  • \$\begingroup\$ Is it possible that your interrupt is being caused by some other GPIO that's not properly pulled down? You should show the config code for the interrupt. \$\endgroup\$ Dec 22, 2015 at 14:14

1 Answer 1


It sounds like the internal pull-up resistor isn't working. It's possible the code has accumulated a bug, or maybe the pull-up has got damaged.

Try an external pull-up resistor.

The Discovery board button schematic shows:

  • R22 is 0Ω, and so isn't doing anything
  • R21 is a pull-down, instead of a pull-up, so it is necessary
  • C22 capacitor as "N/A", which on ST's schematics often means the part isn't fitted.
  • R20 - if C22 isn't fitted, then it does nothing.

So, one resistor + switch is equivalent.

Noise, triggering the other, unused pins which have no defined state might be an explanation for relatively frequent and random triggering.

Looking at your picture of the project at github, I see that there is main power nearby. Noise may come from that path.

In general it is a good practice to ensure all unused pins are in a known state anyway. Pins might otherwise trigger, or even go into a 'mid-state' where one, or even both of the complementary MOSFET transistors conduct in the 'analogue' region, causing excessive heat.

You don't say what the main-loads are, but they may make ensuring pin stability, by excluding noise, even harder.

Set unused pins, which are not already wired to ground or power, to a known state using the internal pull-down or pull-up resistors. Leave them as inputs. Be careful to not do this for pins already tied to signals, ground or power.

You might start with any unused pins which trigger the same interrupt as you are using.

(You might also consider handling different pin-interrupts just to see if it is affecting more of the MCU. For example you might set an LED if any of the unused pins trigger. This isn't a fix, but is only to help an investigation or analysis.)

Try to ensure this deliberate pin-setting is highlighted/documented so that future changes to the system will not cause any pin to get into conflict with these pull-up/down settings.

Also ...
It might also be worth a test where the solenoid-board, and mains power, is completely removed from the vicinity of the Discovery board, on the small chance that noise is coming via that board. For example, there may be a ground loop.

  • \$\begingroup\$ I will give that a try and update the question with results! \$\endgroup\$
    – Roger Dahl
    Dec 16, 2015 at 21:59
  • \$\begingroup\$ @RogerDahl - please do feedback. I'll be off-line soon (for sleep) but someone will likely help a bit more. \$\endgroup\$
    – gbulmer
    Dec 16, 2015 at 22:01
  • \$\begingroup\$ I have not yet tried external pull-ups, but I verified that the internal ones are working. See the question update. \$\endgroup\$
    – Roger Dahl
    Dec 21, 2015 at 20:36
  • \$\begingroup\$ I also checked the GPIO configuration for the reliable User button (that uses the circuit you analyzed) and it's configured with GPIO_PuPd_NOPULL. In other words, the Discovery board designers went with only external components and pulling both up and down to get a reliable push button. \$\endgroup\$
    – Roger Dahl
    Dec 21, 2015 at 20:41
  • \$\begingroup\$ I've changed the circuit to match the one on the board. It didn't help. Maybe the wires are too long? My project is on GitHub here. The two external buttons can be seen in the picture there. There are now 10K resistors next to the buttons in the picture. \$\endgroup\$
    – Roger Dahl
    Dec 21, 2015 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.