Arduino IDE version (found in Arduino -> About Arduino menu): Usin Platform IO with Arduino 1.813
The problem lies in the functions getShuntVoltage_raw() and getCurrent_raw() both of which return an unsigned integer from the BusIO_Register read() function. and return this value from a function intended to return a signed integer but do not deal with the flags CNVR and OVF so give some very odd readings when used bidirectionally as I am doing monitoring the current flowing from and into the battery in a circuit that includes a charging circuit as well as using the device away from the charger.
The function getBusVoltage_raw() does not have this problem as the return value there is
// Shift to the right 3 to drop CNVR and OVF and multiply by LSB
return (int16_t)((value >> 3) * 4);
This works correctly and if used in the other two functions provides correct values for current flow in either direction.
Arduino board: Custom ESP32 board
Arduino IDE version (found in Arduino -> About Arduino menu): Usin Platform IO with Arduino 1.813
The problem lies in the functions getShuntVoltage_raw() and getCurrent_raw() both of which return an unsigned integer from the BusIO_Register read() function. and return this value from a function intended to return a signed integer but do not deal with the flags CNVR and OVF so give some very odd readings when used bidirectionally as I am doing monitoring the current flowing from and into the battery in a circuit that includes a charging circuit as well as using the device away from the charger.
The function getBusVoltage_raw() does not have this problem as the return value there is
// Shift to the right 3 to drop CNVR and OVF and multiply by LSB return (int16_t)((value >> 3) * 4);
This works correctly and if used in the other two functions provides correct values for current flow in either direction.