0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 7:47 pm

Hello,

I am connecting BMP085 Pressure Sensor with the Raspberry Pi, it is an i2c device so I have followed this tutorial to enable i2c in my Raspberry Pi,

http://learn.adafruit.com/adafruits-ras ... guring-i2c

I have successfully enabled it and now when i type

Code: Select all

i2cdetect -y 1
I get the following table,

0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 69 -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77

In this table, the number 68 and 69 belongs to the ADC Pi connected to my RPi, and 77 belongs to the BMP085 Sensor.

I want to know what these numbers are and how are they assigned in this table.

As far as I can tell,
these numbers are the memory addresses in HEX (like 0x77)....but I am still confused how are they assigned when the i2c device are connected, and why it assigns the same address to the same device everytime ?

I can also observe that there are total 120 of these addresses (15*8 = 120)

User avatar
joan
Posts: 14990
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 7:59 pm

The devices have their I2C addresses hard-wired by the manufacturer. They presumably liaise to prevent clashes.

Some devices also have 3 little DIP switches (giving 8 combinations) which can be set to alter the address, e.g. if the default address is 56, it can be altered to be 57, 58, 59, 60, 61, 62, or 63 instead.

0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:04 pm

joan wrote:The devices have their I2C addresses hard-wired by the manufacturer. They presumably liaise to prevent clashes.

Some devices also have 3 little DIP switches (giving 8 combinations) which can be set to alter the address, e.g. if the default address is 56, it can be altered to be 57, 58, 59, 60, 61, 62, or 63 instead.
So, you mean there is no two devices in the world with same i2c address ?
and why they have to be a 7-bit address. ?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13217
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:07 pm

All I2C devices are assigned a fixed 7-bit address during manufacturing (sometimes several bit of the 7-bit adress can be changed by changing pins of the device high or low). A device will only react to the address it is assigned to.

0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:09 pm

mahjongg wrote:All I2C devices are assigned a fixed 7-bit address during manufacturing (sometimes several bit of the 7-bit adress can be changed by changing pins of the device high or low). A device will only react to the address it is assigned to.
If each i2c devices are assigned a fixed 7-bit address, then you are complying that there are only 120 "i2c" devices in the world ?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13217
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:11 pm

0x0000 wrote: So, you mean there is no two devices in the world with same i2c address ?
and why they have to be a 7-bit address. ?
No, all similar devices have the same seven bit address, but because you sometimes want to connect several identical devices to the same bus there are often one to three pins assigned that can be tied high or low to make up to eight of them dissimilar

0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:14 pm

mahjongg wrote:
0x0000 wrote: So, you mean there is no two devices in the world with same i2c address ?
and why they have to be a 7-bit address. ?
No, all the devices have the same seven bit address, but because you sometimes want to connect several identical devices to the same bus there are one to three pins assigned that can be tied high or low to make up to eight of them dissimilar
I didn't get you, how could there be more than 120 sensors with distinct addresses ? Please elaborate ....If I were to connect two BMP085 Sensors, that means both of these BMP085 will have the same memory address of 0x77, then How would I connect them together ? wouldn't they interfere?

There is no such button on the BMP085 sensor which allows to change the memory address of the sensor, beside SDA,SCL, GND and VCC , there are two other pins,
XCLR and EOC.

Could you please explain with the example ?

Like what would happen if i will connect two BMP085s ?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13217
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:19 pm

For example the popular IO expander chip PCF8575 has three hardware address pins, and an address base of hex20, so you can use up to eight of them on the same bus with addresses hex20 to hex27

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13217
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:23 pm

0x0000 wrote:
mahjongg wrote:
0x0000 wrote: So, you mean there is no two devices in the world with same i2c address ?
and why they have to be a 7-bit address. ?
No, all the devices have the same seven bit address, but because you sometimes want to connect several identical devices to the same bus there are one to three pins assigned that can be tied high or low to make up to eight of them dissimilar
I didn't get you, how could there be more than 120 sensors with distinct addresses ? Please elaborate ....If I were to connect two BMP085 Sensors, that means both of these BMP085 will have the same memory address of 0x77, then How would I connect them together ? wouldn't they interfere?

There is no such button on the BMP085 sensor which allows to change the memory address of the sensor, beside SDA,SCL, GND and VCC , there are two other pins,
XCLR and EOC.

Could you please explain with the example ?

Like what would happen if i will connect two BMP085s ?
If the BMP085 has no memory set pins, it means it has a permanent seven bit address, and that means only one of them can be used on an I2C bus.


Sometimes there are other mechanisms at work to still make it possible to add multiple of the same devices to the same bus, Disregarding the standard mechanisms. not sure if that is true for this device.

0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:23 pm

mahjongg wrote:For example the popular IO expander chip PCF8575 has three hardware address pins, and an address base of hex20, so you can use up to eight of them on the same bus with addresses hex20 to hex27
OK Got it,

You mean to say that the IO expander chip has three hardware address pins so 2^3 = 8 , which means , from the base address of 0x20 we can use the same bus and can assign addresses from 0x20 to 0x27.

But BMP085 has no hardware address pin which allow us to change its address.

User avatar
joan
Posts: 14990
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:24 pm

0x0000 wrote:
mahjongg wrote:
0x0000 wrote: So, you mean there is no two devices in the world with same i2c address ?
and why they have to be a 7-bit address. ?
No, all the devices have the same seven bit address, but because you sometimes want to connect several identical devices to the same bus there are one to three pins assigned that can be tied high or low to make up to eight of them dissimilar
I didn't get you, how could there be more than 120 sensors with distinct addresses ? Please elaborate ....If I were to connect two BMP085 Sensors, that means both of these BMP085 will have the same memory address of 0x77, then How would I connect them together ? wouldn't they interfere?

There is no such button on the BMP085 sensor which allows to change the memory address of the sensor, beside SDA,SCL, GND and VCC , there are two other pins,
XCLR and EOC.

Could you please explain with the example ?

Like what would happen if i will connect two BMP085s ?
Unless the device has a mechanism to change its I2C address (via DIP switch or internal persistent memory) you are stuffed and will only be a able to use one on the I2C bus.

0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:25 pm

Now this is the correct answer to my question , Thanks a lot :)

0x0000
Posts: 137
Joined: Tue Aug 27, 2013 8:59 pm

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:30 pm

mahjongg wrote: Unless the device has a mechanism to change its I2C address (via DIP switch or internal persistent memory) you are stuffed and will only be a able to use one on the I2C bus.
Just find out that actually its kind of possible,

Because each I2C device on the bus needs to have it's own unique address, you normally can only have one device at address 0x77 (etc.). If you require several I2C devices at the same address, and if the devices have a reset pin (like the BMP085 does), then you CAN use multiple devices at the same address ... but at the expense of one GPIO pin per device. What you can do is hold the other devices in reset by pulling the XCLR (Reset) pin low, and letting XCLR go high on the one device that you do want to read, releasing it from reset and causing it to respond to any request on the I2C bus.

achrn
Posts: 421
Joined: Wed Feb 13, 2013 1:22 pm

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:32 pm

0x0000 wrote: I didn't get you, how could there be more than 120 sensors with distinct addresses ? Please elaborate ....If I were to connect two BMP085 Sensors, that means both of these BMP085 will have the same memory address of 0x77, then How would I connect them together ? wouldn't they interfere?
As you have determined, on this device XCLR is effectively an 'enable' signal, so you can have more than one on the bus, as long as you use separate control lines to shut down all but one of them using teh XCLR lines. You talk to that one, then shut that one down and enable another one, then use teh same address to talk to that one.
0x0000 wrote: Like what would happen if i will connect two BMP085s ?
If both are active, it's undefined, but probably this: The way I2C works any device can pull a single bit low. So you'd send the command, both devices would receive it and do their processing. Both would try and answer simultaneously. If they were perfectly in sync the answer you'd get back would be whatever you get if you do a bitwise AND on the answers from the two devices. That is, if one answered 10110001 and one answered 01000110 you'd receive 00000000. However, in reality you're outside the devices spec and you might get anything (or nothing) back.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13217
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 8:37 pm

This I2C device has a base address of hexEF, ans so only one can be adressed on an I2C bus, but it does have an expansion scheme, see paragraph 4.2 of the .PDF at https://www.google.nl/url?sa=t&rct=j&q= ... 7178,d.d2k

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: How i2c assigns memory addresses to the devices

Sat Dec 28, 2013 9:56 pm

Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

Return to “Beginners”