cancel
Showing results for 
Search instead for 
Did you mean: 

BQ21061's value of status registers and flag registers

curiae
Associate III

Hello,

Now I'm trying to watch battery charge status using the charge IC BQ21061.
I got the each registers' value via I2C by STM32LO 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

 

int16_t 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);
}

 

 

 

1 REPLY 1

@curiae wrote:

using the charge IC BQ21061.


This: https://www.ti.com/product/BQ21061 ?

that's a TI product - nothing to do with ST - so you need to go to TI with questions about their products. 

https://www.ti.com/product/BQ21061#support-training

 

Please see this article for how to properly post source code; see also the Posting Tips:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228