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?
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;
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.
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.