File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
libraries/Nicla_System/src Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -284,13 +284,23 @@ int8_t nicla::getBatteryVoltagePercentage(bool useLatchedValue) {
284
284
uint8_t faults = _pmic.getFaultsRegister ();
285
285
if (faults & BAT_UVLO_FAULT) return -1 ; // Battery is not connected or voltage is too low
286
286
287
- // Write 1 to VBMON_READ to trigger a new reading
288
- // TODO: Disable charging while reading battery percentage. SEE chapter 9.3.4
289
287
290
288
if (!useLatchedValue){
289
+ // Disable charging while reading battery percentage. SEE chapter 9.3.4
290
+ bool chargingEnabled = (_fastChargeRegisterData & 0b10 ) == 0 ; // Bit 1 is 0 if charging is enabled.
291
+
292
+ if (chargingEnabled) {
293
+ disableCharging ();
294
+ }
291
295
// Write 1 to VBMON_READ to trigger a new reading
292
296
_pmic.writeByte (BQ25120A_ADDRESS, BQ25120A_BATT_MON, 1 );
293
297
delay (3 ); // According to datasheet, 2ms is enough, but we add 1ms for safety
298
+
299
+ if (chargingEnabled) {
300
+ // Re-enable charging by setting bit 1 to 0
301
+ _fastChargeRegisterData &= 0b11111101 ;
302
+ _pmic.writeByte (BQ25120A_ADDRESS, BQ25120A_FAST_CHG, _fastChargeRegisterData);
303
+ }
294
304
}
295
305
uint8_t data = _pmic.readByte (BQ25120A_ADDRESS, BQ25120A_BATT_MON);
296
306
You can’t perform that action at this time.
0 commit comments