Close

Dynamic address resolution

A project log for Intelligent Shields

A system to build intelligent shields, for use with Arduino, Raspberry Pi or directly connected to a computer.

mattias-wingstedtMattias Wingstedt 08/21/2014 at 01:141 Comment

SMBus already uses a dynamic address resolution, and SMBus is based on I2C. So maybe we could just use their algorithm?

SMBus relies on slave bus arbitration. Bus arbitration on I2C works by the node both writing to the bus, and listening to the bus. If several nodes write to the bus 0 always trumps 1. So if a node writes a 1 but reads a 0 it knows that several nodes are writing at the same time. It also loses arbitration and needs to shut up. In the dynamic address resolution of SMBus each node that needs an address writes its unique id. Since the UIDs differ the nodes must lose arbitration until only one is left. That node gets an address, and then the process repeats until all nodes have gotten an address.

However most AVR processors with I2C (or TWI) support do not support bus arbitration in slave mode. They only support bus arbitration in master mode. Which seem to make it impossible to implement the SMBus address resolution protocol on an AVR based Arduino. At least using the builtin TWI support, there is probably a way if you build a software I2C implementation.

Another factor is that the SMBus standard requires a unique id for each node. Something which may make it harder to create firmware, since each shield would need its UID added in the flashing process.

So I think there are three ways to design a dynamic address resolution algorithm, that can be implemented on an AVR based Arduino:

1) A UID based approach, that uses bus arbitration in master mode
2) A random number based approach, that uses bus arbitration in master mode
3) An shield enable signal, that is connected between each shield, so we can enable each shield in order

I do not like the first approach because of the need to add a separate step when flashing the shield firmware

I am not sure how easy it is to get a good enough random number on an AVR processor. If it is easy then we should look into this approach.

Now I like the third approach best. The drawback is that it will not be as easy to build a board with through-hole connectors. However it will be easy using surface-mount components. Another advantage is that we will find the physical layout of the shields. We will know in which order the shields are stacked, and may use that order when programming.

Discussions

John Matthias Syrinek wrote 07/18/2015 at 22:56 point

Great information! I'm trying to build a plug-and-play system, and not sure how to handle address conflicts with I2C either. I considered 1-3 as well, and for #2 - random number approach - if you have an extra ADC input pin, you could leave this pin floating and read its value. This may provide fairly random values.

By the way, have you found any SMBus libraries for Arduino? I'mA designing the slave-devices for a customizable pinball platform and am considering using Atmega8's.

  Are you sure? yes | no