I2C Addressing

Thread Starter

LewisMF

Joined Nov 15, 2014
119
1.
10 cm will be fine. It is when you get into meter or more, than you will have problems. There are a couple of ways to make i2c to work for longer distances, but, as you noted, your distance is not great so you don't need them.

2.
If your slaves use pre determined addresses and you know the maximum number of slaves, all you have to do is make master check through the list of slave addresses. Master can store the list in an array or you can do manual if statements.

3.
The manual address input is almost like interfacing keypad to uC. Only your's is even simpler. First you have to decide what input you want. Do you want active high to be the input or active low? Then you just configure 4 pins of the PIC as inputs (or configure the whole port, probably 8 pins, as input port). If that PIC has 8 bit ports, each pin of the port is a bit. Once you decide what type of input you want, you can wire 4 pins to be your digital zero and use the other 4 pins for the input via 4 position DIP switch. I think the most sensible would be to tie pins 7, 6, 5, 4 to be digital zero and use pins 3, 2, 1, 0 for the input from the DIP switch. This way when you select 0000 on switch, you will have 0000 0000 on the PIC port (00 hex). When you select 0001 on switch, you will have 0000 0001 on the PIC port (01 hex). When you select 0010 on switch, you will have 0000 0010 on PIC port (02 hex). And so on.
Hi shteii01,

Thank you for your brilliant explanation. I think I fully understand the idea. When I read off these ports, how do I make this reading be the address of the I2C slave?
 
Last edited:

Thread Starter

LewisMF

Joined Nov 15, 2014
119
As long as you are getting ribbon cables and connectors to lash everything together why not add a few extra lines to act as an address? Then you don't need the dip switches and you are guaranteed unique I2C addresses on every slave.
Hi ErnieM,

I like the idea but I don't fully understand the idea of 'adding a few extra lines to act as an address'.

If I did this, I assume that there would be no need for addressing via DIP switch or by software therefore I understand that the master would be the one addressing, is that correct?

Would this work independently of the slave that is connected? i.e. system is running with 3 slaves connected. Then system is turned off, the slaves are disconnected and rearranged and connected again and the system is turned on. It would work without having to change anything in software therefore the master would be addressing, right?
 

Thread Starter

LewisMF

Joined Nov 15, 2014
119
Interesting stuff.
What are you building with 7 slave PIC's? an LED matrix? a multi-motor controller? 3D printer, maybe?
Hi Korchoi,

It´s a security system based on a master and various slaves. The slaves will control the inputs for the sensors and the outputs for the relays, actuators, etc... Depending on the size of the building that needs to be protected, more or less slaves will be needed, within the range of 1 to 6 slaves. That's why I need flexibility with the addressing therefore the slaves will not be addressed by default, it will have to be the end user that addresses the 'expansion' PCBs depending of their position on the bus and the number of PCBs (slaves) that are connected.
 

shteii01

Joined Feb 19, 2010
4,644
Hi shteii01,

Thank you for your brilliant explanation. I think I fully understand the idea. When I read off these ports, how do I make this reading be the address of the I2C slave?
You have PIC port configured as input. In the software of your PIC you take this input and store it in a variable.
 

ErnieM

Joined Apr 24, 2011
8,415
You would drive the address lines the same way the dip switched would be set, and read the the same way too. Thos keeps anyone from setting a switch the wrong way.
 
Top