How to wire I2C address pins (A0, A1, A2, ...)?
When you want to use an I2C device like an EEPROM you might ask yourself how to wire the address pins (A0, A1 and A2).
The prime rule: No unconnected address pins
You need to remember the prime rule of I2C addressing: Never leave address pins unconnected unless explicitly allowed in the datasheet!
While there are some devices like the MCP3472 that allow floating address pins, most devices might not work properly (especially in noisy environments).
The second rule: Avoid address conflicts
You need to avoid having two parts with the same I2C address on the same I2C bus (address collisions)!
The I2C address of an I2C is 7 bits long and typically consists of a part-specific prefix (e.g. 0101
) plus address pins (e.g. 0101ABC
where A, B and C are the values of the address pins A0
, A1
and A2
)
First you need to find out **whether there are other devices on the same I2C bus,**i.e. other ICs that are connected to the same pair of SDA
and SCL
pins.
- In case there are no other devices on the same I2C bus, you can wire all the pins to GND(you can also wire any of them to VCC in case that works better for you. If in doubt, wire them to GND!)
- In case there are other devices on the same I2C bus, you need to proceed as outlined below
How to wire I2C address pins with multiple devices on the same I2C bus?
Multiple ICs with the same part number
If you have multiple ICs with the same part number on the I2C bus (examples: Multiple I2C ADCs, multiple I2C port expanders) it is quite easy to wire them to avoid address collisions: Just wire every one of the ICs differently. This will result in different addresses for each different IC.
Multiple different ICs
As we wrote before, you need to avoid having multiple ICs with the same address.
Most likely, different ICs will have different addresses in the first place, no matter how you wire their pins. However, this is not guaranteed!(if you are feeling lucky, producing only a small batch of prototype boards and don’t mind soldering around, you might as well test your luck and just assume they are different!).
Proceed as follows:
- Open the datasheets of all the parts you want to use in your design
- In each datasheet, find the section that lists the address details.
The address details will look like this:
In almost all I2C devices, the first few bits are fixed! The other bits ($A_2$, $A_1$ and $A_0$ in this example) depend on the address pins in one way or another. While in most devices they represent the address pins directly, some devices try to have more configurable address slots than address pins and hence use floating address pins.
Compare these fixed bits between the devices. In case you can be sure that no two devices can have the same address, you can wire the address pins either to GND or to VCC since it doesn’t matter.
In this example, there obviously can’t be conflicting addresses since some of the fixed bits are different(as indicated by the red lines).
If you can’t be sure that there is no conflict, you need to assign the address pins appropriately so the parts have different I2C addresses.
Our recommendation is to actually write down the I2C addressesand check if they are actually different. This approach avoids hard-to-debug errors. You can do this using old-school pen & paper or do it in any editor.
***Note: You should always write down the I2C address of each IC on the schematic, especially if you have multiple I2C parts!***Not doing this typically results in having to re-do the calulation over and over again.
Interested on how we made the address diagrams in this post? Check out How to visualize I2C first byte structure in TikZ