MCU push button triggered by electrostatic discharges

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?

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.

• 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. – gbulmer Dec 16 '15 at 21:30
• I didn't post the schematic because it's simply pin - switch - gnd. No other components. – Roger Dahl Dec 16 '15 at 21:36
• @gbulmer You're right, I examined the board and C22 is not fitted. The button on the board is working fine though. – Roger Dahl Dec 16 '15 at 21:43
• 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. – gbulmer Dec 17 '15 at 14:43
• 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. – Scott Seidman Dec 22 '15 at 14:14

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.

Edit:
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.

• I will give that a try and update the question with results! – Roger Dahl Dec 16 '15 at 21:59
• @RogerDahl - please do feedback. I'll be off-line soon (for sleep) but someone will likely help a bit more. – gbulmer Dec 16 '15 at 22:01
• I have not yet tried external pull-ups, but I verified that the internal ones are working. See the question update. – Roger Dahl Dec 21 '15 at 20:36
• 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. – Roger Dahl Dec 21 '15 at 20:41
• 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. – Roger Dahl Dec 21 '15 at 22:42