Page 1 of 1

PIC18 Addressing Multiple Slaves over I2C

Posted: Sun Feb 12, 2017 5:25 pm
by mreiter
Hello!

It seems I have been posting here a lot recently, but I am making progress! As of now, if you've been following my recents posts, I have gotten I2C unconditionally working for my RTC. Now I am moving onto incorporating other slave devices, of which, I particularly need to get two of these colour sensors (https://cdn-shop.adafruit.com/datasheets/TCS34725.pdf) to work.

So my questions is, how is the addressing is going to work? Conceivably, I need to read from these colour sensors separately, and to do so I would need to go through the proper I2C channels under a different start address. So if I am using 2 identical sensors, wouldn't that address be the same?

As always, thanks for the help.

Matthew

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Mon Feb 13, 2017 8:02 am
by phalanx
Hi again,

If all you need is 2 color sensors, you can use a TCS34725 and a TCS34721. The only difference appears to be their slave address which is 0x29 and 0x39 respectively.

Another option would be to bit-bang the I2C bus using GPIO from the PIC effectively creating a software controlled I2C bus that's independent from the hardware one. You could also change PICs to one that has multiple I2C units in hardware.

Another possibility would be to see if the SCL and SDA pins of the sensor stay HI-Z if you remove power from the Vdd pin. If this is the case, you could connect Vdd to a GPIO pin on the PIC and use it to turn specific sensors on and off under software control. You will have to check to make sure things stay high impedance when powered down otherwise this won't work.

Another option is to use an I2C address translator such as the LTC4317 from Linear Technology: http://www.linear.com/product/LTC4317. This part will change the slave address by an amount that you configure via a resistor divider allowing you to use multiple parts with the same address.

-Bill

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Mon Feb 13, 2017 9:31 pm
by mreiter
As always, thanks for the quality response. I genuinely am impressed at how dedicated you are to help.

I will definitely look into using the TCS34721, unfortunately I have not been able to come across one. The LTC4317 seems like a quite order away, and definitely sounds promising.

But in terms of "bit banging", Im not quite sure what this means in terms of how I would set this up. Do you have/know of any resources that would be a good place for me to start researching?

Matthew

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Tue Feb 14, 2017 7:13 am
by DanV
just google "bit bang i2c"

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Tue Feb 14, 2017 7:42 am
by phalanx
Basically, bit-banging means using your GPIO pins and their 3 states (output-high, output-low, input-hi-z) to emulate the functionality of a hardware communications peripheral. You can emulate UARTs, CAN, SPI, I2c, parallel interfaces, etc. You have to manage all the timing, state changes, pin configurations, and protocol adherence in software. It's a bunch of tedious work but not overly difficult if you have a good understanding of the protocol you are trying to bit-bang.

-Bill

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Tue Feb 14, 2017 1:08 pm
by mreiter
Alright thanks for the clarification. I think the first thing that i will try in my lab today is simply multiplexing the inputs

Thanks

Matthew

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Tue Feb 14, 2017 2:06 pm
by phalanx
I'm curious to know how you intend to multiplex open-drain I2C signals.

-Bill

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Tue Feb 14, 2017 2:42 pm
by mreiter
I have not yet tried this mind you, but I was planning on connecting the SDA pins of the two color sensors to the input of the of a two to one multiplexer, with the output connected to the SDA pin of the PIC.

You mentioned "open drain" as if that would prevent this?

Matthew

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Tue Feb 14, 2017 2:55 pm
by phalanx
My point was a simple multiplexer IC won't necessarily work. This did inspire me to actually look up I2C multiplexers which I haven't had occasion to do before and this IC came up: http://www.ti.com/lit/ds/symlink/tca9548a.pdf

It's an 8 channel I2C switch that can pass bidirectional I2C data from the input to any combination of the outputs. I was unaware a part like this existed and it looks easier to use than the address translator part I linked to previously.

-Bill

Re: PIC18 Addressing Multiple Slaves over I2C

Posted: Tue Feb 14, 2017 3:16 pm
by mreiter
Getting that part will be easy, thanks. I think ill first try a regular mux though :dance:

Matthew