ElectronicsInfoline

Serial buses

Basics of the I²C communication protocol

By Bulan Sarkar, founder of ElectronicsInfoline (since 2000) · About a 12-minute read

I²C (say "I squared C") is the two-wire bus that most hobby sensors, small OLED screens, real-time clocks and LCD backpacks use. One microcontroller talks to many chips over the same pair of wires, and each chip answers only to its own address.

This page covers what happens on those two wires, why the bus needs pull-up resistors and how to pick their value, the 7-bit against 8-bit address mix-up, and when SPI or a plain UART would do the job better. The bus rules come from NXP's I²C specification (UM10204), and the part numbers from the makers' data sheets, all listed at the end.

Advertisement

I²C is a serial bus with two shared lines: SDA carries the data and SCL carries the clock. A controller (usually your microcontroller) starts every transfer, sends a 7-bit address, and only the chip with that address replies. Both lines are open-drain, so each needs one pull-up resistor to the supply.

Standard-mode runs at 100 kHz and Fast-mode at 400 kHz. There are 112 usable addresses. Every byte takes 9 clocks, eight data bits plus an acknowledge. For a short breadboard bus at 400 kHz, 2.2 kΩ pull-ups are a safe pick on 3.3 V or 5 V; the common 4.7 kΩ is too weak once the bus passes about 75 pF.

I²C in four numbers

Usable 7-bit addresses
112
Clocks per byte, ACK included
9
Largest pull-up, 400 kHz on 100 pF
3.54 kΩ
128×64 OLED frame at 100 kHz
92.3 ms

Two wires, many chips

Every chip on an I²C bus connects to the same SDA and SCL lines, and to a common ground. The controller drives the clock and decides who speaks. The other chips are targets: a temperature sensor, a clock chip, a display. Older documents and most Arduino code call them master and slave; NXP changed the words to controller and target in 2021 (NXP Semiconductors).

VDDRp = 2.2 kΩ eachSDASCLArduino UNOcontrollerOLED0x3CLCD backpack0x27sensorown addressevery chip shares GND as well; each target answers only to its own address
Figure 1. One controller and three targets share SDA and SCL. A single 2.2 kΩ pull-up on each line serves the whole bus.

On an Arduino UNO, SDA is pin A4 and SCL is A5 (the R3 also repeats them on the two pins beside AREF). The ATmega328P's I²C hardware, which Microchip calls TWI, handles up to 400 kHz (Microchip).

Why the lines need pull-ups

No chip on the bus ever drives a line high. Each one has a transistor that can pull the line to ground, or let go. A resistor to the supply, the pull-up, lifts the line back up when everyone has let go. This is called open-drain (open-collector on older bipolar parts).

VDDRplinechip Achip Ba chip can pull low, never drive highABlineoffoffHIGHonoffLOWoffonLOWononLOW
Figure 2. Two open-drain outputs on one line. The line is high only when both let go, so any chip can hold it low and none can fight another.

Two things follow. First, two chips can never short the supply by driving opposite levels, which is what makes a shared bus safe. Second, a target can hold SCL low to make the controller wait (clock stretching), and it can pull SDA low to acknowledge a byte. The cost is speed: the line falls fast through a transistor but rises slowly through a resistor charging the wire's capacitance. That rise sets the pull-up value, worked out below.

Advertisement

One transfer, bit by bit

A transfer opens with a START: SDA falls while SCL is high. Then the controller clocks out the 7-bit address and one more bit, 0 to write or 1 to read. On the ninth clock it lets go of SDA, and the addressed chip pulls it low. That low bit is the acknowledge (ACK). If no chip answers, SDA stays high: a NACK, and the transfer stops.

Data bytes follow the same pattern, eight bits and an acknowledge. A STOP ends it: SDA rises while SCL is high. Those two moves, START and STOP, are the only times SDA may change while SCL is high (NXP Semiconductors).

SCLSDASP010011100000010000address 0x27Wdata 0x08SDA changes only while SCL is low; S and P are the two exceptionsdriven by the target
Figure 3. Writing 0x08 to a PCF8574 LCD backpack at 0x27: START, address 0100111, write bit, ACK, data byte, ACK, STOP. The green bits come from the target.

Count the clocks and you can time any transfer. Writing one value into a sensor register takes three bytes (address, register number, value), so 27 clocks: 270 µs at 100 kHz. Reading 6 bytes back, the size of an accelerometer's X, Y and Z, takes the register write, a repeated START, the address again and six bytes: 81 clocks, or 810 µs at 100 kHz and 202.5 µs at 400 kHz.

Addresses, and the 0x27 against 0x4E trap

The address is seven bits, so there are 128 of them. The specification reserves two blocks of eight, 0000xxx and 1111xxx, for special jobs such as the general call and 10-bit addressing, which leaves 112 for ordinary chips (NXP Semiconductors). A chip usually has a fixed part of its address and one to three pins that set the rest, so you can fit several of the same chip on one bus.

0A61A50A40A31A21A11A0R/Wbit 07-bit address 0x270 write, 1 readSame byte read as 8 bits: 0x4E to write, 0x4F to read.Libraries want the 7-bit number; some data sheets print the 8-bit one.0x08–0x77: 112 usable0x00–0x07 reserved0x78–0x7F reservedthe 128 seven-bit addresses, reserved blocks in red
Figure 4. The address byte of an LCD backpack at 0x27. Shifted left with the R/W bit added, the same address reads 0x4E or 0x4F.

The trap is the address form. The PCF8574, the chip on most 16×2 LCD backpacks, has the address 0100 A2 A1 A0, which is 0x20 to 0x27. TI's data sheet lists it as 8-bit write addresses, 0x40 to 0x4E (Texas Instruments). The SSD1306 OLED controller is 011110 plus one pin, 0x3C or 0x3D, and some module sellers print that as 0x78 (Solomon Systech). The Arduino Wire library, like most libraries, wants the 7-bit number. If a data sheet address doesn't answer, halve it.

Speed modes and real transfer times

UM10204 defines Standard-mode at up to 100 kHz, Fast-mode at 400 kHz and Fast-mode Plus at 1 MHz (NXP Semiconductors). Faster modes exist, but hobby parts rarely support them. The bus runs only as fast as its slowest chip: the PCF8574 is rated to 100 kHz (Texas Instruments), so a bus with an LCD backpack on it should stay at 100 kHz, whatever else shares it.

With 8 data bits in every 9 clocks, 100 kHz moves at most 11,111 bytes a second. That is plenty for sensors and slow for screens. A 128×64 monochrome OLED holds one bit per pixel, so a full frame is 1,024 bytes; with the address and a control byte it takes 9,234 clocks.

I²C 100 kHz92.3 ms (11 fps)I²C 400 kHz23.1 ms (43 fps)SPI 8 MHz1.02 ms (977 fps)ms per frame, log scale
Figure 5. Time to send one full 128×64 OLED frame (1,024 bytes). Over SPI the same SSD1306 takes a clock up to 10 MHz; an UNO's SPI tops out at 8 MHz.

At 100 kHz the frame takes 92.3 ms, about 11 frames a second. At 400 kHz, the SSD1306's I²C limit (400 kHz) (Solomon Systech), it takes 23.1 ms. The same module wired for SPI at 8 MHz needs 1.02 ms (Microchip). In the Arduino Wire library, Wire.setClock(400000) after Wire.begin() switches the bus to Fast-mode, once every chip on it allows it.

Choosing the pull-up resistors

The pull-up has a window. Too small, and a chip pulling the line low has to sink more current than it is rated for: the specification promises only 0.4 V at 3 mA, so Rp(min) = (VDD − 0.4 V) ÷ 3 mA. Too large, and the line rises too slowly: the time from 30 % to 70 % of VDD is 0.8473 × Rp × Cb, and it must stay under 1000 ns in Standard-mode and 300 ns in Fast-mode, so Rp(max) = tr ÷ (0.8473 × Cb) (NXP Semiconductors).

Worked example. Take 4 chips at the specification's worst-case 10 pF per pin, plus 60 pF for jumper wires and board traces: Cb = 100 pF. Then Rp(max) is 11.8 kΩ at 100 kHz, 3.54 kΩ at 400 kHz and 1.42 kΩ at 1 MHz. For Rp(min), use the supply at its +10 % high end, as the specification's own example does: 1.08 kΩ on a 3.3 V bus (3.63 V) and 1.70 kΩ on 5 V (5.5 V).

2k4k6k8k10k12k0100200300400bus capacitance Cb, pFRp, Ωmin at 5 V: 1.70 kΩmin at 3.3 V: 1.08 kΩStandard 100 kHzFast 400 kHz4.7 kΩ2.2 kΩ
Figure 6. The pull-up window. Any value between the dashed floor for your supply and the curve for your speed works. On a 100 pF bus, 4.7 kΩ misses Fast-mode; 2.2 kΩ fits both modes on 3.3 V and 5 V.

The usual 4.7 kΩ gives a rise time of 398 ns on that bus. Fine for 100 kHz, too slow for 400 kHz. It only meets Fast-mode up to 75 pF of bus capacitance. 2.2 kΩ rises in 186 ns and sinks 2.32 mA at 5.5 V, inside both limits.

30%70%VDDFast-mode limit 300 ns2.2 kΩ: 186 ns4.7 kΩ: 398 nstime after release, ns
Figure 7. The line rising after release on a 100 pF bus. 2.2 kΩ crosses 30 % to 70 % in 186 ns; 4.7 kΩ needs 398 ns, past the 300 ns Fast-mode limit.

Watch for pull-ups you didn't fit. Most breakout boards carry their own pair, often 4.7 kΩ, and every module you add puts another pair in parallel. On 3.3 V you can stack 4 such modules before the total drops under 1.08 kΩ; on 5 V only 2.

1 module4.70 kΩ2 modules2.35 kΩ3 modules1.57 kΩ (3.3 V only)4 modules1.18 kΩ (3.3 V only)5 modules0.94 kΩ (too low)total pull-up, kΩ
Figure 8. Total pull-up with 1 to 5 modules of 4.7 kΩ each in parallel. Red bars are below the 5 V floor of 1.70 kΩ; the last one is under the 3.3 V floor too.

Our take: for a breadboard or one small board at 400 kHz, fit 2.2 kΩ on each line if no module has its own. If two or more modules already carry pull-ups, measure SDA to VDD with the power off and add nothing unless the reading is above about 3.5 kΩ. On a long cable, drop to 100 kHz before you go below 1.7 kΩ.

Mixing 3.3 V and 5 V on one bus

Open-drain makes this easier than with push-pull pins, but not automatic. An UNO reads a high on its I²C pins only above 0.7 × VCC, which is 3.5 V at 5 V (Microchip). A 3.3 V sensor module with pull-ups to 3.3 V gives 0.2 V less than that. It often works on the bench and is not guaranteed. Pulling the bus to 5 V instead can damage a 3.3 V chip that is not 5 V tolerant.

3.3 V side5 V side3.3 V5 V2.2 kΩ2.2 kΩBSS138SDGSDA or SCLSDA or SCLeither side can pull the line low; both pull-ups lift it
Figure 9. The one-MOSFET bidirectional level shifter from Philips AN97055, one per line. Each side keeps its own pull-up to its own supply.

The fix is the level shifter in figure 9, which Philips published for exactly this bus (Philips Semiconductors). When the 3.3 V side pulls low, the MOSFET turns on and pulls the 5 V side down. When the 5 V side pulls low, current through the body diode drags the 3.3 V side down until the MOSFET switches on. Ready-made 4-channel boards carry two of these per bus. Our level shifter guide compares them with buffer chips and dividers.

I²C, SPI or UART

The ATmega328P on an UNO has all three in hardware, one of each, so the choice usually comes down to the part you are wiring.

I²CSPIUARTWiresSDA, SCL + GNDSCK, MOSI, MISO, CSTX, RX + GNDDevicesup to 112 addressesone CS pin eachtwo, point to pointClockshared, from controllershared, from controllernone, agreed baudSpeed100 / 400 kHzMHz range9600–115200 baudAcknowledgeevery bytenonenoneOutputsopen-drain + pull-upspush-pullpush-pullBest formany slow sensorsdisplays, SD, ADCsPC link, GPS, modules
Figure 10. The three common serial buses on a microcontroller board, side by side.

SPI uses four wires and a separate chip-select line for each device, but no addresses and no acknowledges, and its push-pull pins run at megahertz. Pick it for screens, SD cards and fast converters.

UART has no clock line at all. Both ends agree on a baud rate, and each byte travels as a start bit, eight data bits and a stop bit (10 bits). At 115,200 baud that is 11,520 bytes a second, about the same as I²C at 100 kHz. It links exactly two devices: a board and a PC, a GPS module, a Bluetooth module. The USB cable on an Arduino is a UART too: a USB-to-UART bridge chip (FT232R, CH340, CP2102 or the UNO R3's ATmega16U2) turns the PC's USB into TX and RX at logic level. USB-to-UART boards with an FT232 or CH340 are what you use to program bare chips and to read debug output.

I²C wins when many slow chips must share few pins: two wires for a dozen sensors, with an acknowledge telling you each one is there.

When the bus hangs or nothing answers

Sometimes a target is reset halfway through a read, still believes it is sending a 0, and holds SDA low. The controller then cannot send a START. The specification's cure is to send nine clock pulses: the stuck chip finishes its byte within those nine and lets go. If SCL itself is stuck low, only a reset or a power cycle of the targets clears it (NXP Semiconductors). Many I²C libraries do the nine-clock clear for you; on a bare microcontroller you toggle SCL as a plain pin.

The other common fault is a scanner sketch that finds nothing. Work down figure 11 with a multimeter before you suspect the code.

Line at 0 V when idle?yesSend 9 clocks or power-cyclenoLine floating, no pull-up?yesFit 2.2 kΩ pull-upsnoSDA and SCL swapped?yesSwap; A4 = SDA on UNOnoNo VCC or common GND?yesWire power and groundnoWrong address form?yesUse 7-bit; check A pins
Figure 11. Fault-finding order when an I²C scan finds no device. The first yes is usually the cause.

Tips and checks

  • Before wiring, measure each module's SDA-to-VCC resistance with the power off. It tells you whether it carries pull-ups and what value.
  • Run the bus at the speed of its slowest chip. One PCF8574 LCD backpack holds the whole bus to 100 kHz.
  • Two modules with the same fixed address cannot share a bus. Use the address pins, a second bus, or an I²C multiplexer chip.
  • Keep I²C on the board. Every extra length of cable adds capacitance toward the 400 pF limit; for a long run, slow the clock or fit a bus buffer chip.
  • A logic analyser that decodes I²C shows every address, byte and NACK on screen; the cheap 8-channel USB ones can do it.

Questions people ask

How many devices can I connect to one I²C bus?

Up to 112 addresses are free for ordinary chips, but capacitance runs out first. At the specification's 10 pF per pin and a little wiring, a breadboard bus stays well under the 400 pF limit with ten or so devices.

Do I always need pull-up resistors?

Yes, one per line for the whole bus. Many modules include them, so check before adding more. The microcontroller's internal pull-ups (20 to 50 kΩ on an UNO) are far too weak for reliable I²C.

What value pull-up should I use?

2.2 kΩ for a short bus at up to 400 kHz on 3.3 V or 5 V. 4.7 kΩ is fine at 100 kHz. Never go below 1.70 kΩ on 5 V or 1.08 kΩ on 3.3 V, counting the pull-ups already on your modules.

What is the difference between I²C and SPI?

I²C uses two wires and addresses, so many chips share them, at 100 kHz or 400 kHz. SPI uses four wires plus one select line per chip and runs at several megahertz, so it suits displays and memory cards.

Lessons behind the numbers

Sources and assumptions

Read on 17 October 2026. NXP's own link to UM10204 did not answer that day, so the link above is a copy of the same Rev. 7.0 file. Our own choices: supplies at +10 % for the minimum pull-up, a 100 pF example bus (4 pins at 10 pF plus 60 pF for wiring), 4.7 kΩ pull-ups on each breakout module, a 6-byte sensor read and 115,200 baud 8N1. Transfer times count clock periods only, without the short setup times around START and STOP. This page rebuilds an older ElectronicsInfoline article of the same title; none of its text is reused.

Advertisement