I2C-Bus with automatic Adresses

Hello,

i would like to implement an I2C - Bus - System, that acts a little bit, like a dhcp - server.
The reason i want to do this, is that i want to implement a system, where every component needs a unique adress. The unique address is specified in my arduino. My only problem is, that i cannot set the i2c-adress fix, because of the small range.

Can anyone help me ?

My only problem is, that i cannot set the i2c-adress fix, because of the small range.

What does "small range" mean? Why can't you set the I2C address to a fixed value? What other devices (other than the controlling Arduino) are connected to that bus?

There is a broadcast address 0x00, but I think it is not implemented in the Wire library.

You can use a start address, say 0x20.
Every module starts as 0x20, and the Master assigns a new address.
Every module has to be an Arduino in that situation.
If two new modules are connected at the same time, it won't work. I don't think there is a workaround for that situation.

The I2C bus was not designed for plug and play with modules.

If you want more I2C addresses, you can use a I2C multiplexer. Some create 4 new I2C busses.

@pylon

My only problem is, that i cannot set the i2c-adress fix, because of the small range.

Small Range means, that i2c adresses are limited to 127 devices. My idea is, to ship modules (sensors) that are able to work on any host (master) like an ethernet.
So there would be a big possibility that 2 modules with the same adress are connected together by the customer.

@Erdin
That was also my idea so far. And I had the same problem as you mentioned: "If two new modules are connected at the same time, it won't work. I don't think there is a workaround for that situation."
Any idea how to solve this?
I've read something about multi-master i2c and csma/ca. Does anyone have further information about this?

Thanks!

You need jumpers or dip switches, so every module can be set to a different address.

A DHCP server will go wrong if two devices have the same mac address. Every device needs its own mac address, and so does every Slave device on the I2C bus needs its own I2C address.

I think there is some collision detection before a Master starts transmitting, but I'm not sure how well it is implemented in the Arduino Wire library. If it is implemented, I doubt if it will work flawless. It is easy to get into a software loop when a number of modules try to start to transmit.

The SMBus is based upon the I2C bus.

The SMBus seems to be able to assign addresses on the fly.

Small Range means, that i2c adresses are limited to 127 devices. My idea is, to ship modules (sensors) that are able to work on any host (master) like an ethernet.

You know that I2C has other limitations (length for example, without extender chips you're limited to about half a meter in length) and is quite delicate about the bus capacity. So if you want to establish a bus which is able to access several sensors and has no fixed configuration, I'd rather go for a RS485 bus. It's much more reliable for longer cables and you can establish your own addressing scheme if you like.