6

I am using an MCP23017 (which shouldn't matter tho) to extend the number of GPIO pins of an arm based linux computer using i2c-dev bitbanging. It all works fine with wires of a few centimetres.

The problem is that i would need 2*~3m wire in between clusters of 3 such MCP23017 based modules. Now, if i use a 3m wire (0.75mm diameter) for SCL and SDA i do get an ack for setting the address but polling the IC for the pin states results in confusing replies.

Sidenote: The MCP23017 has 2 banks of 8 pins each, with the 3 metre wire only 1 bank seems to work and B turns into A... Not sure what happens to the signal there, i guess the address in the request is being corrupted on a regular basis.

So i figured to increase the signal strength i would add an external pullup (the gpio pins used for bitbanging already have an internal one), which again works nice for some 10cm wires but kills even the address ACK for the 3m wire.

I tried 2k2, 4k7 and 10k ohms, all with the (exact) same result from my low resolution perspective.

Unforunately i don't have an oscilloscope to look at the whole thing and i'm not too knowledgeable about all the details to figure this out by just staring at it, therefore trying this route.

I hope someone has an idea what is happening here, what i could try or where i could learn enough to understand this on a level that helps me fix this. Let me know if you need any more info.

UPDATE: 3m wire now works with 850 ohms external pullups. going down to 150 ohms it also works with 6m but isn't a great thing to do since one easily uses more power (to pull the line low) than most gpio pins are rated for.

Gung Foo
  • 163
  • 5

3 Answers3

5

Given the high cable capacitance, you need a smaller resistor than 2.2k. Try 1k or 750. Also, a cable with lower capacitance will help. The communication to your i2c device is probably OK because bit banging would be slow.

Scott Seidman
  • 29,274
  • 4
  • 44
  • 109
  • could it be that leaving the gpio pins internal pullups on adds up to me actually increasing the resistance of the pullups by adding external ones? – Gung Foo Mar 14 '13 at 11:02
  • No. That resistor would combine in parallel, reducing overall resistance. – Scott Seidman Mar 14 '13 at 11:08
  • 1
    Awesome! Everything works with 820 Ohms.. thanks a bunch scott! i was soo close... :D – Gung Foo Mar 14 '13 at 11:13
  • What works, works, but keep in mind that you might be violation the i2c standard about how much current you can deal with. See page 39-40 in http://www.nxp.com/documents/other/39340011.pdf. You should be OK at 820, but the 150 seems real low. Reliable performance and long life would be more likely with a bus extender, as PeterJ was pointing you to. – Scott Seidman Mar 14 '13 at 12:59
  • i won't be needing 6m of wire so the 820 will suffice. – Gung Foo Mar 14 '13 at 13:00
4

The problem you're likely to be having with that cable length is the total 400pF capacitance allowed on the bus. Even most high quality data cable such as Cat 5e is around 50pF per meter. Then you also have to take into account the capacitance of other devices on the bus, the following somewhat related question has a good answer in that regard:

i2c bus capacitance

In general I2C is designed for communications over a short distance only. For longer distances while more expensive you might want to take a look at something like TIA-485 designed for robust operation over longer distances.

I haven't tried the solution myself but as an alternative to using a different protocol Texas Instruments make I2C bus extenders and the following device would likely meet your requirements, it allows 3000pF on the transmission side, the datasheet gives a good description of how it works:

P82B715 Bus Extender

PeterJ
  • 17,131
  • 37
  • 56
  • 91
  • thanks for your answer, i did fear that the cable capacitance would be a problem, which is why i tried to add the external resistor to smoothen the waveform. does the diameter of the cable affect its capacitance? is there anything i can do to get this to work, besides switching protocols? – Gung Foo Mar 14 '13 at 10:43
  • PS: would you perhaps be available for chat? :) – Gung Foo Mar 14 '13 at 10:45
0

Since I2C can work even at 0Hz (DC) you can insert two LEDs on the pull-ups and literally see what's going on on the bus, without resorting to an oscilloscope. You can step the protocol either using a button on a input GPIO or stepping the micro itself using the debugger.

If your I2C communication works at such low frequencies then it's likely a timing problem (check your RC constant made by the pull-up and the cable itself).