60
\$\begingroup\$

What is the maximum length of cable that could be used to connect two I2C devices (I2C master-> I2C slave)?

Yes, I know that I2C is really designed for intra-board communication. I have been tasked with a "design goal" of using a common I2C bus for multiple I2C slaves to support a demo.

For purposes of clarity, let's assume the standard I2C bus rate of 100 kHz.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ The max length comes I to play with the capacitance introduced by the length. Too much capacitance and it could affect your speed. So as always, this depends. \$\endgroup\$ Commented Apr 11, 2014 at 20:38
  • 2
    \$\begingroup\$ @Nate Guideline: maximum net bus capacitance of 400pF. (Somewhat related to the question: Memoirs of an overgrown I2C bus.) \$\endgroup\$ Commented Apr 11, 2014 at 21:15
  • 2
    \$\begingroup\$ I2C = Inter-Integrated Circuit bus. It's not designed for long distances between boxes, and certainly not at 400kHz. \$\endgroup\$ Commented Apr 13, 2014 at 20:18
  • 1
    \$\begingroup\$ Just wanted to throw in some personal experience aside from calculations. I have done a demo going from a dev board to an I2C to USB converter with an unshielded wire about 3ft. Didn't look pretty, but it worked 90% of the time. \$\endgroup\$
    – mcmiln
    Commented Feb 3, 2016 at 18:03
  • 1
    \$\begingroup\$ Sometimes in extreme low power circuits where long distance transceivers are not viable due to current consumption I have used I2C over distances larger than 30m. This was achieved using Cat5E cables with a board rate of 1KHz. \$\endgroup\$ Commented Jun 17, 2016 at 13:10

6 Answers 6

27
\$\begingroup\$

For fast mode, and resistor pullup, capacitance should be less than 200pF, according to this NXP document I2C-bus specification and user manual.

With current source pullups you can go to 400pF, but not with resistors.

If your wire is 20pF/30cm and you have another 50pF of stray and input capacitance, you're limited to 2.25m of cable length. Different assumptions will lead to different numbers.

\$\endgroup\$
2
34
\$\begingroup\$

The insane sounding lengths like 10,25, and 100m are perfectly possible, and I use the method often (with UART not I2C, but the method stands) when I need to put stuff together quickly. It's not exactly the best way, though.

The key is to know your input voltage threshold. Make sure the voltage drop in the ground lead is well below this, or else a transmitter at a high ground potential will not be able to pull the voltage low enough. Lack of tolerance for ground offsets IMHO is the biggest reason to use RS485 or can transceivers (I2C over CAN is mentioned in a few application notes).

Ideally, all devices will have their own wall wart and battery and no power will be sent over the ground wire between devices.

But, lets take CAT5 for example. CAT5 can't be higher than 52pf/m, or it isn't CAT5.

100m of 52pf cable has a capacitance of 5200pf or 5.2nf.

5.2n times 20kohms (pullup) gives a time constant of about 104 microseconds. That limits speed to about 10kHz or so.

Using 2.2kohm pullups, you could probably get to 100kHz.

I have heard that devices should have a resistor on SDL and SCK, because of the big capacitive load they are driving, of something like 180 or 200 ohms.

But honestly, I2C is not at all the way to go for long distances. CAN transceivers or RS485 used with normal UART is a robust solution with very good fault protection, ESD resistance, speed, distance, etc, at a cost of a dollar a chip or so, ground offsets don't matter nearly as much so you are free to carry power along with data.

The only downside is that a can transceiver can reach 70ma transmitting and 1 or 2ma just listening, so I2C or direct TTL UART might be useful in extreme low power situations, but consider how much time you actually spend sending.

\$\endgroup\$
1
  • \$\begingroup\$ A little off topic, but I see the Raspberry Pi has 2 I2C pins and the rest are SPI seen here. Do you know if there would be a difference in these pins? \$\endgroup\$
    – Josh
    Commented Mar 9, 2021 at 12:17
16
\$\begingroup\$

I work for a company making USB sensors. Most of them are based on I2C sensor chips, those devices can be split in two, so you can install the CPU part in one place and the sensor part in another. We conducted quite a lot of tests on the I2C connection between the device CPU and the I2C sensors. At 100 kHz, with a good error recovery protocol, 25m can be easily reached using basic wires. We were even able to reach 100m once with CAT5 cable.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ 25m is quite a lot even for a usb... \$\endgroup\$ Commented Apr 12, 2014 at 6:23
  • 7
    \$\begingroup\$ No, I'm really talking about the I2C connection between the device CPU and the I2C sensor chips, not the USB connection between the host and the CPU. Here is an example: yoctopuce.com/EN/products/yocto-meteo/doc/… \$\endgroup\$
    – martinm
    Commented Apr 13, 2014 at 5:43
  • 2
    \$\begingroup\$ If you wanted to use twisted pair for I2C and power, which pair would you twist together? (SDA, SCL), (VCC, GND) or (SDA, GND), (SCL, VCC) ? \$\endgroup\$
    – Cano64
    Commented Feb 12, 2015 at 15:23
  • 10
    \$\begingroup\$ Ideally, you don't use twisted pair at all. Twisted pair is useful for balanced signals. If you don't have any other cable, twist signal with ground. If you really only have four wires, think about how much power the remote end consumes – you may end with a higher-than-tolerable ground offset – before committing to using only one wire for GND. I usually use old Cat5 cable (not higher! the double shield adds capacity you don't need) with one pair ground, one pair +5V, and SDA+GND and SCL+GND pairs. \$\endgroup\$ Commented May 24, 2017 at 16:19
  • 1
    \$\begingroup\$ How would you run the recovery protocol for the sensor side? The off-the-shelf sensors ICs with the I2C interface usually don't have any provisions for error detection or recovery. I've never seen sensors with those kinds of features. \$\endgroup\$ Commented Sep 10, 2018 at 22:54
8
\$\begingroup\$

Something like NXP's P82B96 could be used to change the voltage levels on the bus, allowing much longer distances.

The datasheet contains examples for I2C cable lengths of 3m, 25m, 100m and 250m.

There are other chips that have similar functionality.

\$\endgroup\$
3
  • \$\begingroup\$ The problem with the NXP chip is that you end up requiring twice as many wires. Any other ideas? the bidirectional ICs I've found don't go above +5V. \$\endgroup\$ Commented May 24, 2017 at 16:32
  • \$\begingroup\$ and why not use the PCA9515 I2C-bus repeater? no additional wires )when compared with P82B96 \$\endgroup\$ Commented Mar 19 at 18:15
  • \$\begingroup\$ That part only allows splitting the bus into two parts. The datasheet specifically says they can't be used in series. So best case you're doubling the maximum length, which is still quite limiting. \$\endgroup\$ Commented Mar 20 at 20:12
5
\$\begingroup\$

IIC is a synchronous protocol, and as such, it can be run arbitrarily slowly to meet system requirements with respect to distance and noise.

There are many examples of using IIC over a cable, all the way from ACCESS.bus back in the 1990s to how it is used today to retrieve EDID information from video displays.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Another example is the Wii Nunchuck, that connected to the Wii Remote via I²C using a 4 foot shielded cable. \$\endgroup\$
    – tcrosley
    Commented Apr 11, 2014 at 23:46
  • 1
    \$\begingroup\$ While in theory you could clock synchronous protocols arbitrarily slow, this is actually not true for I2C in general, hence this tip is a bad one. The reason is, many I2C chips have a minimum supported SCL frequency due to vendor-specific implementation details. This leads to not being able to clock such ICs with frequencies lower than 70-100 Khz (actual limit found in corresponding manuals of course). Not every I2C chip has this lower bound to SCL frequency, but quite many enough do. \$\endgroup\$
    – ultimA
    Commented Aug 6, 2020 at 11:13
4
\$\begingroup\$

Maybe overkill if it was working before, but an option is to use an I2C to Differential converter such as PCA9615, LTC4331, etc. If making the resistors smaller don't work or you need to extend the cable, consider not using I2C directly. Not only the range will be extended but you will also have better noise immunity

https://electronics.stackexchange.com/a/428983/147302

The Adafruit LTC4311 maybe an option.

The Sparkfun I2C breakout board is a nice solution

https://www.sparkfun.com/products/16988

  1. Use a bus extender. The P82B96 or PCA9600 would both be good options in your case.
  2. If you need higher speeds or extremely long cables, you can use a differential I2C transceiver like the PCA9600. However, this will make your circuit considerably more complicated, and you need an IC at both ends of the cable. Take a look at AN10658 and AN11084 from NXP for more information.

https://electronics.stackexchange.com/a/461016/147302

Use an I2C bus extender like the P82B715.

https://electronics.stackexchange.com/a/461030/147302

Pick a sensor that can work at a slower speed.

Also, https://hackaday.com/2017/02/08/taking-the-leap-off-board-an-introduction-to-i2c-over-long-wires/ is a good read.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.