Sub topic 13
Bus Capacitance and Cable Length
This chapter assumes you know how SDA and SCL work as open-drain lines, why pull-up resistors are needed, and how to use the Wire library. You should be comfortable reading a simple RC time constant and a datasheet timing table.
I2C is designed for short connections between chips on one board. Once you add breakout boards, jumper wires and longer cables, the bus can stop working even though the wiring is correct. The cause is usually capacitance, and this chapter explains how to estimate it and what to do about it.
Why capacitance limits the bus
Every conductor, pin and wire has some capacitance. On an I2C bus, all of these add up on each line:
- Each device pin adds roughly 3 to 10 pF.
- Each connector or breadboard row adds a few pF.
- Wire or cable adds capacitance per unit length. Typical unshielded jumper wire is around 30 to 50 pF per metre. Twisted pair or ribbon cable is often 50 to 100 pF per metre, and shielded cable can be higher.
Open-drain lines can only pull a line low actively. A rising edge happens only because the pull-up resistor charges the bus capacitance. That makes the rising edge an exponential curve, not a sharp step. The time constant is the pull-up resistance times the bus capacitance:
τ = R × C
The I2C specification measures rise time between 30% and 70% of the supply voltage. For an RC charge curve, that interval is about 0.8473 × R × C.
The I2C specification sets a maximum rise time (tr) and a maximum total bus capacitance (Cb):
| Mode | Clock | Max rise time | Max bus capacitance |
|---|---|---|---|
| Standard | 100 kHz | 1000 ns | 400 pF |
| Fast | 400 kHz | 300 ns | 400 pF |
| Fast-mode Plus | 1 MHz | 120 ns | 550 pF |
If the rise time is too long, the line has not reached a valid logic high when the receiver samples it. The result is corrupted bits, NACKs, or a bus that works for one device and fails when you add a second.
Working out a pull-up value
The rise-time limit gives you an upper bound on the pull-up resistance:
Rp(max) = tr / (0.8473 × Cb)
For Standard mode with 200 pF of bus capacitance:
Rp(max) = 1000 ns / (0.8473 × 200 pF) ≈ 5.9 kΩ
For Fast mode with the same capacitance:
Rp(max) = 300 ns / (0.8473 × 200 pF) ≈ 1.77 kΩ
A lower resistance gives faster edges. It also has a lower limit, set by how much current the devices can sink. The specification requires a device to sink 3 mA while holding the line at 0.4 V or less:
Rp(min) = (Vcc − 0.4 V) / 3 mA
At 5 V that is about 1.5 kΩ. At 3.3 V it is about 970 Ω. Choose a value between the two limits. Going toward the lower end gives cleaner edges but wastes more current and raises the low-level voltage.
The following table shows how the same 200 pF bus behaves with different resistors at 5 V.
| Pull-up | Rise time (0.8473 × R × C) | Fits Standard (1000 ns)? | Fits Fast (300 ns)? |
|---|---|---|---|
| 10 kΩ | about 1695 ns | No | No |
| 4.7 kΩ | about 796 ns | Yes | No |
| 2.2 kΩ | about 373 ns | Yes | No |
| 1.5 kΩ | about 254 ns | Yes | Yes |
Note that 10 kΩ, a common default on some breakout boards, fails even at 100 kHz once the bus reaches 200 pF.
Estimating the capacitance of your own bus
You can write a small calculator to check a design before you build it. This sketch runs on any Arduino and prints the estimated rise time and the allowed resistor range. It does not use the I2C bus. It is only a worksheet.
// Estimate I2C rise time and pull-up limits from a capacitance budget.
const float VCC = 5.0; // supply voltage in volts
const int DEVICE_COUNT = 4; // number of devices on the bus
const float PF_PER_DEVICE = 10.0; // pin plus breakout trace, in pF
const float CABLE_METRES = 1.0; // cable length
const float PF_PER_METRE = 60.0; // cable capacitance per metre
const float PULLUP_OHMS = 2200.0; // pull-up resistor value
const float MAX_RISE_NS = 1000.0; // 1000 standard, 300 fast
void setup() {
Serial.begin(9600);
float cbPf = DEVICE_COUNT * PF_PER_DEVICE + CABLE_METRES * PF_PER_METRE;
float riseNs = 0.8473 * PULLUP_OHMS * cbPf * 1e-12 * 1e9;
float rMaxOhms = (MAX_RISE_NS * 1e-9) / (0.8473 * cbPf * 1e-12);
float rMinOhms = (VCC - 0.4) / 0.003;
Serial.print("Bus capacitance: ");
Serial.print(cbPf, 0);
Serial.println(" pF");
Serial.print("Rise time: ");
Serial.print(riseNs, 0);
Serial.println(" ns");
Serial.print("Allowed pull-up range: ");
Serial.print(rMinOhms, 0);
Serial.print(" to ");
Serial.print(rMaxOhms, 0);
Serial.println(" ohms");
if (cbPf > 400.0) {
Serial.println("Warning: over the 400 pF limit");
}
if (riseNs > MAX_RISE_NS) {
Serial.println("Warning: rise time too long");
} else if (rMaxOhms < rMinOhms) {
Serial.println("No valid pull-up exists: reduce capacitance");
} else {
Serial.println("Rise time OK");
}
}
void loop() {
}With the default values the bus is 100 pF, the rise time is about 186 ns, and the allowed range is 1533 to 11803 ohms. Change CABLE_METRES to 5 and the capacitance becomes 340 pF, which leaves a much narrower range.
Practical limits on cable length
The specification does not set a maximum length. It sets 400 pF, and the length follows from your cable. With 50 pF per metre and four devices at 10 pF each, the 400 pF budget leaves about 7 m in theory. In practice, you should plan for much less:
- A breadboard with jumper wires works well up to about 50 cm at 100 kHz.
- Ribbon cable between boards is reliable up to about 1 m at 100 kHz.
- Beyond 1 to 2 m, noise pickup becomes a problem as well as capacitance. I2C has no differential signaling and no error correction on the wire.
Keep SDA and SCL apart from noisy conductors such as motor leads. Where you need a long run, do not put SDA and SCL as a twisted pair with each other, because the coupling between them can create crosstalk. Twisting each signal with its own ground wire is better.
Options when the bus is too slow
When rise time is out of range, try these in order:
- Lower the clock with
Wire.setClock(100000)or evenWire.setClock(50000). A slower clock does not fix the rise time itself, but it gives the line more time to settle before each sample, and it is often enough in practice. - Lower the pull-up resistance, staying above Rp(min).
- Shorten the cable or remove devices you do not need.
- Split the bus with a multiplexer such as the TCA9548A, so that each segment carries only part of the capacitance.
- Use a bus buffer or extender chip such as the P82B715 or PCA9600, designed for long runs.
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.setClock(50000); // 50 kHz for a long or heavily loaded bus
}
void loop() {
}Common mistakes
- Treating the 400 pF figure as a safe target. Stay well under it, since noise margins shrink as the rise time approaches the limit.
- Ignoring capacitance that comes from breakout boards. Many include their own traces, ESD parts and sometimes extra pull-ups.
- Using a very long cable and then raising the clock to 400 kHz. Fast mode needs three times shorter rise times than Standard mode.
- Assuming that a scanner that finds a device proves the bus is healthy. Marginal edges can still pass a one-byte address scan and fail on longer reads.
Exercise
A bus has 5 devices at 8 pF each and 2 m of cable at 50 pF per metre. It runs at 400 kHz from 3.3 V. Compute the bus capacitance, the maximum pull-up resistance for a 300 ns rise time, and the minimum pull-up resistance. Is there a valid value?
Show answer
Cb = 5 × 8 + 2 × 50 = 140 pF. Rp(max) = 300 ns / (0.8473 × 140 pF) ≈ 2.53 kΩ. Rp(min) = (3.3 − 0.4) / 0.003 ≈ 967 Ω. A valid pull-up lies between about 970 Ω and 2.5 kΩ, so a 1.5 kΩ or 2.2 kΩ resistor works.
Exercise
Your bus works at 100 kHz but fails at 400 kHz. You measure a rise time of 600 ns. Name two ways to fix it without changing the clock.
Show answer
Lower the pull-up resistance (staying above Rp(min)), or reduce the bus capacitance by shortening the cable or removing devices. A multiplexer to split the bus also works. The rise time must fall below 300 ns for Fast mode.