View previous topic :: View next topic |
Author |
Message |
Johann17943
Joined: 11 Dec 2010 Posts: 11 Location: Germany
|
I2C changing slave address |
Posted: Sat Dec 11, 2010 4:04 am |
|
|
Hello!
I have a Pic to Pic bus system with one master (18F4550) and more slaves (16F1826) connected via I2C.
Is it possible to change the address of the slave by software?
My idea is to have all the slaves first programmed with the same address (same software). Then connect one after another (not more then one at a time) to the master and after first connection via the first address, I wish to change the slave address via the master sending the new address to the slave.
The slave will change the address then and after a reset it will have the new address (until the address is changed again in the same way).
Also possible option: depending on the input of two or three pins of the slave pic the software will set the address when it starts up.
What do you mean?
Thanks.
Johann |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Dec 11, 2010 4:45 am |
|
|
The last line, is the easiest.
This is how it is done on a lot of standard chips.
It is possible, using GCA, but you are always going to have the complexity of actually knowing for sure which chip is which. Since they all have the same code, making them choose/respond to different addresses will always be difficult. Much easier to just have some pins, selecting which address each chip uses. Also means that when you plug a new chip into a given location, you know that chip will respond to the same address as the last one...
Best Wishes |
|
|
Johann17943
Joined: 11 Dec 2010 Posts: 11 Location: Germany
|
|
Posted: Sat Dec 11, 2010 5:37 am |
|
|
Hello Ttelmah,
thanks for so quick answer!
Perhaps I should explain a little more detailed my project, for understanding.
The master and slave is not on the same board. I have one master device (board) connected via wire to more slave devices. The slave board will have always the same board with the same pic (and same software). The slave will activate 4 dc motors, the start and time of running a motor will come via I2C from the master. Because the slaves are connected in parallel to the I2C it is possible to connect up to 3 slaves (12 motors) to the master. The master code allows to control these 12 motors (on 3 slave devices). There are not always connected all 3 slaves.
If the slave address would be able to be changed by software, I would start to connect one slave, then search by the 3 possible addresses which slave is connected and have then the possibility to change the address.
If the slave address would be controlled by slave pic pins, I would have two switches/jumpers on the slave board to set the address.
As you can see the first option would be much better, I do not need jumpers or to open the device.
Important is for me to know how to set the address in the #use i2c(...):
1. address pointed to an address in the eeprom?
2. use the #use i2c(..) in main() where it can be set depending on an eeprom-value or the input of some pins
If you know how, please explain like for a dummy, I'm not so specialist in these (I have some experience in I2C communication with an RTC) and basic CCS-compiler knowledge.
Thanks.
Johann |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sat Dec 11, 2010 7:17 am |
|
|
I did 'remote address programming several years ago, so your idea is valid. Basically when a new 'device' is seen by the master, the master would assign the 'slave' an address,adding it to the database of slaves online.
You may have a problem with the I2C bus (timing, collisions, data corruption) if more than one slave is added to the bus at the same time. The master could see both slaves and their data mixed together (a ghosting condition). Providing you add one slave at a time and is configured to a unique address I do not see any technical issues. If you have an extra LED on the slaves, use it to confirm that an address has been issued and it is 'online'.
In my system, 4 LEDs were used to display the slave address and then blink to confirm online status (that was over 25 years ago..) using a handful of 4000 series CMOS chips. Today a single PIC will do it and much more ! |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sat Dec 11, 2010 11:03 am |
|
|
I have not played with I2C much, but you might want to check out how DHCP works in the ethernet world. It accomplishes what you are asking - basically a slave would announce that it was there and wanted an address, the master would "offer" a new address and then the "slave" accepts/acknowledges the address (that allows the case where more than one "dhcp server" can hand out addresses. The master now knows it has handed out a new address from it's available "pool" of addresses. The part that is missing is that usually there is a unique (or supposed to be anyway) MAC address that does not change associated with each interface. You could accomplish the same thing by giving each board a serial number that it uses when it requests an actual address. Just a thought.
A couple of links that may help you (or give you ideas)
http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol
http://kb.iu.edu/data/adov.html
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
|