I am trying to set the charge current (ICHG) to 100mA or 200mA using nPM1300 on nRF52832 via TWI (I2C). However, the measured current is always limited to ~87mA, even when ICHG is set higher.
This is the code i am using :
bool npm1300_set_charge_current(const nrf_drv_twi_t *twi, uint16_t current_ma)
{
if (!twi) {
return false;
}
// Validate range: 32 mA to 800 mA, in 2 mA steps
if (current_ma < 32 || current_ma > 800 || (current_ma % 2) != 0) {
NRF_LOG_ERROR("Invalid charge current: %dmA (must be 32-800mA, 2mA steps)", current_ma);
return false;
}
// 9-bit code = ICHG / 2
uint16_t code = current_ma / 2;
uint8_t msb = (code >> 1) & 0xFF; // bits [8:1]
uint8_t lsb = code & 0x01; // bit [0]
// Charger must be disabled before updating registers
if (!npm1300_write_reg(twi, BCHG_ENABLECLR, 1)) {
NRF_LOG_ERROR("Failed to disable charger before setting current");
return false;
}
if (!npm1300_write_reg(twi, BCHG_ISETMSB, msb)) {
return false;
}
if (!npm1300_write_reg(twi, BCHG_ISETLSB, lsb)) {
return false;
}
// Re-enable charger so new current takes effect
if (!npm1300_write_reg(twi, BCHG_ENABLESET, 1)) {
NRF_LOG_ERROR("Failed to re-enable charger after setting current");
return false;
}
NRF_LOG_INFO("Charge current set to %dmA (CODE=%u, MSB=0x%02X, LSB=0x%02X)",
current_ma, code, msb, lsb);
return true;
}
bool npm1300_set_charge_voltage(const nrf_drv_twi_t *twi, uint16_t voltage_mv)
{
if (!twi) {
return false;
}
// Charge voltage range: 3.5V to 4.45V in 50mV steps per datasheet
if (voltage_mv < 3500 || voltage_mv > 4450 || ((voltage_mv - 3500) % 50) != 0) {
NRF_LOG_ERROR("Invalid charge voltage: %dmV (must be 3500-4450mV, 50mV steps)", voltage_mv);
return false;
}
uint8_t vterm_code = (voltage_mv - 3500) / 50;
if (!npm1300_write_reg(twi, BCHG_VTERM, vterm_code)) {
return false;
}
NRF_LOG_INFO("Charge voltage set to %dmV (code=0x%02X)", voltage_mv, vterm_code);
return true;
}
Steps performed:
1. Initialize nPM1300 and clear flags.
2. Disable charger.
3. Set charge voltage to 4.1V.
4. Set charge current to 200 mA (ISET_CODE: 84).
5. Enable charger.
Observations:
- Without battery connected: Charger reports `Battery detected: NO`, `Charging active: NO`.
- With battery connected: Charger reports `Battery detected: YES`, `Charging active: YES`, `CC mode: YES`, but current does not exceed ~87 mA.
- Logs show correct ISET_CODE and charge voltage settings.
I am also using BUCK1 and BUCK2, are there any specific steps to follow when setting the charge current or voltage.
Help me to resolve this issue.
Thank you!