I have some problems with i2c. I can not use long wires on SDA and SCK bus.

This seems to be the consequence of the capacity between the SDA and SCK wires and not between SDA/SCK and GND.

I figured this out by placing capacitors in a breadboard with a Arduino UNO and some MCP23017's (with 2k2 pull-up resistors).

100pF capacitor between SDA and SCK: No problem.

150pF: The communication stops.

1nF from SDA to GND and/or 1nF from SCK to GND: No problem.

A two wire cable is approx 50pF per meter, so 2 meters seems the limit.

With an ATtiny85 (8MHz clock, 100k i2c speed) as master it is even worse: With 2k2 pull-up a capacity of 68pF is killing.

By reducing the pull-up resisters to 470E I was able to go up to 200pF (hurray: 4 meters of wire).

Someone any idea how to increase the distance by tuning the SDA/SCK timing?

  • 1
    I2C is not designed to be used over long wires. What makes you think you can? – Majenko Sep 29 '17 at 17:23
  • 3
    A P82B96 Dual bidirectional bus buffer can help you "go the extra mile". See table on page 14, nxp.com/docs/en/data-sheet/P82B96.pdf – Mikael Patel Sep 29 '17 at 18:33
  • 1
    @MikaelPatel add your comment as a answer. – MatsK Sep 29 '17 at 18:40

As @majenko wrote, the I2C bus was not designed to go over wires or into a cable. It is ment for components on the same pcb board. As @mikaelpatel wrote there are bus drives which convert the I2C signal into some kind of RS-485 signal for twisted pair cables.

The crosstalk between SDA and SCL should be avoided at all times. Don't put SDA and SCL into wires that are next to each other. When using twisted pair cable (for example Cat5), then use SDA in a different pair than SCL.
The worst situation is when SDA and SCL are next to each other in a flat ribbon cable.

The capacitance caused by the cable from SDA to GND and from SCL to GND can be compensated some by a lower value of the pullup resistors and by lowering the clock speed.

The maximum current is specified as 3 mA. That means with 5V, the lowest value for the pullup resistor is 1k6.
A little more can be achieved with a current driver of 3 mA instead of the pullup resistors. This is not often done, but it creates a better signal.

The Arduino Wire library for the Arduino Uno can be set to 50 kHz with Wire.setClock. I don't know the lowest value, but there is a limit without warning. I don't know the lowest clock speed for an Attiny microcontroller. A software I2C bus implementation can often go much lower.
Note that some sensors have a minimum clock speed.

The rule of thumb is that 50 cm is the maximum for the I2C wires. However, some say that they are able to use the normal I2C bus over 6 meters cable. My opinion is that the I2C should always work, since it is not very fault tolerant, and the Arduino Wire library for the Arduino Uno is not fault tolerant at all. Therefor, don't go near the limits.

The MultiSpeedI2CScanner (probably only working for Atmega chips) helped me a lot to learn about the I2C limits in different situations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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