I would like to interface a Raspberry Pi with an ATmega328p microcontroller using the I2C bus. These two parts act both as masters, but not at the same time. The Raspberry Pi is powered through the +5V pin on the GPIO header and power to the RPi is controlled by a p-channel MOSFET through the ATmega328p µC (see schematics). When the RPi is in power cut state, the I2C bus is pulled low disabling all I2C communication.
How do I disconnect the RPi from the I2C bus when power cut?
In detail, there are the following two operation modes:
- The Raspberry Pi is powered on (running) and acts as I2C master. The Raspberry Pi reads/sets the time from an PCF8583 RTC (I2C slave) and displays time and other information on a HD44780 compatible 16x2 LCD connected via an PCF8574 I2C expander IC. While the RPi is running, the ATmega µC I2C bus is sleeping and is not involved in any I2C communication.
This modus works as expected.
- The Raspberry Pi power is cut via a p-channel MOSFET when shutdown. While +5V line is disconnected by the FET, the RPi is still connected to common GND pulling all GPIO pins on RPi low. Hence the I2C bus constantly pulled low and I2C communication is disabled.
My question is, how can I isolate the Raspberry PI I2C connection from the bus when it is in powered off state?
I tried the following solutions:
- The RPi is powered through the normal micro USB plug and held in reset state (P6 header) when powered off. The I2C lines are high impedance and not interfering with the rest of the bus. This solution works, but I would like to cut power to the RPi completely.
- Adding simple diodes in SDA and SCL lines. This works for the SCL line as the RPi I2C bus always acts as master and generates the clock signal for the I2C slaves. However, the SDA line is bi-directional and hence communication is not possible with a diode inserted in between.
What is the easiest solution? I found suggestions here, but I do not understand how these circuits work and no explanation is given. Which of these schematics is best for this problem (if any)?
Any other (simpler?) solutions are welcome.
Thank you very much for your help.