This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BQ21061: BQ21061's value of status registers and flag registers

Part Number: BQ21061


Tool/software:

Hello,

Now I'm trying to watch battery charge status using the charge IC BQ21061.
I got the each registers' value via I2C by a MCU.
I felt strange that Charge CV state and PGOOD state was set in the STAT0 register but Charge CV flag in the FLAG0 register was not set.
I expected both status register set/clear and flag register set/clear coincide with charge events but reality was not.
By what conditions flag registers reflected by real charge status?
Just for reference I'll post my source code watches BQ21061's registers.

Thanks

void get_State_Reg_BQ21061()
{
#define BQ21061_SLAVE_ADDRESS 0xD6U
I2C_HandleTypeDef hi2c1;
int16_t i, rec_val, ret = 0;
uint8_t received_reg_val[7];
uint8_t buf[4];
for(i = 0; i < 7; i++)
{
received_reg_val[i] = HAL_I2C_Mem_Read(&hi2c1, BQ21061_SLAVE_ADDRESS, i, I2C_MEMADD_SIZE_8BIT, buf, 1, 1000);
}
// STAT0
uint8_t chrg_cv_stat = (received_reg_val[0] & CHRG_CV_STAT_MASK) >> CHRG_CV_STAT_SHIFT;
uint8_t charg_done_stat = (received_reg_val[0] & CHARGE_DONE_STAT_MASK) >> CHARGE_DONE_STAT_SHIFT;
uint8_t iinlim_active_stat = (received_reg_val[0] & IINLIM_ACTIVE_STAT_MASK) >> IINLIM_ACTIVE_STAT_SHIFT;
uint8_t vdppm_active_stat = (received_reg_val[0] & VDPPM_ACTIVE_STAT_MASK) >> VDPPM_ACTIVE_STAT_SHIFT;
uint8_t vindpm_active_stat = (received_reg_val[0] & VINDPM_ACTIVE_STAT_MASK) >> VINDPM_ACTIVE_STAT_SHIFT;
uint8_t thermreg_active_stat = (received_reg_val[0] & THERMREG_ACTIVE_STAT_MASK) >> THERMREG_ACTIVE_STAT_SHIFT;
uint8_t vin_pgood_stat = (received_reg_val[0] & VIN_PGOOD_STAT_MASK);
// STAT1
uint8_t vin_ovp_fault_stat = (received_reg_val[1] & VIN_OVP_FAULT_STAT_MASK) >> VIN_OVP_FAULT_STAT_SHIFT;
uint8_t bat_ocp_fault_stat = (received_reg_val[1] & BAT_OCP_FAULT_STAT_MASK) >> BAT_OCP_FAULT_STAT_SHIFT;
uint8_t bat_uvlo_fault_stat = (received_reg_val[1] & BAT_UVLO_FAULT_STAT_MASK) >> BAT_UVLO_FAULT_STAT_SHIFT;
uint8_t ts_cold_stat = (received_reg_val[1] & TS_COLD_STAT_MASK) >> TS_COLD_STAT_SHIFT;
uint8_t ts_cool_stat = (received_reg_val[1] & TS_COOL_STAT_MASK) >> TS_COOL_STAT_SHIFT;
uint8_t ts_warm_stat = (received_reg_val[1] & TS_WARM_STAT_MASK) >> TS_WARM_STAT_SHIFT;
uint8_t ts_hot_stat = (received_reg_val[1] & TS_HOT_STAT_MASK);
// STAT2
uint8_t ts_open_stat = (received_reg_val[2] & TS_OPEN_STAT_MASK);
// FLAG0
uint8_t chrg_cv_flag = (received_reg_val[3] & CHRG_CV_FLAG_MASK) >> CHRG_CV_FLAG_SHIFT;
uint8_t charge_done_flag = (received_reg_val[3] & CHARGE_DONE_FLAG_MASK) >> CHARGE_DONE_FLAG_SHIFT;
uint8_t iinlim_active_flag = (received_reg_val[3] & IINLIM_ACTIVE_FLAG_MASK) >> IINLIM_ACTIVE_FLAG_SHIFT;
uint8_t vdppm_active_flag = (received_reg_val[3] & VDPPM_ACTIVE_FLAG_MASK) >> VDPPM_ACTIVE_FLAG_SHIFT;
uint8_t vindpm_active_flag = (received_reg_val[3] & VINDPM_ACTIVE_FLAG_MASK) >> VINDPM_ACTIVE_FLAG_SHIFT;
uint8_t thermreg_active_flag = (received_reg_val[3] & THERMREG_ACTIVE_FLAG_MASK) >> THERMREG_ACTIVE_FLAG_SHIFT;
uint8_t vin_pgood_flag = (received_reg_val[3] & VIN_PGOOD_FLAG_MASK);
// FLAG1
uint8_t vin_ovp_fault_flag = (received_reg_val[4] & VIN_OVP_FAULT_FLAG_MASK) >> VIN_OVP_FAULT_FLAG_SHIFT;
uint8_t bat_ocp_fault_flag = (received_reg_val[4] & BAT_OCP_FAULT_FLAG_MASK) >> BAT_OCP_FAULT_FLAG_SHIFT;
uint8_t bat_uvlo_fault_flag = (received_reg_val[4] & BAT_UVLO_FAULT_FLAG_MASK) >> BAT_UVLO_FAULT_FLAG_SHIFT;
uint8_t ts_cold_flag = (received_reg_val[4] & TS_COLD_FLAG_MASK) >> TS_COLD_FLAG_SHIFT;
uint8_t ts_cool_flag = (received_reg_val[4] & TS_COOL_FLAG_MASK) >> TS_COOL_FLAG_SHIFT;
uint8_t ts_warm_flag = (received_reg_val[4] & TS_WARM_FLAG_MASK) >> TS_WARM_FLAG_SHIFT;
uint8_t ts_hot_flag = (received_reg_val[4] & TS_HOT_FLAG_MASK);
// FLAG2
uint8_t ts_open_flag = (received_reg_val[5] & TS_OPEN_FLAG_MASK);
// FLAG3
uint8_t wd_fault_flag = (received_reg_val[6] & WD_FAULT_FLAG_MASK) >> WD_FAULT_FLAG_SHIFT;
uint8_t safty_tmr_fault_flag = (received_reg_val[6] & SAFETY_TMR_FAULT_FLAG_MASK) >> SAFETY_TMR_FAULT_FLAG_SHIFT;
uint8_t ldo_ocp_fault_flag = (received_reg_val[6] & LDO_OCP_FAULT_FLAG_MASK) >> LDO_OCP_FAULT_FLAG_SHIFT;
uint8_t mrwake1_timout_flag = (received_reg_val[6] & MRWAKE1_TIMEOUT_FLAG_MASK) >> MRWAKE1_TIMEOUT_FLAG_SHIFT;
uint8_t mrwake2_timout_flag = (received_reg_val[6] & MRWAKE2_TIMEOUT_FLAG_MASK) >> MRWAKE2_TIMEOUT_FLAG_SHIFT;
uint8_t mrreset_warn_flag = (received_reg_val[6] & MRRESET_WARN_FLAG_MASK);
}

  • Hi,

    Typically seeing a STAT bit register will be paired with seeing a FLAG bit register being set, but the two bits behave a bit differently.

    -The STAT bit register will tell you in real time the current state of the device.

    -The FLAG bits tell you if an event has taken place since the last time the register was read.

    If the FLAG register is read then the bits are automatically cleared, even if it is still in the indicated state. This means that if the FLAG register is read and read again, and both times the CV flag is high then during this time the device has been in CV state, exited CV state, and entered CV state again. If the FLAG register is read one and then read again, and the second time the CV flag is low, then CV state has been entered only once and may still be CV or may have exited CV.

    In your scenario, is the FLAG register being read more than once? If so this would explain why the STAT register may show CV status but the CV flag may be low, CV was entered once but has not exited since the last time the FLAG register was read.

    Best Regards,

    Juan Ospina

  • Thank you for your answer.

    I understood the flags are cleared after read out.

    But still my question remains.

    If the flag bit shows state transition, at least once must be observed flag set but in my software these flags' set was not detected even first loop.

    How should I interpret about the fact?

    Thanks,

  • Hi Naoya,

    Can you please describe the test procedure for the reading of this bit?

    Is the device already charging or is charging initiated before the registers are read? Has the device stopped charging and started charging again since the previous test?

    Best Regards,

    Juan Ospina