mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-07 03:31:36 +08:00
Add I2C retries in INA226 to prevent publishing 0's on a single read failure
This commit is contained in:
@@ -102,14 +102,19 @@ int INA226::read(uint8_t address, int16_t &data)
|
|||||||
{
|
{
|
||||||
// read desired little-endian value via I2C
|
// read desired little-endian value via I2C
|
||||||
uint16_t received_bytes;
|
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) {
|
for (size_t i = 0; i < 3; i++) {
|
||||||
data = swap16(received_bytes);
|
ret = transfer(&address, 1, (uint8_t *)&received_bytes, sizeof(received_bytes));
|
||||||
|
|
||||||
} else {
|
if (ret == PX4_OK) {
|
||||||
perf_count(_comms_errors);
|
data = swap16(received_bytes);
|
||||||
PX4_DEBUG("i2c::transfer returned %d", ret);
|
break;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
perf_count(_comms_errors);
|
||||||
|
PX4_DEBUG("i2c::transfer returned %d", ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user