cancel
Showing results for 
Search instead for 
Did you mean: 

Current-limiting resistors for GPIO pins?

I'm not a hardware engineer, so apologies if this is a stupid question ...

I have two STM MCUs communicating over an open-drain line which has a pull-up resistor. Each MCU has a GPIO port connected to the line, and the ports are configured open-drain, no internal pull-up or pull-down. Software "bit bangs" the GPIO ports. Everything works.

(This is a simplified example for sake of the question. Real system has multiple open-drain lines and more than two MCUs connected to each.)

What happens if buggy or malicious software sets the ports to push-pull with one high and one low? This is a direct short from Vdd, through the high port's high-side transistor, across the line to the low port's low-side transistor, to ground. The transistors aren't power MOSFETs with milliohm RDS(on), and I can't find a spec in the datasheets, but maybe 10's of ohms (??), so still lots of current.

STM GPIO ports are typically rated for 8 mA (or 20 mA "with a relaxed V(OL)/V(OH)"). What happens next?

  1. The port is destroyed?
  2. The whole chip is destroyed?
  3. Some safety circuit shuts down the port (or the whole chip)?

Assuming #1 or #2, should I put series resistors on the ports to limit the current to a safe range? 3.3V divided by 8 mA equals 412.5 ohms. Maybe divided by two because one on each port, in series. But maybe increased because multiple ports driving the line in parallel.

This will decrease the noise immunity of the ports because voltage drops across the resistors will lower the "1" level (and raise "0"?). But the input impedance of the ports should be fairly high (again can't find a spec except for the ADC ports), maybe 10's of kOhms, so a large ratio voltage divider and thus not a problem?

What's standard practice for this? Thanks for any advice.

10 REPLIES 10
MikeDB
Lead

I think standard practice is to ignore the possibility 🙂

However if you are in a safety critical application where it is necessary, put a Schottky diode in each output line so that the output can only be pulled low, not driven high. You'll reduce the line noise margin by 0.2V to 0.3V as well so check this is ok. Alternatively you could use active diodes built with discrete MOSFETs but then you are getting really complicated/

Thanks for the insights, MikeDB!

I'm surprised this isn't taken into consideration more often. I've searched online and only ever found it discussed at https://www.rugged-circuits.com/10-ways-to-destroy-an-arduino -- they use a 30mA resettable fuse (PTC) but say it has 220 ohms resistance anyway, so it seems like higher-valued normal resistors could accomplish the same thing albeit at a higher voltage drop.

If I use a worst case scenario of 430 ohm resistors on each GPIO pin (to handle being driven directly from a low output impedance Vdd power supply, much worse than multiple GPIOs in parallel each with their own 430 resistor) that's 3.3V / 430 ohms = 7.7 mA so within safe limits for the 8 mA spec'd ports. And then taking a wild guess at the port's input impedance as being 20K when configured open-drain and set to high-Z (or as input), then one port driving another through their resistors in series gives 3.3V * 860ohm / 20860ohm = 136 mV voltage drop.

Like I said (and probably demonstrated), my EE knowledge leaves something to be desired. I've read about using Schottky diodes or active MOSFETs in the context of reversed battery power supply protection (another thing I'm worried about), but here it seems that simple resistors would do the trick.

As far as standard practice ignoring the problem, I guess if you have complete faith in your software, that the chips don't power up in a bad state or a momentary glitch isn't enough to cause failure, that noise margins are always an issue, that the additional cost and complexity of resistors/diodes/etc is significant in a high-volume product, on and on ... then I can understand the engineering decision. If the system allows users to install their own software it might change the equation (warranty claims from clueless or dishonest customers).

Mainly just thinking out loud here. Thanks again for the response and confirming I'm not totally imagining all this.

The problem with resistors is you will slug the rising and falling edges a little. Whether this is a problem depends on your frequency of operation, and indeed may reduce EMC problems if it isn't. But I'd still recommend the diodes. BAT85s are about a cent each so it won't add much to your system cost.

Reverse power supply is a different problem altogether as you need power devices. Here a power MOSFET will always give less power loss than any diode. There are loads of circuits on the Internet to choose from.

Thanks again, MikeDB!

Ah, yes. The old "parasitic capacitance unwanted RC low-pass filter" thing. (Said in best Don Adams "Get Smart" voice.) I'm learning. Slowly, but still learning.

I'm only getting around 30 Kbits/s with my bit-banging software -- mostly due to software overhead but a little from open-drain slowness with 4K7 pullups to keep power waste to a reasonable level. Still, every little bit helps, so the diodes sound good. BTW, if you really want to waste a lot of your time, check out https://github.com/thanks4opensource/tri2b-quad4me for how I could never get true multi-master I2C to work on STM and other MCUs and had to invent my own protocol instead. (I just recently found https://community.st.com/s/question/0D50X00009XkgoYSAR/stm32-i2c-multimaster-hardware-bug so maybe I'm not the only one with the problem.)

This is all just prototype R&D for me right now, so component cost isn't an issue. Thanks for the BAT85 suggestion. It's always hard for a newbie like me to sift through thousands of parts and datasheets to find the, "C'mon, just give me the standard Schottky diode (or whatever) that everyone uses".

I have been collecting reversed power supply example circuits from the net. Crossing that bridge is a still a little down the road for my project.

Have a look at this to speed your bus edges

www.analog.com%2Fmedia%2Fen%2Ftechnical-documentation%2Fdata-sheets%2F4311fa.pdf

(The link key doesn't seem to work for me so just cut and paste it in)

YES!!!

I downloaded the LTC4311 datasheet quite a while ago. Asked my embedded mentors about it but they're more software than hardware and couldn't offer any advice.

Seems like a much better solution. One active pullup per bus line instead of individual high current drivers on each port attaching to the line. I also found example circuits for doing something similar with discreet components, but the integrated chip is smaller, has more features, and might be overall cheaper when board real estate is factored in.

One of the big disadvantages of my "tri2b/quad4me" protocols -- besides being bit-banging slow and requiring 3 or 4 lines compared to I2C's two -- is that one of the lines has to be held low at bus idle (maybe 99% of the time in some applications), so the pullup strength vs rise time vs power waste tradeoff is even harder than in I2C where clock and data are high at idle. Great that the LTC4311 supports 10K pullups (typ) but swaps in the current source for fast low-to-high transitions.

Thanks for the hands-on experience recommendation for the chip.

BTW, entering links into a post seems to be one of the failings of this site. For text formatting (bold, italic, etc) you can either click the icon and start typing, or select some existing text and click the icon to change it. A different technique is required for "Code Snippet" where clicking pops up a sub-editor window.

Links are neither. You have to first type the link, then select it, and then re-enter the link in the pop-up window. No other way I've found. This allows turning arbitrary text into a link but that probably isn't a good idea in a public forum anyway (never know when someone is sending you to a spam/attack site).

S.Ma
Principal

One push pull wins over other open drains.

If there are several push pulls from different micros with some high and low levels, the output current will be higher than what it has been transistor sized and the output voltage will shift to mid voltage direction. As long as the max Vdd supply current is not exceeded for each MCU, you just get heat.

I sometime group Push pull GPIO to use then together as a 100mA power switch....

There's also the LTC1694 if that's cheaper where you are. NXP have a cheaper solution but you have to put one per MCU so it's more expensive in board area, and in cost if you have more than 4 MCUs. I really don't know why cheaper brands haven't produced active pullups like these. They save power and increase speed.

Sorry for keeping this thread going, but you guys are providing good information.

Yes, the LTC4311 datasheet has a comparison between it and the older(??)  LTC1694. The 4311 wins on most of the specs. Depending on version and package the 1694 is a little cheaper from the distributors I use.

I assume the NXP chip is a buffer/driver (bidirectional, open-drain). I have a bunch of datasheets for those, mostly from TI -- level translators and bus extenders, etc. Again, what's appealing about the LTC4311/1694 is that it's one per bus, not one per MCU on the bus. (The bus extenders aren't applicable for my use.) Even without considering cost the LTC4311 is a more "elegant" solution.

I agree: Don't know why this isn't more widespread. I've found many more buffer/drivers/etc than active pullup chips.