Skip to main content

i2c-scanner

ACK-probes every 7-bit address on an I²C bus and reports the ones that respond. Useful as a sanity check that buses are wired correctly and chips are populated.

Source: examples/i2c-scanner/.

board.yaml

som:
sku: E1M-AEN701

preset: e1m-evk

cores:
m55_hp:
app: ./src
peripherals: [i2c]

diagnostics:
log_level: info

Source (abbreviated)

#include <alp/peripheral.h>
#include <alp/e1m_pinout.h>
#include <zephyr/kernel.h>

int main(void) {
alp_i2c_t *bus = alp_i2c_open(&(alp_i2c_config_t){
.bus_id = ALP_E1M_I2C0,
.bitrate_hz = 100000u,
});
if (bus == NULL) {
printk("[i2c] open failed: err=%d\n", (int)alp_last_error());
return -1;
}

/* ACK-probe every 7-bit address 0x08..0x77: a zero-length write
drives just the address phase + STOP; ALP_OK means the device
ACKed its address, ALP_ERR_IO means NACK (nothing there). */
printk("[i2c] scanning...\n");
size_t count = 0;
for (uint8_t addr = 0x08; addr <= 0x77; addr++) {
if (alp_i2c_write(bus, addr, NULL, 0) == ALP_OK) {
printk(" 0x%02x\n", addr);
count++;
}
}

printk("[i2c] found %zu device(s)\n", count);
alp_i2c_close(bus);
return 0;
}

Expected output

On a populated E1M EVK:

[i2c] scanning...
0x30 // OPTIGA Trust M
0x40 // TMP112
0x50 // 24C128 EEPROM
0x52 // RV-3028-C7 RTC
0x68 // 5L35023B clock gen (V2N only)
[i2c] found 5 device(s)

Troubleshooting

SymptomCause / fix
open failed err=-ENOSUPPORTWrapper not implemented for this OS/SoM yet. Check the test plan.
Zero devices on a known-populated busCheck pull-up resistors; bridge / mux PWREN line.
Expected device missingACK-probe fails → chip is DNI on this BOM variant, or the rail powering it is down.

See also

Questions about this page? Discuss in Community Forum