Sub topic 6
Standard, Fast and other bus speeds
This chapter assumes you know how SDA and SCL work, why the bus uses pull-up resistors, and how a transaction is framed with START, ACK and STOP. You should also be able to write a basic Wire sketch. Here you will learn what the I2C speed grades are, what limits the speed in practice, and how to set the clock with Wire.setClock.
The speed modes
The I2C specification defines several modes. The mode is not negotiated on the bus. The controller generates SCL at whatever frequency it is configured for, and each target must be able to follow it.
| Mode | Maximum SCL | Maximum rise time | Notes |
|---|---|---|---|
| Standard-mode (Sm) | 100 kHz | 1000 ns | The default on Arduino boards |
| Fast-mode (Fm) | 400 kHz | 300 ns | Supported by most sensors and displays |
| Fast-mode Plus (Fm+) | 1 MHz | 120 ns | Needs stronger drivers (20 mA sink) and stiffer pull-ups |
| High-speed mode (Hs) | 3.4 MHz | Set by active pull-up circuitry | Needs a special controller start sequence |
| Ultra Fast-mode (UFm) | 5 MHz | Not applicable | Write-only, push-pull, no ACK. A different electrical scheme |
Most Arduino projects use Standard or Fast mode. Hs and UFm are rarely reachable from the Wire library, and they need support from the controller hardware and the target chips. If a datasheet lists "I2C up to 3.4 MHz", check whether your microcontroller can generate that mode before planning around it.
What limits the speed
Three things limit the speed, and the slowest one wins.
- The slowest device on the bus. A target rated for 100 kHz can misread bits or return garbage at 400 kHz. One slow device caps the whole bus, unless you isolate it with a multiplexer channel and change the clock before you talk to it.
- The controller. The hardware divides the CPU clock to produce SCL. Not every board can produce every rate, and the library may round your request.
- The rise time. An open-drain line is pulled low by a transistor but pulled high only by the resistor. The line rises as the resistor charges the bus capacitance. If the rise is too slow for the clock period, receivers see a high level too late, and the bits become unreliable.
The third limit is the one you control with hardware, so it gets the most attention below.
Rise time, pull-ups and capacitance
The specification measures rise time between 30% and 70% of the supply voltage. For a pull-up resistor R and total bus capacitance Cb, that time is approximately:
tr = 0.8473 × R × CbSolving for the largest resistor that still meets a mode's limit gives:
R_max = tr_max / (0.8473 × Cb)A lower limit also exists. When a device pulls the line low, it must sink the pull-up current and still reach a valid low level (about 0.4 V). With the 3 mA sink current of Standard and Fast mode:
R_min = (Vcc − 0.4 V) / 3 mAA worked example
Suppose the wiring and the chips add up to Cb = 200 pF, and you want 400 kHz on a 3.3 V bus.
R_max = 300 ns / (0.8473 × 200 pF) ≈ 1.77 kΩR_min = (3.3 V − 0.4 V) / 3 mA ≈ 967 Ω
Any value from about 1 kΩ to 1.7 kΩ works, so 1.2 kΩ is a reasonable choice. At 100 kHz with the same capacitance, R_max becomes 1000 ns / (0.8473 × 200 pF) ≈ 5.9 kΩ, so the common 4.7 kΩ value fits.
On a 5 V bus, R_min rises to about 1.53 kΩ, and the usable window at 400 kHz and 200 pF shrinks to roughly 1.5 kΩ to 1.77 kΩ. This is why a bus that works at 100 kHz can fail at 400 kHz without any code change.
Pull-ups add up in parallel
Many breakout boards carry their own pull-ups, often 4.7 kΩ or 10 kΩ. They are all connected in parallel with each other, so three boards with 4.7 kΩ each give about 1.57 kΩ. That is already near the lower limit on a 5 V bus. If you add external resistors on top, the combined value can drop below R_min. When you build a multi-device bus, count the pull-ups that are already present before you add any.
Setting the clock with Wire
Wire.begin() starts the bus at 100 kHz on most Arduino cores. Wire.setClock(frequency) changes the rate for the controller. It does not message the targets. Call it after Wire.begin():
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.setClock(400000); // request Fast mode, 400 kHz
}
void loop() {
}Key points about setClock:
- It is a request. The hardware divider may give a nearby frequency instead of the exact number. Use a logic analyzer or oscilloscope to confirm the real rate.
- It is global to the bus. All traffic after the call runs at the new rate, including traffic to slow devices.
- Some cores reset the clock when you call
Wire.begin()again, so set the clock after any re-initialization. - If you use a multiplexer, you can switch the clock between transactions to mix fast and slow devices. Keep this simple, because every change is one more place for a bug.
Measuring what you actually gain
Doubling or quadrupling the clock does not make a sketch four times faster. Each byte costs 9 clock cycles (8 data bits and an ACK). Reading a 16-bit register, as in the earlier register chapter, takes about 47 SCL cycles in total, from the address and register bytes, the repeated START, and the two data bytes. That is roughly 470 µs at 100 kHz and 118 µs at 400 kHz. On a slow microcontroller, the time spent in library code and interrupts adds a fixed overhead that does not shrink when the clock rises.
This sketch measures the real gain by probing every address, and it needs no device on the bus. A NACK takes about as long as an ACK, so the timing is still valid.
#include <Wire.h>
const unsigned long clocks[] = {100000UL, 400000UL};
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
for (byte i = 0; i < 2; i++) {
Wire.setClock(clocks[i]);
unsigned long start = micros();
for (byte address = 1; address < 127; address++) {
Wire.beginTransmission(address);
Wire.endTransmission();
}
unsigned long elapsed = micros() - start;
Serial.print(clocks[i]);
Serial.print(" Hz: ");
Serial.print(elapsed);
Serial.println(" us for 126 probes");
}
delay(5000);
}Expect the 400 kHz result to be noticeably shorter, but not a quarter of the 100 kHz result. The gap between the measured ratio and 4:1 is the software overhead.
When to raise the speed, and when not to
Raise the clock when:
- you move a lot of data, such as a display framebuffer or a block of samples from a FIFO;
- the loop timing is tight and the bus time is a measurable part of it;
- every device on the bus lists Fast mode support.
Stay at 100 kHz when:
- the wires are long, loosely wired, or run through a breadboard with many devices;
- any device is rated only for Standard mode;
- the pull-ups were not calculated and the bus is already marginal.
Common errors
- Calling
setClockbeforeWire.begin(), so the setting is lost. - Assuming the clock is negotiated, then wondering why a Standard-mode-only device misbehaves at 400 kHz.
- Adding external pull-ups on top of breakout-board pull-ups until the combined value falls below
R_min. - Expecting Fm+ or Hs from a board whose I2C peripheral cannot produce it.
- Measuring only SCL frequency and ignoring the rise time, which is where the real limit usually appears.
Exercise
A 3.3 V bus has a total capacitance of 100 pF and must run at 400 kHz (maximum rise time 300 ns). Using the 3 mA sink limit, what range of pull-up values is allowed, and would 4.7 kΩ pull-ups be acceptable?
Show answer
Rmax = 300 ns / (0.8473 × 100 pF) ≈ 3.54 kΩ. Rmin = (3.3 V − 0.4 V) / 3 mA ≈ 967 Ω. The allowed range is about 1 kΩ to 3.5 kΩ. A 4.7 kΩ pull-up is above R_max, so the rise time would be about 0.8473 × 4.7 kΩ × 100 pF ≈ 398 ns. That is longer than 300 ns, so it is not acceptable at 400 kHz. It would be fine at 100 kHz, where the limit is 1000 ns.
Exercise
You place four breakout boards on one 5 V bus. Each has 10 kΩ pull-ups on SDA and SCL, and you add 2.2 kΩ external pull-ups. What is the combined pull-up resistance, and is it above the 3 mA minimum?
Show answer
Five resistors in parallel: four of 10 kΩ and one of 2.2 kΩ. The conductance is 4 × (1/10 kΩ) + 1/2.2 kΩ = 0.4 mS + 0.4545 mS = 0.8545 mS, so the combined resistance is about 1.17 kΩ. R_min on 5 V is (5 V − 0.4 V) / 3 mA ≈ 1.53 kΩ. The combined value is below that, so the devices may not pull the line low enough. Remove the external resistors or use a larger value, for example 10 kΩ external, which gives about 1.4 kΩ in total.