Skip to content

Commit

Permalink
ina238: use I2C resets
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKlimaj committed Jan 22, 2025
1 parent 15b94a3 commit 4a81e65
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/drivers/power_monitor/ina238/ina238.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,13 @@ int INA238::read(uint8_t address, uint16_t &data)
uint16_t received_bytes;
int ret = PX4_ERROR;

for (size_t i = 0; i < 6; i++) {
ret = transfer(&address, 1, (uint8_t *)&received_bytes, sizeof(received_bytes));
ret = transfer(&address, 1, (uint8_t *)&received_bytes, sizeof(received_bytes));

if (ret == PX4_OK) {
data = swap16(received_bytes);
break;

} else {
perf_count(_comms_errors);
PX4_DEBUG("i2c::transfer returned %d", ret);
}
if (ret == PX4_OK) {
data = swap16(received_bytes);
} else {
perf_count(_comms_errors);
PX4_DEBUG("i2c::transfer returned %d", ret);
}

return ret;
Expand Down Expand Up @@ -165,6 +161,8 @@ int INA238::Reset()

int ret = PX4_ERROR;

_retries = 6;

if (RegisterWrite(Register::CONFIG, (uint16_t)(ADC_RESET_BIT)) != PX4_OK) {
return ret;
}
Expand Down

0 comments on commit 4a81e65

Please sign in to comment.