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.
-
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\$Gustavo Litovsky– Gustavo Litovsky2014年04月11日 20:38:57 +00:00Commented 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\$Nick Alexeev– Nick Alexeev2014年04月11日 21:15:22 +00:00Commented 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\$Spehro 'speff' Pefhany– Spehro 'speff' Pefhany2014年04月13日 20:18:55 +00:00Commented 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– mcmiln2016年02月03日 18:03:37 +00:00Commented 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\$Anthony Phan– Anthony Phan2016年06月17日 13:10:22 +00:00Commented Jun 17, 2016 at 13:10
6 Answers 6
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.
-
2\$\begingroup\$ @KrunalDesai It is specifically mentioned in the NXP document linked above. I2C-bus specification and user manual \$\endgroup\$Spehro 'speff' Pefhany– Spehro 'speff' Pefhany2016年04月12日 17:24:22 +00:00Commented Apr 12, 2016 at 17:24
-
3\$\begingroup\$ For a real-world example, the Nintendo Wii's "Wiimote" uses 400kHz I2C ( wiibrew.org/wiki/Wiimote/Extension_Controllers ) to communicate with peripherals like the Nunchuk ( wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck ) which, as you can see, has a cable that is about 1m. Passive extenders are sold to give an additional 1m ( amazon.com/Extension-Cable-Wii-Nunchuck-Nintendo/dp/B0039OEV9K ), so they're pushing, but staying within that 2.25m limit. \$\endgroup\$Rob Starling– Rob Starling2017年03月19日 20:49:10 +00:00Commented Mar 19, 2017 at 20:49
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.
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.
-
1\$\begingroup\$ 25m is quite a lot even for a usb... \$\endgroup\$Vladimir Cravero– Vladimir Cravero2014年04月12日 06:23:31 +00:00Commented Apr 12, 2014 at 6:23
-
8\$\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– martinm2014年04月13日 05:43:15 +00:00Commented 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– Cano642015年02月12日 15:23:34 +00:00Commented Feb 12, 2015 at 15:23
-
11\$\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\$Matthias Urlichs– Matthias Urlichs2017年05月24日 16:19:30 +00:00Commented 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\$Nick Alexeev– Nick Alexeev2018年09月10日 22:54:52 +00:00Commented Sep 10, 2018 at 22:54
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.
-
\$\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\$Matthias Urlichs– Matthias Urlichs2017年05月24日 16:32:53 +00:00Commented May 24, 2017 at 16:32
-
\$\begingroup\$ and why not use the PCA9515 I2C-bus repeater? no additional wires )when compared with P82B96 \$\endgroup\$Miguel Tomás– Miguel Tomás2024年03月19日 18:15:08 +00:00Commented Mar 19, 2024 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\$Jeffrey Nichols– Jeffrey Nichols2024年03月20日 20:12:19 +00:00Commented Mar 20, 2024 at 20:12
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.
-
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– tcrosley2014年04月11日 23:46:38 +00:00Commented Apr 11, 2014 at 23:46
-
2\$\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– ultimA2020年08月06日 11:13:17 +00:00Commented Aug 6, 2020 at 11:13
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
- Use a bus extender. The P82B96 or PCA9600 would both be good options in your case.
- 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.