Skip to content

Commit 32f34d7

Browse files
committed
making a test by scanning i2c addresses
1 parent 61444dc commit 32f34d7

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Diff for: app/module/drivers/sensor/pinnacle/pinnacle.c

+19-3
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,26 @@ static int pinnacle_write(const struct device *dev, const uint8_t addr, const ui
7979
return ret;
8080
#elif DT_INST_ON_BUS(0, i2c)
8181
const struct i2c_dt_spec *spec = &config->bus;
82-
LOG_WRN("i2c addr: %02x", spec->addr);
83-
LOG_WRN("reg addr: %02x", PINNACLE_WRITE | addr);
84-
LOG_WRN("device addr: %02x", spec->addr << 1);
8582

83+
uint8_t nDevices = 0;
84+
LOG_WRN("Scanning...");
85+
86+
for (uint8_t address = 1; address < 127; address++) {
87+
int ret;
88+
ret = i2c_reg_write_byte(spec->bus, address << 1, PINNACLE_WRITE | addr, val);
89+
if (ret < 0) {
90+
// LOG_WRN("Nothing found at 0x%02X\n", address);
91+
} else {
92+
LOG_WRN("I2C device found at address 0x%02X\n", address);
93+
nDevices++;
94+
}
95+
k_msleep(2);
96+
}
97+
98+
if (nDevices == 0)
99+
LOG_WRN("No I2C devices found\n");
100+
else
101+
LOG_WRN("done\n");
86102
return i2c_reg_write_byte(spec->bus, spec->addr << 1, PINNACLE_WRITE | addr, val);
87103

88104
// return i2c_reg_write_byte_dt(&config->bus, PINNACLE_WRITE | addr, val);

0 commit comments

Comments
 (0)