2
\$\begingroup\$

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?

schematic

simulate this circuit – Schematic created using CircuitLab

In detail, there are the following two operation modes:

  1. 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.

  1. 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:

  1. 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.
  2. 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.

\$\endgroup\$
  • \$\begingroup\$ Your PFET will not work. You have not got the drive circuit correct for turning on/off the 5V PFET power switch, with the 3.3V Atmega. It looks like you think PFETs and NFETs work the same way! \$\endgroup\$ – KyranF Apr 28 '15 at 17:57
  • 1
    \$\begingroup\$ I think your best bet is to find a I2C compatible (bidirectional) tri-state buffer IC, and use it's ENABLE pin controlled at the same time as the PFET to essentially "detach" the RPI's I2C pins from the I2C bus at the same time. \$\endgroup\$ – KyranF Apr 28 '15 at 17:59
  • \$\begingroup\$ I think the PMOS is backwards. You want to connect source to power supply and drain to raspberry pi. You want to pull up the gate to the source (5V). Use a small NMOS or NPN BJT to drive the gate low when you want the raspberry pi to power up. Let gate be pulled up to 5V when you want it de-powered. \$\endgroup\$ – mkeith Apr 28 '15 at 18:15
  • \$\begingroup\$ Why are you powering the atmega at 3.3 when you have 5V available? \$\endgroup\$ – Passerby Apr 28 '15 at 18:25
  • \$\begingroup\$ Quick note. I followed the link you provided. "Poul's circuit examples." The circuit labeled "I2C bus isolator with 2 MOSFETs" will work for you. I suggest you put a small capacitor (somewhere in range of zero to 18pF) from source to drain of the BSS138's. The cap may not be needed, but can improve rising edges if you find that the signal rise and fall times are too slow. \$\endgroup\$ – mkeith Apr 28 '15 at 18:35
3
\$\begingroup\$

I suggest you get a I2C compatible bi-directional buffer with tri-state/high impedance mode using "ENABLE" style signal.

I found one by NXP called the PCA9517A (which is on digikey for $1.37 a piece or 59c in bulk) which does all of the above, plus allows for voltage level shifting and defeats bus capacitance issues! The same signal used to remove power from the RPI can be used to drive the enable pin, thus detaching that whole side of the I2C bus from the AVR's side.

Another note about the PFET circuit you show - you need a logic-level gate voltage PFET, and you need to use a BJT to properly turn the PFET on/off, and at least put the pull up resistor there.

It should look more like this to operate correctly:

schematic

simulate this circuit – Schematic created using CircuitLab

Please realize that the capacitors I show are very important, the RPI needs good power supply decoupling and heavy duty bulk capacitance nearby, I suggest you place the capacitors as close as you can to the RPI's 5V input.

\$\endgroup\$
  • \$\begingroup\$ please change Q1 to an NPN type BJT. You have accidentally drawn in a PNP. Also, I would suggest 100k pullup, 10k base resistor. No need to load the gpio with 100 Ohms. And I agree with you that IRF9530 is a poor choice. OP should find something with Rds(on) specified at 4V or lower. \$\endgroup\$ – mkeith Apr 28 '15 at 18:30
  • 1
    \$\begingroup\$ @mkeith ah yes, accident on the BJT type. And the IRF9530 was just the circuitlab default PFET. \$\endgroup\$ – KyranF Apr 28 '15 at 18:32
  • 1
    \$\begingroup\$ @mkeith I agree with the resistor changes, I have changed them too. \$\endgroup\$ – KyranF Apr 28 '15 at 18:33
  • \$\begingroup\$ @mkeith Changed IRF9530 to IRF5305PbF which has VGS of -2V to -4V and is logic level compatible. \$\endgroup\$ – Pohl7534 Apr 28 '15 at 19:35
  • \$\begingroup\$ Actually, I would suggest something like this: Diodes, Inc part number DMG2305UX-13. There are many other options. You can search on digikey. Look for something in SOT 23 package with Rds less than 100 mOhm when Vgs is 4 or 4.5V. (You can select based on this parameter from digikey search page). \$\endgroup\$ – mkeith Apr 28 '15 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.