diff --git a/src/systemcmds/i2c/i2c.c b/src/systemcmds/i2c/i2c.c index 2991456cf1..1fa60a7e47 100644 --- a/src/systemcmds/i2c/i2c.c +++ b/src/systemcmds/i2c/i2c.c @@ -75,21 +75,25 @@ int i2c_main(int argc, char *argv[]) /* find the right I2C */ i2c = up_i2cinitialize(PX4_I2C_BUS_ONBOARD); - if (i2c == NULL) + if (i2c == NULL) { errx(1, "failed to locate I2C bus"); + } usleep(100000); uint8_t buf[] = { 0, 4}; int ret = transfer(PX4_I2C_OBDEV_PX4IO, buf, sizeof(buf), NULL, 0); - if (ret) + if (ret) { errx(1, "send failed - %d", ret); + } uint32_t val; ret = transfer(PX4_I2C_OBDEV_PX4IO, NULL, 0, (uint8_t *)&val, sizeof(val)); - if (ret) + + if (ret) { errx(1, "recive failed - %d", ret); + } errx(0, "got 0x%08x", val); } @@ -121,8 +125,9 @@ transfer(uint8_t address, uint8_t *send, unsigned send_len, uint8_t *recv, unsig msgs++; } - if (msgs == 0) + if (msgs == 0) { return -1; + } /* * I2C architecture means there is an unavoidable race here @@ -133,8 +138,9 @@ transfer(uint8_t address, uint8_t *send, unsigned send_len, uint8_t *recv, unsig ret = I2C_TRANSFER(i2c, &msgv[0], msgs); // reset the I2C bus to unwedge on error - if (ret != OK) + if (ret != OK) { up_i2creset(i2c); + } return ret; }