I²C bring-up checklist
An ordered checklist for getting a new I²C sensor talking, from supply and pull-ups to the first verified read and bus recovery, with the limits from the NXP specification.
This page is for the moment a new I²C (Inter-Integrated Circuit) sensor or peripheral does not answer. Work down the list in order: each step rules out a class of fault before the next step depends on it. The bus limits come from NXP’s I²C-bus specification UM10204 Rev. 7.0. The driver behaviour is from ESP-IDF v6.1.1 and MicroPython. The worked example is the Sensirion SHT4x humidity sensor used in our projects.
1. Power and logic levels
- Measure the sensor’s supply pin with a meter, at the sensor, while the board runs. A breakout’s on-board regulator or a wrong jumper is a common surprise.
- Check that the sensor and the microcontroller share a ground.
- Check the thresholds. UM10204 defines the input LOW threshold (VIL) as at most 0.3 VDD and the input HIGH threshold (VIH) as at least 0.7 VDD. If the two sides run from different rails, check that a HIGH from one side reaches 0.7 VDD of the other, and that the pull-up voltage stays within the microcontroller’s absolute maximum input rating in its datasheet. If either check fails, use a level shifter.
- Give the sensor its datasheet start-up time before the first transaction.
2. Wiring and pull-ups
I²C lines are open-drain: devices only pull them LOW, and resistors pull them HIGH. With no pull-ups, nothing works.
- Confirm SDA (data) goes to SDA and SCL (clock) to SCL. Swapped lines are the most common wiring fault.
- Find every pull-up on the bus. Breakout boards often carry their own, and several boards in parallel lower the total resistance.
- Size the pull-up between two limits from UM10204 section 7.1:
| Limit | Formula | What sets it |
|---|---|---|
| Smallest resistor, Rp(min) | (VDD − VOL(max)) / IOL | The weakest device must still pull the line below VOL(max) while sinking the current through Rp. IOL is at least 3 mA at VOL = 0.4 V in Standard-mode and Fast-mode, 20 mA in Fast-mode Plus. |
| Largest resistor, Rp(max) | tr / (0.8473 × Cb) | The line must rise from 0.3 VDD to 0.7 VDD within the maximum rise time tr. The RC time between those thresholds is 0.8473 RC. Cb is the total capacitance of wires, connectors and pins. |
- Use the limits for your speed mode:
| Mode | Bit rate up to | Max rise time tr | Max bus capacitance Cb |
|---|---|---|---|
| Standard-mode (Sm) | 100 kbit/s | 1000 ns | 400 pF |
| Fast-mode (Fm) | 400 kbit/s | 300 ns | 400 pF |
| Fast-mode Plus (Fm+) | 1 Mbit/s | 120 ns | 550 pF |
Source: UM10204 Rev. 7.0, Tables 10 and 11. High-speed mode (3.4 Mbit/s) and Ultra Fast-mode (5 Mbit/s, one direction only) exist but are rare on sensors.
- Read the sensor’s own limits too. The SHT4x datasheet (v7.3, Table 4) allows up to 400 pF in fast mode only with a pull-up of 820 Ω or less, and 340 pF in fast mode plus with 390 Ω and VDD above 1.62 V.
- Do not rely on internal pull-ups. The ESP-IDF v6.1.1 guide says the chip’s internal pull-ups are not strong enough at high bus frequencies and recommends external ones. It suggests 1 kΩ to 10 kΩ, with 2 kΩ to 5 kΩ as a starting range, and never below 1 kΩ.
- For cables longer than 10 cm that carry the supply, UM10204 section 7.5 suggests the conductor order SDA, VDD, VSS (ground), SCL, or SDA, VSS, SCL. It limits crosstalk and keeps both lines at the same capacitance.
3. Address
- Take the 7-bit address from the datasheet, not from a library example. The SHT4x family uses 0x44, 0x45 or 0x46 depending on the order code.
- Watch for 8-bit notation. If a datasheet gives the address shifted left with the read/write bit included (0x88 for a device at 0x44), shift it right by one. ESP-IDF and MicroPython take the 7-bit value.
- Avoid the reserved ranges. UM10204 (section 3.1.12) reserves 0000 XXX and 1111 XXX, that is 0x00 to 0x07 and 0x78 to 0x7F, for the general call, START byte, high-speed controller codes, device ID and 10-bit addressing.
- Check for two devices with the same address on one bus. Use the address pins, a different order code or a multiplexer.
4. Scan the bus
A scan sends each address with the write bit and listens for an acknowledge (ACK). The controller drives the ninth clock pulse, and a present target pulls SDA LOW during it (UM10204 section 3.1.6).
| Tool | What to run | What it reports |
|---|---|---|
| ESP-IDF v6.1.1 | i2c_master_probe(bus, addr, timeout_ms) in a loop, or the i2c_tools example’s i2cdetect console command (ESP32-C5 is a listed target) |
ESP_OK on ACK, ESP_ERR_NOT_FOUND on NACK, ESP_ERR_TIMEOUT when the bus does not behave |
| MicroPython | i2c.scan() |
A list of addresses from 0x08 to 0x77 that pulled SDA LOW after the address and write bit |
- Treat
ESP_ERR_TIMEOUTdifferently from “not found”. ESP-IDF’s header fori2c_master_probesays a timeout is not an expected result and usually means the pull-ups are missing or wrong. Go back to step 2. - An empty scan with correct pull-ups usually means swapped lines, no power at the sensor, or a sensor held in reset.
- A device at every address usually means SDA is stuck LOW. Go to step 8.
- Some devices do not answer a bare address. ESP-IDF’s documentation notes that not every device supports address-only probing. Check the datasheet before you conclude the part is dead.
5. First read with a known answer
A scan proves the device acknowledges. It does not prove you can read data. Pick a transaction whose answer you can check: an ID or “who am I” register, a fixed reset value from the datasheet’s register map, or a serial number with a checksum.
- For a register-mapped part: write the register address, then read with a repeated START, and compare the byte with the datasheet’s fixed ID value.
- For the SHT4x, which uses commands instead of registers: send command 0x89 (read serial number), then read 6 bytes. They are two 16-bit words, each followed by a CRC-8 byte.
- Check the CRC rather than eyeballing the bytes. The SHT4x CRC-8 uses polynomial 0x31, initial value 0xFF, no reflection and no final XOR. The datasheet’s test vector is CRC(0xBEEF) = 0x92, so test your CRC function against it first.
- Allow for busy periods. The SHT4x does not stretch the clock. It answers NACK to a read header while it is still measuring or heating, so wait for the datasheet’s measurement time before reading.
6. Speed and timing
- Start at 100 kHz. Raise the clock only after reads are reliable.
- Respect the controller’s ceiling. ESP-IDF v6.1.1 documents Standard-mode and Fast-mode for the ESP32-C5 and says the master SCL should not exceed 400 kHz.
- Expect a lower real clock than requested. MicroPython’s documentation says hardware I²C may run slower than the requested frequency. Slow rising edges from large pull-ups also stretch each bit.
- Clock stretching is optional in UM10204 (section 3.1.9), and most targets cannot do it. If a device does stretch, set the ESP-IDF per-device timeout
scl_wait_ushigh enough. The ESP-IDF guide notes that stretching can last 12 ms, and 0 keeps the register default. - If the bus is over the capacitance limit, UM10204 section 7.2 lists four ways out: a lower SCL frequency, higher-drive Fast-mode Plus parts, bus buffers or multiplexers that split the bus into segments, or a switched pull-up.
7. Look at the wires
When software checks run out, measure.
- Logic analyser: decode one transaction. Confirm the address byte, the ACK on the ninth clock and the data. A NACK on the address means wrong address or no device. A NACK later means the device rejected the command or was busy.
- Oscilloscope on SDA and SCL: measure the rise time between 30 % and 70 % of VDD and compare it with the table in step 2. Rounded “shark fin” edges mean too much pull-up resistance or too much capacitance.
- Check the LOW level. If it sits above 0.3 VDD, the pull-up is too strong for the weakest driver.
- Look for ringing or crosstalk on long cables. Shorten the cable or slow the bus before adding parts.
8. Bus recovery
A target that was reset mid-transfer, or a brown-out, can leave SDA held LOW. UM10204 section 3.1.16 gives the procedure:
- If SDA is stuck LOW, the controller sends up to nine clock pulses. The target that holds SDA should release it within those nine clocks.
- If SCL is stuck LOW, or nine clocks do not free SDA, use the device’s hardware reset input, or cycle its power so its power-on reset runs.
- In ESP-IDF v6.1.1,
i2c_master_bus_reset(bus_handle)resets the master bus. Call it after a timeout, then probe again. - In a product, give I²C sensors a switchable supply or a reset line so firmware can recover without a full reboot.
For makers
Check pull-ups first, at 100 kHz, with one sensor on the bus. Most “dead” sensors are wiring or pull-up faults. Run a scan, then one read you can verify, and only then add the next device.
For product teams
Budget bus capacitance on the schematic from pin and connector capacitances, choose Rp between Rp(min) and Rp(max) for the worst-case supply, and log ESP_ERR_TIMEOUT separately from NACKs in field telemetry. Add a recovery path (nine-clock bus clear, sensor power switch) and test it by resetting the sensor mid-transfer on the bench.
Related pages
- Sensors and actuators for choosing sensors.
- Hardware design for IoT for schematic and layout practice.
- ESP-IDF cheat sheet for building and flashing the
i2c_toolsexample.