Arduino I2C multiple slaves
Connecting more than 1 I2C device to an Arduino is simple, if you follow some basic rules.
I2C Basics
The I2C bus is designed to be a multipoint serial connection system.
So it was always intended to use with multiple devices.
But how can they share the same Pins on the Arduino?
Here is a simple layout:
The µC Master is the Arduino, with multiple I2C Slaves connected over the SDA and SCL Lines.
The Trick is within the 2 pullup Resistors Rp!
I2C pullup resistors
They are needed to help the devices with getting the slew rates it needes. Depending on the i2c bus speed different rise times are needed.
In Standard mode with 100khz a maximum rise time of 1000ns is ok, for fast mode with 400khz the rise time should not exceed 300ns.
If want to just get it going, take 4.7k and it will work when you have just 1 slave.
But we want to make it right or?
The size is depending from the total capacitance in the circuit, so you will have to look to the datasheets and sum up the capacitance to get our Cb, next look up the formula:
Rp(max) = tr/0.8473 x Cb
Where tr is our allowed rise time for the signal, take this with 1µs or 300ns depending on your bus speed.
See also the TI Application note: SLVA689 I2C Bus Pullup Resistor Calculation
So what? What happens when the resistor is wrong?
I2C wrong pullup resistor
if the resistor is to high the signal rises to slow, that will cause missing bits -> trouble.
But also to low values get you trouble, they will draw too much current, do not go below 1k.
Good practice is to first make the calculations, then hook up a oscilloscope and verify your values.
I2C bus slave address conflict
Every slave must have a unique address, so check your datasheets and ensure that the devices all have unique addresses!
I2C Bus with mixed Voltages
mixing 5V and 3V devices is possible, but dont just connect them together!
(AN97055)
It needs a bidirectional level shifter, common practice is to use Mosfets with clamping diodes.
Take a look at the Application Note 10441 from NXP it is about "Level shifting techniques in I2C-bus design"
Also the old Application Note AN97055 "Bi-directional level shifter for I2C-bus and other systems." is a more in depth read about it.
Sources:
Silabs AN0011 I2C Master and Slave Operation
TI SCAA106 Troubleshooting I2C Bus Protocol
DSScircuits Effects of varying I2C pullup resistors
NXP AN10441 Bidirectional level shifter for I2C
Phillips AN97055 Bi-directional level shifter for I2C-bus and other systems
Comments powered by CComment