Skip to content
Tactiverge

School/○ Innovator/Elective · ECE-310

I²C: decoding a bus conversation

Twenty sensors share the same two wires, and none of them talk over each other. Who decides who speaks, and how does a sensor say “got it”?

About 40 min · 3 goals · Checked by automated tests

Review status: Technically checked (automated tests)Content file last checked 2026-11-29.How independent review works

1.Why should I care?

Temperature sensors, IMUs, real-time clocks and small displays almost all speak I²C, because it needs only two wires for a whole bus of devices. When a sensor “isn't found”, the answer is in the capture: the address byte, and whether anyone pulled SDA low to acknowledge it. Reading a bus capture bit by bit is the core skill of embedded debugging.

  • ◇ Explain why I²C uses open-drain lines with pull-up resistors.
  • ◇ Build the address byte from a 7-bit address and the R/W bit, and read ACK and NACK.
  • ◇ Decode a captured register-read transaction byte by byte and estimate how long it takes.

2.Predict

A datasheet says a sensor's I²C address is 0x48. A logic analyser shows the first byte after START is 0x90. What has gone wrong?

Guess first. Being wrong here is how the surprise works.

3.Discover

Leave the address at 0x48 and step through the register read one byte at a time. Watch the 9th bit of each byte: who drives it, and why is the very last one different?

Loading the interactive…

Can't use the interactive? Read a description instead

The I²C diagram lists a register read from address 0x48, register 0x00, with sample data 0x1A and 0xC3: byte 1 address+W 0x90 ACK by target; byte 2 register 0x00 ACK by target; byte 3 address+R 0x91 ACK by target; byte 4 data 0x1A ACK by controller; byte 5 data 0xC3 NACK by controller, then STOP. Each step shows the 8 SDA bits most significant first and the 9th acknowledge bit. The readout totals 45 clocks: 450 µs at 100 kHz and 112.5 µs at 400 kHz.

4.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1 · a fresh version every time

A controller starts an I²C read from the device with 7-bit address 0x4E. The first byte on SDA is the address followed by the R/W bit (1 = read, 0 = write). What is that byte's value, in decimal?

Practice 2

During the acknowledge clock, what does the receiving device do to say ACK?

5.Watch

→ Watch for the START and STOP conditions (SDA changing while SCL is high) and the acknowledge bit after every byte.

An instrument maker's clear explanation of I2C addressing, acknowledges and timing.

10 min 57 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

The video is optional: everything you need is also in the lesson text and the interactive.

6.Understand

Two wires, pulled up

I²C has SCL (clock, driven by the controller) and SDA (data). Devices never drive a line high: they can only pull it low or let go (open drain). Pull-up resistors bring released lines back high. So two devices can never fight, one pushing high and one low; at worst both pull low. It also means a 0 is a definite act, which is why the acknowledge is a 0.

Start, address, acknowledge

A transaction begins with START: SDA falls while SCL is high (data normally changes only while SCL is low). Then the controller sends the address byte: 7 address bits, MSB first, plus R/W (0 = write, 1 = read). On the 9th clock it releases SDA; the device with that address pulls it low: ACK. If nobody does, SDA stays high: NACK, meaning no such device (or it is busy).

Reading a register

Most sensors keep values in numbered registers. A register read is: START, address+W, register index (target ACKs both), repeated START, address+R, then the target sends data bytes. Now the controller acknowledges: ACK means “send another”, and a NACK on the last byte means “that's enough”, followed by STOP (SDA rises while SCL is high).

Counting the time

Every byte costs 9 clocks: 8 data bits and the acknowledge. Reading 2 data bytes from a register is 5 bytes on the bus, so 45 clocks: 450 µs at standard mode (100 kHz) or 112.5 µs at fast mode (400 kHz), before counting the START, repeated START and STOP. The addressing overhead is why I²C suits small, occasional reads rather than streaming video.

Explain it another way

It is a classroom with one teacher. The teacher calls a name (the address); only that pupil answers “here” (ACK). The teacher then asks a question (the register) and listens to the answer, nodding after each word until saying “thank you, that's all” (NACK and STOP).

Derivation: How long a register read takes
  1. List the bytes: address+W, register index, address+R (after the repeated START), then n data bytes: 3 + n bytes.

  2. Each byte is 8 data clocks plus 1 acknowledge clock: 9 clocks per byte, so 9(3 + n) clocks.

  3. One clock lasts 1/f. At 100 kHz that is 10 µs; at 400 kHz, 2.5 µs.

  4. Time ≈ 9(3 + n)/f. For n = 2: 45 clocks → 450 µs at 100 kHz, 112.5 µs at 400 kHz (START/STOP conditions add a little more).

Worked example 1

A capture shows the first byte after START as SDA bits 1 1 0 1 0 0 0 1 (MSB first), then SDA low on the 9th clock. Decode it.

11010001 = 0xD1. The top 7 bits 1101000 = 0x68 are the address; the last bit 1 means read. SDA low on clock 9 is an ACK: a device at 0x68 is present and ready to send.

Worked example 2

After sending address 0x3C+W, SDA stays high on the 9th clock. What does it mean and what would you check?

NACK: no device acknowledged 0x3C. Check the address in the datasheet (some quote the 8-bit form 0x78), the wiring and the pull-up resistors, and that the device is powered.

Common mix-ups

  • The address byte on the wire is the 7-bit address itself.
    ✓ It is the address shifted left with R/W in the lowest bit, so 0x48 appears as 0x90 (write) or 0x91 (read).
  • I²C devices drive the data line high and low like any output.
    ✓ They only pull low or let go; pull-up resistors make the highs. That is what makes sharing the bus safe.
  • A NACK always means an error.
    ✓ A NACK after the address usually means no device; a NACK on the last byte of a read is the normal way to finish.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 3

What is the address byte, in decimal, for writing to an I²C device at 7-bit address 0x68?

Practice 4

In a multi-byte read, the controller answers the final data byte with a NACK. Why?

Practice 5

A register read of 2 data bytes is 5 bytes on the bus at 9 clocks each. How long does it take at 400 kHz, in microseconds, ignoring START and STOP?

µs

Practice 6 · a fresh version every time

A controller reads 4 data bytes from a sensor register over I²C at 400 kHz: address byte (write), register index, repeated start, address byte (read), then the data. Count 9 clock cycles per byte (8 bits + ACK) and ignore the start, stop and repeated-start conditions. How long does the transaction take, in microseconds? (1 decimal place)

µs

8.Apply it

Your robot reads a temperature sensor (2 data bytes) and an IMU (14 data bytes) on the same 400 kHz bus, each 200 times a second. Using 9 clocks per byte and the register-read pattern, what fraction of the bus time is used? Would 100 kHz still work?

9.Reflect

Concepts: Serial communication: UART, I2C and SPI