I2C, different power supplies?

If we connect two Arduino boards with I2C, can the boards have different power supplies or regulators to give about 5 V?

E.g. one Arduino is taking its power from USB (5V+-0.25V) , and the other from a battery pack of about 8 V through Vin to the Arduino regulator to produce 5 V +-0.25V.

There are warnings in the net that the pins SDA, SCL might have out-of-range currents or voltages in some situations ("back-power"). What happens if one power supply gives 4.75 V and the other 5.25 V ? If one Arduino has power on and the other power off, will there be magic smoke? Is there a foolproof simple way to connect those two Arduinos with I2C? If yes, how?

Is there significant difference in principle if we are talking about SPI instead of I2C?

I think you will be okay.

I2C is open collector, but the microcontroller has protection diodes to Vcc.
However, the current is limited by the pullup resistor.

For I2C, it is valid to lower the signal. That can be a device pulling the SDA or SCL down, but it can also be an Arduino with lower voltage that will pull it down to for example 4.5V or even 3.3V. No problem, the I2C bus will still work.

Even with an Arduino with no power, nothing gets damaged. But the Wire library might stop the Arduino. Some Wire library functions are blocking, and do wait forever when the SDA and SCL are shortcut to each other and I think also when SDA and SCL are shortcut to ground.

With SPI you do have a problem. And output pin of 5.25V to an Arduino without power will push the 5.25 into the Arduino and to the Vcc of that Arduino. The Arduino without power might even start working, or the output pin that delivers the current might be blown.

Erdin:
I think you will be okay.

I2C is open collector, but the microcontroller has protection diodes to Vcc.
However, the current is limited by the pullup resistor.

For I2C, it is valid to lower the signal. That can be a device pulling the SDA or SCL down, but it can also be an Arduino with lower voltage that will pull it down to for example 4.5V or even 3.3V. No problem, the I2C bus will still work.

Even with an Arduino with no power, nothing gets damaged. But the Wire library might stop the Arduino. Some Wire library functions are blocking, and do wait forever when the SDA and SCL are shortcut to each other and I think also when SDA and SCL are shortcut to ground.

With SPI you do have a problem. And output pin of 5.25V to an Arduino without power will push the 5.25 into the Arduino and to the Vcc of that Arduino. The Arduino without power might even start working, or the output pin that delivers the current might be blown.

Thanks, that is good news, for I2C.

As a newbie I still try to understand this more thoroughly.

When one Arduino is not powered at all, could there be a current (through the pullup resistors of SDA and SCL lines) of 5V/4.7kOhm = 1 milliampere from the powered Arduino there to the unpowered Arduino? Sure to be safe?( a strict warning of Grumpy_Mike in this thread)

Yes, there will be a current of 1mA, but nothing is damaged.
When an I2C device is communicating, it also lowers the I2C signals to 0V now and then. That is how the I2C works with the pull-up resistors. The resistors make the signal high, and the Master and Slave pull the signals low to communicate.

The I2C bus will no longer work when an Arduino is pulling the I2C bus down.
And 1mA might in some cases be enough to make the Arduino start working a little and even make a power led to light a little.

Erdin:
Yes, there will be a current of 1mA, but nothing is damaged.
When an I2C device is communicating, it also lowers the I2C signals to 0V now and then. That is how the I2C works with the pull-up resistors. The resistors make the signal high, and the Master and Slave pull the signals low to communicate.

The I2C bus will no longer work when an Arduino is pulling the I2C bus down.
And 1mA might in some cases be enough to make the Arduino start working a little and even make a power led to light a little.

I connected one Arduino Nano and Arduino Uno together with 1 ground wire, 1 SDA with 4.7 K ohm resistor pullup to 5V of Nano, and 1 SCL with 4.7 K ohm resistor pull up to 5 V of Nano. Then 1 usb cable from Nano to an usb-hub of a laptop, and 1 usb cable from Uno to the same laptop hub.

Test examples of Arduino ide worked well with 100 kHz speed and 400 kHz speed, although windows XP did not always recognize the usb devices at the first usb-connection attempt. (I used a separate usb-hub without external power supply to connect the Arduinos to the laptop).

The 5V pin in Nano had 4.54 V (!) and 5 V pin in Uno had 4.86 V.

When usb cable from Nano was disconnected, the 5 V pin in Nano still had 0.22 V.
When Nano was reconnected with the usb, but Uno disconnected, the Uno 5V voltage was 0.86 V.

When the pull up resistors were moved from the Nano power supply to the Uno power supply 5V, the unpowere voltages changed: Uno 0.19V, Nano 0.89V.

It is quite comfortable to be able to start two or more Arduino ide processes with their own boards and serial ports in the same computer and see the monitor windows from all Arduinos side by side!

But I am still concerned whether it is safe enough for me to let 1 milliampere current flow to an unpowered Arduino through the SDA pin internal protection diode(?) and another milliampere through SCL internal protection diode. There are strong opinions in the web that internal protection diodes should be allowed to have only microampere currents at most as designed. E.g. Russel McMahon's current table here.

Would it be good to add 8 external protection diodes:

SDA Uno to ground
SDA Uno to 5V
SCL Uno to ground
SCL Uno to 5V
SDA Nano to ground
SDA Nano to 5V
SCL Nano to ground
SCL Nano to 5V

e.g. Schottky 1N5819 ?

And perhaps increas the pull up resistors from 4.7K to a double or tripple value to decrease the current to the unpowered Arduino?

Well done, you have it working.

The 4.54 is not a problem. This happens when an Arduino is powered with usb.
It is low, but it still is above 4.5V, so that is okay.

Most of the time, the two pullup resistors are at the Master.
4k7 is often used, or 2k2 or 10k. The 10k might already be too high for 400kHz.

Nick Gammon has very nice pictures of the signals with different pullup values.

Scroll down for the analog bus signals.

I don't know how much current can be pushed into a pin.
Is that specified somewhere ? I can't find it.
Document AVR040 is about the protection diodes, but it doesn't say how much DC current they allow.

There are ways to protect the ATmega chip, but that is used when there are large voltage spikes, for example in a car. Protection diodes like the 1N4148 from the SDA and SCL to GND and VCC and with an extra resistor of 100 ohm to the A4 and A5 pin.

So the extra clamping diodes will catch the current/voltage, and the 100 ohm is low enough to keep the I2C bus going.

But this is not needed in your situation.

Erdin:
...
I don't know how much current can be pushed into a pin.
Is that specified somewhere ? I can't find it.
Document AVR040 is about the protection diodes, but it doesn't say how much DC current they allow.

There are ways to protect the ATmega chip, but that is used when there are large voltage spikes, for example in a car. Protection diodes like the 1N4148 from the SDA and SCL to GND and VCC and with an extra resistor of 100 ohm to the A4 and A5 pin.

So the extra clamping diodes will catch the current/voltage, and the 100 ohm is low enough to keep the I2C bus going.

But this is not needed in your situation.

Protection diodes: not over 1 mA recommended:
http://forum.arduino.cc/index.php?action=dlattach;topic=180727.0;attach=50238

Ideas about protection are welcome, because I 'll connect Arduinos and the electrical system of an electric bike together somehow.

Thank you for the link to the AVR182 document.
"It is not recommended that the clamping
diodes are conducting more than maximum 1 mA ..."

That 4k7 pullup should be no problem.

The Arduino is for prototyping, and it doesn't have good protecting for ESD spikes and voltage spikes. Perhaps you need optocouplers or other protection circuits. If the I2C wires are long and run along other wires, you might need to protect that too. In that case you could use the extra clamping diodes and the series resistors of 100 ohm.