linguini1 commented on issue #994:
URL: https://github.com/apache/nuttx-apps/issues/994#issuecomment-2231986178
I managed to get proper detection for all the sensors I have access to using
the following logic:
```c
int main(int argc, FAR char *argv[]) {
int err;
int i2c = open("/dev/i2c0", O_RDWR);
if (i2c < 0) {
fprintf(stderr, "Couldn't open /dev/i2c0: %d\n", errno);
return 1;
}
uint8_t contents = 0;
for (unsigned int i = 0; i < 128; i++) {
struct i2c_transfer_s i2c_transfer;
struct i2c_msg_s msg = {
.frequency = I2C_SPEED_FAST,
.addr = i,
.flags = 0,
.buffer = &contents,
.length = 0,
};
i2c_transfer.msgv = &msg;
i2c_transfer.msgc = 1;
err = ioctl(i2c, I2CIOC_TRANSFER, (unsigned long)(&i2c_transfer));
if (!err) {
printf("%02x\n", i);
}
}
return 0;
}
```
Because the message length is set to 0, I would expect that the I2C driver
is just sending the address header, but I will have to wait until I have access
to a logic analyzer to confirm.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]