Preventing backfeeding through IO in UART <> MCU - Page 1
Forum section: electronics / projects

author: Buriedcode
author_rank: Super Contributor
timestamp: May 02, 2025, 11:52:29 pm
content: A lot of debugging I do involves hooking a USB-UART bridge to an MCU to either spit out debug data, or allow a crude terminal interface to test modules.A consequence of this is, for certain applications - such as when a micro can control its own power for auto power-off, the UART connection can backfeed to keep the MCU powered. This can also happen in reverse, such as if the USB-UART bridge crashes, simply unplugging the USB side can leave it powered by backfeeding through the Tx/Rx pins.I know its a classic problem, but after all these years I haven't bothered to look at a neat solution, specifically for debugging - this is a one-off thing that I can use rather than a design to be implented in multiple products. I initially thought it would be easy - diodes and pull ups? that can still allow a pullup resistor to power the Tx of the other end. Logic with "power-down" protection - such as the VHC and AHC, sounds good, but I started to get caught up with trying to keep inputs high by default.So, the situation is.. standard UART, two way, where either end can be powered down, and that shouldn't send any leakage to the other end, but leave its inputs high (that is, high, if that side is powered). Is this as simple as, pullups on inputs and outputs (powered by different ends) or am I missing something? It seems the more I tihnk about this, the more confusing it can get.I came up with a 4 transistor circuit that looks ok, but its not exactly high speed. Probably fine for up to 19200, but there has to be a more elegant way. Whats everyones go-to solution?Enit: I just realised a brute-force but rather simple solution... a DPST relay. That can be powered by either side, but requires that both sides be active to fire the relay, so it opens if either side goes down. Its simple, fairly cheap (I'm probably going to make a few but just for convenience) but it can be power hungry. Perhaps a latching relay..

author: moffy
author_rank: Super Contributor
timestamp: May 03, 2025, 12:03:03 am
content: Why not just use logic isolators powered from their respective sides?

author: incf
author_rank: Frequent Contributor
timestamp: May 03, 2025, 12:16:52 am
content: high speed opto-isolators tend to be more convenient than relays

author: dobsonr741
author_rank: Frequent Contributor
timestamp: May 03, 2025, 12:26:17 am
content: 74LVC1T45 Frequently used on debug probes.

author: ledtester
author_rank: Super Contributor
timestamp: May 03, 2025, 01:45:32 am
content: Quote from: Buriedcode on May 02, 2025, 11:52:29 pmWould just a PNP/P-MOS transistor with its collector/source pulled up work?Or even just a pulled-up diode? Maybe need to use a one with a low Vf.Wouldn't be high-speed, of course.I'm not seriously proposing these solutions but would be interested in feedback.

author: Ian.M
author_rank: Super Contributor
timestamp: May 03, 2025, 03:13:00 am
content: Quote from: dobsonr741 on May 03, 2025, 12:26:17 am+a pullup to set the idle state when one side isn't powered. You also get level translation for free.

author: AndersJ
author_rank: Frequent Contributor
timestamp: May 03, 2025, 03:24:47 am
content: Would a series resistor on the Tx linecause enough voltage drop to not power the device?

author: Buriedcode
author_rank: Super Contributor
timestamp: May 03, 2025, 06:15:13 pm
content: Quote from: incf on May 03, 2025, 12:16:52 amWell, damn for some reason I just completely forgot about optos... works for MIDI and I doubt I'll be doing anything above 31250. With actual galvanic isolation being a nice bonus.Quote from: dobsonr741 on May 03, 2025, 12:26:17 amAnd we have a winner. I knew there was a specific device, I have a few level translators, but its theQuoteI wanted. And looks like datarate won't be an issue..Quote from: Ian.M on May 03, 2025, 03:13:00 amYup, both sides will have weakish pullups, these tend to be already in system. I was trying to avoid having anything "extra" on the USB-UART side, or the target board side - so a small circuit inserted between the two, with VCC, Tx, Rx, and GND either side, so I can use any USB device, and any target board. And yes, the level translation is a very nice bonus - especially as I'm using 1.8V more and more, and many "cheap" USB dongles are really 3.3V only.Quote from: AndersJ on May 03, 2025, 03:24:47 amI thought about this. But with certyain designs, for increased battery life there can be really very little load on the power line, so even a few 10k (too high for series resistors for any decent baud) was enough to hold the VDD up to prevent brown out reset. A cheapish way I've used for up-translation is the classic reverse schottky, with a pullup on the Rx side - but its that pull-up (has to be low enough to get decent edges, but high enough to prevent too much leakage) that can still go through the diode, and into the IO's protection diodes.Thanks folks, I must have been having a brainfart - still can't believe I didn't think of the 40 year old MIDI standard..

author: Ian.M
author_rank: Super Contributor
timestamp: May 03, 2025, 08:21:19 pm
content: You should probably also add a 270R resistor on the bridge board in series with target RX-in (bridge TX-out) as the 74LVC1T45 has quite a lot of output drive (+/-24mA), and if its mis-connected or the target is misconfigured, its a good idea to limit the current if there is a level conflict. A similar resistor in series with target TX-out may also be worth fitting - it should never pass significant current unless the target is miswired, but if so, may well prevent blowing a 74LVC1T45. If you want 'belt and braces' protection, put a reversed biassed Schottky across Vcc and Gnd on the target side of the 74LVC1T45, and a 50mA polyfuse in series with target Vcc, which gives some survivability if Vcc and Gnd get swapped!

author: Buriedcode
author_rank: Super Contributor
timestamp: May 03, 2025, 11:03:23 pm
content: I generally use 100-220R in series with data lines in prototypes just for that reason - modern MCU's can have significant drive current, and as you mentioned modern logic families can too.Since I'm prone to brainstorming I wrote down several ways to do this - before hearing of the 74LVC1T45 - including using VHC logic, either single gates, only powered from the device connected to its output (no input diode to VDD on those), or using 74VHC125 with OR Schottky diodes so the buffer is always powered if either (or both) but it is only enabled if both supplies are present. That means, input signals can't power it, and output pullups can't backfeed into the bufferes power, because it is always powered. This gets tricky when dealing with two seperate supplies, which is why none of these solutions (apart from the afforementioned dual suppy buffer) works for every application. I might post a few example circuits some time, each with their own pros and cons, but might be useful to someone if they just want something quick with generic parts.One thing thats not particularly important, but is one of the reasons I started to get so confused is - if an input to this has a pullup, then if that pullup is connected to the input side devices power, that works, but if that side isn't powered, there is no input pullup, and the input floats - so that output side is unknown, or more likely, sitting at 0, because the input pullup is essentially at GND. If that pullup is connected to the output side, then that can obviously feed back to the input side, when the output side is powered. (Note: this is not an issue with the 74LVC1T45, since the outputs are tristated unless both are active).

author: David Hess
author_rank: Super Contributor
timestamp: May 04, 2025, 01:11:05 am
content: Quote from: Buriedcode on May 02, 2025, 11:52:29 pmI checked some old designs for battery backed up SRAM which face the same problem. They use single transistors with pull-ups as inverters between the power domains.I have also seen high voltage open collector/drain gates used for this because they lack a protection diode on the high side. 3.3 volt logic which can accept 5 volt inputs should also work.

author: Buriedcode
author_rank: Super Contributor
timestamp: May 04, 2025, 03:05:48 am
content: Quote from: David Hess on May 04, 2025, 01:11:05 amYeah, open collectors with transistors/logic were my first thought because it kills two birds with one stone - allows the pullup to be on the receiving side (setting the level), but not allowing that current to flow back through the transistor, and int he case of a discrete NPN - also requires a ground referenced voltage to pull it low, so if the transmitting side isn't powered at all, nothing happens and the output defaults to high. You can make open collectors with tristate buffers, but these often still have that dreaded output diode (AC, AHC, VHC, HC and their T equivalents). A half measure would be an NPN driven by a logic buffer, using a second transistor could work, but two in series might slow things up too much for hgiher speed comms. (I'm limiting myself to 56k here, up to 3 Mbaud is nice, but I very rarely use that). As I said in my initial post - you can throw 4 transistors at this with a few resistors and it'll be fine for many applications, but it wont' be "fast" or particularly elegant. (I should probably put my money where my mouth is and prototype and scope this).And again, it goes back to optocouplers - that often have an open collector output. The only real downside I can see to optos is the current consumption with strong pullups and regular traffic - not exactly and issue when debugging, since power consumption won't be a concern.Its one of those issues that seems to have glitched my brain a bit. Many solutions and not really a "problem" in modern electronics, and kind of niche for my application (hot plugging/powering equipment with debugging headers).

author: Whales
author_rank: Super Contributor
timestamp: May 04, 2025, 09:02:58 am
content: This is a notable problem for STC micros because programming them sometimes requires you to power cycle them and then quickly start UART communications (before the bootloader finishes). I used to have lots of power backfeeding problems from my USB-uart that prevented reset. I couldn't use the actual reset pin because I had co-opted it for other purposes.My original fix was to wire my power SPDT power switch to disconnect and short the 3.3V rail when in the 'off' position. I current limited the UART pins with some resistors. That worked.I then found that the datasheet makes a suggestion to solve this exact problem:Pin P3.0 is RX and importantly has an internal pullup. Pin P3.1 is TX (strong push/pull), so it still backfeeds a bit, not enough to cause me problems.This diode is an inferior version of the level shifting transistor suggested by others here, but still might sometimes be worthwhile. It's good enough for 115200 baud, I've never had problems.

author: David Hess
author_rank: Super Contributor
timestamp: May 04, 2025, 09:20:00 am
content: Quote from: Buriedcode on May 04, 2025, 03:05:48 amI could not find any modern logic which has open drain outputs without the high side protection diode, although I am sure it exists. Many open collector analog comparators do and could be used.There are simple ways to speed up a single NPN inverter:1. Use a fast transistor, like an MMBT2369 or PMBT2369 fast saturated switch. They are made for this application.2. Add a schottky Baker clamp diode.3. Operate the transistor in common base mode instead of common emitter. This means driving the emitter with the logic signal and connecting the base to a positive supply through a resistor. Non-inverting operation may be advantageous.

author: pqass
author_rank: Super Contributor
timestamp: May 04, 2025, 11:54:26 am
content: Another way to speed up (turning off) a NPN inverter is to connect a 100pf cap across the base resistor. Seehere.