Pages: [1]   Go Down
Author Topic: I2C Discovery  (Read 1386 times)
0 Members and 1 Guest are viewing this topic.
Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm designing devices that will be communicating via the I2C protocol.  One of the shortcoming of I2C is that it can't do an auto discovery of slaves and I want to build something where the end user doesn't need to figure out how to set addresses on the slaves.  So I'm trying to figure out some way of doing slave discovery on a network and came up with the following idea.  I'm hoping you guys can help me figure out if this will work, what have I forgotten or overlooked, caveats, etc., etc.

The I2C slaves will always come up with an address of 0x00 and won't do anything till told.  By pushing a button, they will then join the network with that address and wait.  Pushing a button on the master will put it in discovery mode (for a set amount of time, say 15 seconds).  During this time, it broadcasts only to address 0x00.  If it receives an ACK, that means there's a slave on that address.  At that point the master will send a new address (> 0x00) to that slave and it gets stored in an array on the master.  The slave receives the address and reconfigures itself to use that new address.  Subsequent slaves all get a new (incrementing) address from the master.

Notes:
the slaves, when first powered up, will *not* respond to address 0x00, not till a button on them is pushed, therefore enabling them to join the network with address 0x00.
the slaves, when suffering a power loss, will forget their address and will come back up as 0x00 next time they are powered up.
the master will only go into discovery mode when told to by a push button
the master, when entering discovery mode, will check it's own array first to see if there aren't slaves already configured.  If so, it continues to increment the address from the last slave in it's array.
the master, during discovery mode, will keep a record of all the slaves it has discovered
the master, when suffering a power loss, will forget all of this and start without any knowledge of slaves upon power up
the master, when in discovery mode, will reset its 15 second timer each time it configures a new slave.  This is so that it has time to continue configuring new slaves in case there are a bunch of them that can't all be configured within the allotted time.  After 15 seconds it exits discovery mode and returns to it's normal routine.

And with this being a specific, custom design, I don't plan on adding anything to the network with address 0x00, so technically there shouldn't be any issues there.

What am I forgetting?
Logged

Offline Offline
Sr. Member
****
Karma: 7
Posts: 290
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The thread right befor yours have some useful information that directly relates to your project:

http://arduino.cc/forum/index.php/topic,128361.0.html
Logged


Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The I2C is only for short wires (within an apparatus).
Do you want to use long wires ?

Some use longer addresses for the I2C devices. That could make things easier.
I don't know if that is programmable for an Arduino.

A power loss will make the slave react to 0x00 ? What if three slaves have power loss.
If they are the same devices with the same timings, the master thinks there is only one slave, and sets it to a new address. But all three have now the new address.
What if someone pressed the button on three slaves simultaneously ?
« Last Edit: January 01, 2013, 12:15:42 am by Krodal » Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The I2C is only for short wires (within an apparatus).
Do you want to use long wires ?
Nope, these will all be relatively close to each other.

A power loss will make the slave react to 0x00 ? What if three slaves have power loss.
If they are the same devices with the same timings, the master thinks there is only one slave, and sets it to a new address. But all three have now the new address.
The only time this would be remotely possible is if someone tells all three to do a discovery at the same exact time.

What if someone pressed the button on three slaves simultaneously ?
This is why there will be documentation specifically not to do that.  One at a time.
Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The thread right befor yours have some useful information that directly relates to your project:

http://arduino.cc/forum/index.php/topic,128361.0.html
Yeah, I've been reading that one as well and actually learned quite a bit from that as well.
Logged

Pages: [1]   Go Up
Jump to: