Is it safe to allow MCU pin signals to be controlled via another MCU/CPU? - Page 1
Forum section: electronics / beginners

author: amaschas
author_rank: Regular Contributor
timestamp: May 20, 2023, 07:03:33 pm
content: I am working on a board with a few LED drivers on it, and an MCU (ESP32) that controls the enable pin on the drivers via GPIOs. I would also like to allow an external device to control the enable functionality on the board, essentially overriding the MCU settings. For example, I'd like a Raspberry Pi (with appropriate level shifting), to be able to set the enable pin low, even when the ESP32 is driving it high. Is it safe to just add a pin header to the board that an external device can drive, or should I add some transistors in between to actual control the signals?

author: ddavidebor
author_rank: Super Contributor
timestamp: May 21, 2023, 12:05:10 am
content: Just put a resistor in between, so if they're both set to output accidentally they won't fry each other

author: Whales
author_rank: Super Contributor
timestamp: May 21, 2023, 07:32:48 am
content: Lookup "open collector bus driving", it allows multiple devices to all control the same wire without frying each other.

author: m k
author_rank: Super Contributor
timestamp: May 21, 2023, 09:18:51 am
content: Nowadays you can find single gate chips.It's still a chip but not very big.

author: amaschas
author_rank: Regular Contributor
timestamp: May 21, 2023, 07:24:53 pm
content: Quote from: Whales on May 21, 2023, 07:32:48 amIs the idea to just add pull-up resistors to the lines like I2C? I'm trying to work out what happens if both devices try to pull the line high if its already pulled high via the resistors.

author: jwet
author_rank: Frequent Contributor
timestamp: May 22, 2023, 12:20:01 pm
content: The conditions that you're trying to avoid is to have one guy high and one guy low on either side- this is the "fry" state where one output driver burns up the other.The magic of open collector driving is to use the tri state or floating output of your micros with the pullups. A high is a float (like an open collector of an NPN) and a low is a real low. This used to be called "wired-or" where either guy can pull down the output. With wired or and pullups, you usually have to think in inverted logic to get the priority right. After adding a pull up to each side, say 4.7k, instead of writing highs and lows, you write a low or let the pin float, which will create a "soft" hi which the other can pull down with a low without hurting anything. This is usually done with the data direction register or i/o config vs. just the output port. You basically write the port pin low and then write the DDR high or low to go from low to float.One difficulty is that the two pins can never be in opposite states with strong drivers enabled- this includes powering up, initializing or power fail, etc. If you can assure this, all is fine, if not, using a a little single gate as suggested or use diode steering or resistors-- basically hardware to protect things. Most but not all uP ports wake up in an input (tristate) state.

author: robca
author_rank: Frequent Contributor
timestamp: May 23, 2023, 04:03:36 pm
content: One more thing to consider: if one of the two MCUs is unpowered, weird thing can happen. Power can flow thru the protection diodes and cause excessive power draw (GPIO pins can only provide so much current) and/or the unpowered device powering up in an incomplete way (and potentially not booting properly if turned on after the first one).Also, as others have stated, you need to decide which device "wins" in case they try to drive different states. It can be done using open collector configurations or even better logic gates (or equivalent). Having logic gates or equivalent will also prevent any power issue I mentioned above

author: amaschas
author_rank: Regular Contributor
timestamp: May 23, 2023, 04:50:08 pm
content: Thanks for all your help everyone, I have a much better understanding of the trouble spots in trying to do something like this. I've decided for this PCB rev that in the interests of a solution with the fewest new components and new circuits that could add bugs, I'm just going to add jumpers between the enable pin of the drivers and MCU pins that drive them, so that I can just pull the jumpers and have an external MCU directly control them if necessary. At some later date I'll probably add a gate IC.