I'm working on interfacing to a SPI bus that is exhibiting some... bad behavior.
The bus comes from a control box on a toy drumset. The control box is the SPI master, and it can be turned on and off with a built-in button. A separate circuit that reads from the drumpads is the only slave on the bus.
What I am doing is this: I have basically added a master to the bus, in the form of a microcontroller. I know that this isn't a standard use of SPI, but it is for a hobby project, so I don't care. The two masters never operate simultaneously, so there are no conflicts. I mostly enforce this: If the control box is on, I don't plug in the USB cable to the microcontroller (I'm using a Pro Micro). Also, if the microcontroller detects the control box is on, the uC will end SPI communications.
Here is my circuit. I still need to buffer the MISO line, but other than that it's what I'm using.
There are three states this circuit can be in:
- Off - control box is off and the Pro Micro is unplugged
- Control box power - The control box is on, but the Pro Micro is off, thanks to the Schottky diode. The control box is the master, and the Pro Micro is isolated from the circuit.
- Pro Micro power - The USB cable is plugged in, and the Pro Micro is the master. The control box is off.
My issue occurs during state 1. Although the control box is off, the SPI lines coming out of it are showing 3.3V. For some reason, the control box powers MOSI, CLK, and CS even though its VCC shows 0V! When neither the control box nor Pro Micro is on, the buffer is unpowered, and the outputs are seeing 3.3V. Somehow this is reverse-powering the buffer, which in turn powers the rest of my circuit.
I'm using a SN74AHC125 buffer.
Before I started using the buffer, I connected the SPI lines directly to my microcontroller (ATMega 32U4). I had the same problem: The SPI lines powered my Pro Micro through the reverse protection diodes on the pins.
So how can I drive these lines when they are still powered while the rest of my circuit is off?