Dynamic address allocation

Technoman

Senior Member
Hi,

I am looking for advices concerning a network with a master and several slaves not having a static address as they could be connected and removed at any time.

Could it be done using an I2c bus with a slave having a default address at power on. The master is regularly sending that address, then give a new one to the slave when admitted within the network.
There is also the improbable case of simultaneous connexion. This issue could be solved in randomly giving a default address within a range.

Is there an other way (other type of bus, ...)?
 
Last edited:

oracacle

Senior Member
I am not sure how the i2c bus behaves with adding new components. however you have to find a way for the master to detect the new slave, you could have the slave pull the clock line low (similar fashion to an I2C ACK). you could force an entire system reboot and set address during power up.
if you don't go the power cycling route and you solve the new slave detection problem you would have to tell all the other slaves to ignore the data on the bus while the new address is sent to the new slave, once that done you need to check that the bus is still working correctly so test bytes would need to sent and received correctly from each of the slaves.

thinking about it, if you have a default address, the master could periodically check this address, if nothing is on the address 255 will be received to the masters bus, anything else could send it to an addressing mode. it really depends on what you are trying to achieve.
 

hippy

Technical Support
Staff member
It should be possible if a newly added slave starts with a known address. The master can poll that address and determine if an added slave is responding or not. If so it's present and can be told what its actual address will be. Other existing slaves should ignore those interactions because they will be on different addresses.

Behaviour of an I2C read or write for a non-present device isn't well defined and some PICAXE types behave differently to others. You might have to bit-bang the I2C bus to reliably handle devices being randomly added and removed.

You should be able to do similar using a multi-drop serial bus.

Handling multiple new devices connected at the same time is quite difficult no matter what is used.
 

Technoman

Senior Member
Thanks to all for these informations.

@oraracle : the system is not supposed to stop or reboot every time someone is connecting/disconnecting his/her personal key during the game ; every key should be hot-pluggable. The master would handle a list of currently connected keys before sending messages.

@hippy :
You might have to bit-bang the I2C bus ...
Still the difficulty to handle I2C error with the basic commands. Same answer as in my previous post concerning an I2C scanner.

... able to do similar using a multi-drop serial bus.
It is may be easier to implement.

The idea to randomly give a default address, between 240 to 255, to each slave should minimize an eventual risk of having two slaves responding at the same time. I will eventually need a more sophisticated protocol in which each slave would have a unique two bytes "MAC address".
 

PhilHornby

Senior Member
I am looking for advices concerning a network with a master and several slaves not having a static address as they could be connected and removed at any time.
Just a snippet of a thought ...

..could you use something like the Maxim/Dallas 'one-wire' protocol to do this? ... one end of the protocol already exists in Picaxe firmware, with various code snippets available for searching the bus for new devices. I've no idea if a Picaxe itself could emulate a one-wire device and exchange actual data though ... ?
 

oracacle

Senior Member
Have you also thought about detecting when a device leaves the system. the master would have to constantly poll every address to detect when there is no response from any given address.
 
Top