Hi shteii01,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.
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: