Skip to content

Commit

Permalink
making a test by scanning i2c addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
FearlessSpiff committed Nov 6, 2023
1 parent 61444dc commit 32f34d7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/module/drivers/sensor/pinnacle/pinnacle.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,26 @@ static int pinnacle_write(const struct device *dev, const uint8_t addr, const ui
return ret;
#elif DT_INST_ON_BUS(0, i2c)
const struct i2c_dt_spec *spec = &config->bus;
LOG_WRN("i2c addr: %02x", spec->addr);
LOG_WRN("reg addr: %02x", PINNACLE_WRITE | addr);
LOG_WRN("device addr: %02x", spec->addr << 1);

uint8_t nDevices = 0;
LOG_WRN("Scanning...");

for (uint8_t address = 1; address < 127; address++) {
int ret;
ret = i2c_reg_write_byte(spec->bus, address << 1, PINNACLE_WRITE | addr, val);
if (ret < 0) {
// LOG_WRN("Nothing found at 0x%02X\n", address);
} else {
LOG_WRN("I2C device found at address 0x%02X\n", address);
nDevices++;
}
k_msleep(2);
}

if (nDevices == 0)
LOG_WRN("No I2C devices found\n");
else
LOG_WRN("done\n");
return i2c_reg_write_byte(spec->bus, spec->addr << 1, PINNACLE_WRITE | addr, val);

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

0 comments on commit 32f34d7

Please sign in to comment.