Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add I2C retries in INA226 to prevent publishing 0's on a single read … #19423

Merged
merged 1 commit into from
Apr 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/drivers/power_monitor/ina226/ina226.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ int INA226::read(uint8_t address, int16_t &data)
{
// read desired little-endian value via I2C
uint16_t received_bytes;
const int ret = transfer(&address, 1, (uint8_t *)&received_bytes, sizeof(received_bytes));
int ret = PX4_ERROR;

if (ret == PX4_OK) {
data = swap16(received_bytes);
for (size_t i = 0; i < 3; i++) {
ret = transfer(&address, 1, (uint8_t *)&received_bytes, sizeof(received_bytes));

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

} else {
perf_count(_comms_errors);
PX4_DEBUG("i2c::transfer returned %d", ret);
}
}

return ret;
Expand Down