mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-22 01:30:35 +08:00
ina228: fix sign error on CURRENT reading (#19296)
This commit is contained in:
@@ -124,7 +124,12 @@ int INA228::read(uint8_t address, int32_t &data)
|
|||||||
const int ret = transfer(&address, 1, (uint8_t *)&received_bytes, sizeof(received_bytes) - 1);
|
const int ret = transfer(&address, 1, (uint8_t *)&received_bytes, sizeof(received_bytes) - 1);
|
||||||
|
|
||||||
if (ret == PX4_OK) {
|
if (ret == PX4_OK) {
|
||||||
data = swap32(received_bytes) >> ((32 - 24) + 4);
|
data = swap32(received_bytes) >> ((32 - 24) + 4); // Convert to 20bit value
|
||||||
|
|
||||||
|
// Handle negative 20bit twos complement
|
||||||
|
if (data & 0x80000) {
|
||||||
|
data = -((0x000FFFFF & ~data) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
perf_count(_comms_errors);
|
perf_count(_comms_errors);
|
||||||
|
|||||||
Reference in New Issue
Block a user