diff options
Diffstat (limited to 'commandline/i2cget.c')
-rw-r--r-- | commandline/i2cget.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/commandline/i2cget.c b/commandline/i2cget.c index 041ffad..c7cd18f 100644 --- a/commandline/i2cget.c +++ b/commandline/i2cget.c @@ -6,7 +6,7 @@ int main(int argc, char **argv) { - int i, address, cmdbuf, got_ack; + int i, address, cmdbuf; unsigned int ret; char *conv_err; @@ -22,23 +22,32 @@ int main(int argc, char **argv) address = strtol(argv[1], &conv_err, 0); if (conv_err && *conv_err) { - fprintf(stderr, "address: Conversion error at '%s'", conv_err); + fprintf(stderr, "address: Conversion error at '%s'\n", conv_err); return 2; } - i2c_tx_byte((address << 1) | 0); + if (!i2c_tx_byte((address << 1) | 0)) { + fprintf(stderr, "Received NAK from slave 0x%02x, aborting\n", address); + return 3; + } for (i = 2; i < argc; i++) { cmdbuf = strtol(argv[i], &conv_err, 0); if (conv_err && *conv_err) { - fprintf(stderr, "read command: Conversion error at '%s'", conv_err); + fprintf(stderr, "read command: Conversion error at '%s'\n", conv_err); return 2; } - i2c_tx_byte(cmdbuf); + if (!i2c_tx_byte(cmdbuf)) { + fprintf(stderr, "Received NAK after byte %d (0x%02x)\n", i-1, cmdbuf); + return 4; + } } i2c_start(); - got_ack = i2c_tx_byte((address << 1) | 1); + if (!i2c_tx_byte((address << 1) | 1)) { + fprintf(stderr, "Received NAK after reSTART from slave 0x%02x, aborting\n", address); + return 3; + } ret = i2c_rx_byte(0); @@ -47,5 +56,5 @@ int main(int argc, char **argv) printf("%i\n", ret); - return got_ack ? 0 : 1; + return 0; } |