Skip to content

Commit a9d58e8

Browse files
pabigotnashif
authored andcommitted
samples: i2c_scanner: provide more complete output
Update the sample to indicate which device it was using, which helps mitigate the existing problems identifyin Arduino I2C buses. Also output a summary of results so cases where no devices are found provide output after the Starting... line. Signed-off-by: Peter Bigot <[email protected]>
1 parent e5af53a commit a9d58e8

File tree

1 file changed

+5
-1
lines changed
  • samples/drivers/i2c_scanner/src

1 file changed

+5
-1
lines changed

samples/drivers/i2c_scanner/src/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
void main(void)
2424
{
2525
struct device *i2c_dev;
26+
u8_t cnt = 0;
2627

2728
printk("Starting i2c scanner...\n");
2829

2930
i2c_dev = device_get_binding(I2C_DEV);
3031
if (!i2c_dev) {
31-
printk("I2C: Device driver not found.\n");
32+
printk("I2C: Device driver %s not found.\n", I2C_DEV);
3233
return;
3334
}
3435

@@ -43,6 +44,9 @@ void main(void)
4344

4445
if (i2c_transfer(i2c_dev, &msgs[0], 1, i) == 0) {
4546
printk("0x%2x FOUND\n", i);
47+
++cnt;
4648
}
4749
}
50+
printk("%u devices found on %s\n", cnt, I2C_DEV);
51+
4852
}

0 commit comments

Comments
 (0)