Skip to content

Commit fc7b392

Browse files
committed
Nicla: tune PMIC charger
1 parent c53aded commit fc7b392

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: libraries/Nicla_System/src/Nicla_System.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,35 @@ uint8_t nicla::readLDOreg()
106106

107107
bool nicla::enableCharge(uint8_t mA)
108108
{
109-
digitalWrite(p25, LOW);
110109
if (mA < 35) {
111110
_chg_reg = ((mA-5) << 2);
112111
} else {
113112
_chg_reg = (((mA-40)/10) << 2) | 0x80;
114113
}
115114
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG, _chg_reg);
115+
116+
// For very depleted batteries, set ULVO at the vary minimum to re-enable charging
117+
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_ILIM_UVLO_CTRL, 0x3F);
118+
119+
// also set max battery voltage to 4.2V (VBREG)
120+
// _pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_BATTERY_CTRL, (4.2f - 3.6f)*100);
121+
116122
return _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG) == _chg_reg;
117123
}
118124

125+
uint8_t nicla::getFault() {
126+
return _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAULTS);
127+
}
128+
129+
130+
float nicla::getBetteryStatus() {
131+
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_BATT_MON, 1);
132+
delay(2);
133+
uint8_t data = _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_BATT_MON);
134+
float res = 0.6f + (data >> 5) * 0.1f + (data >> 2) * 0.02f - 0.01f;
135+
return res;
136+
}
137+
119138
void nicla::checkChgReg()
120139
{
121140
if (_chg_reg != _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG)) {

Diff for: libraries/Nicla_System/src/Nicla_System.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class nicla {
2020
static bool enterShipMode();
2121
static uint8_t readLDOreg();
2222
static bool enableCharge(uint8_t mA = 20);
23+
static float getBetteryStatus();
24+
static uint8_t getFault();
2325

2426
static RGBled leds;
2527
static BQ25120A _pmic;

0 commit comments

Comments
 (0)