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.

Problem writing to BLOCKDATA

Below is code I am using to write to the BLOCKDATA area in a BQ27425.  The code seems to work correctly up to the RESET.  The problem is that when I do the SOFT_RESET clear the CFGUPDATE flag, the BQ27425 returns a BUSY (not the expected OK). 

I have also tried a HARD_RESET rather than a SOFT_RESET and even waited 240seconds without doing a reset.  None of these three options solve the BUSY problem. 

Can you suggest a sequence that allows me write to the BLOCKDATA area in a BQ27425 without getting a BUSY return when to clear the CFGUPDATE flag?

HAL_StatusTypeDef  WriteDataBlock (uint8_t CLASS, uint8_t OFFSET, uint8_t Init, uint8_t u8WriteBytes, bool toNVM)
{
   HAL_StatusTypeDef    HalReturn = HAL_NOP;
   uint8_t              UnSealReturn;
   uint8_t              i8Sum, x, u8Dummy;
   uint8_t              u8LocalWriteBuffer[32] = {0x00};
   uint8_t              u8LocalReadBuffer[36] = {0x00}; //Little Endian
   uint8_t              u8CheckSumBuffer[10] = {0x00};

      //To update a Data Block the bq must be in CFGUPDATE mode
      if ((HalReturn = WriteStandardInfo(CONTROL, SET_CFGUPDATE, &u8Dummy))  == HAL_OK)
      {
          if (ReadStandardInfo(FLAGS, NO_CNTL_FNCT, u8LocalReadBuffer, 2) == HAL_OK)
              //LoByte = OCVTAKEN / RSVD / ITPOR / CFGUPMODE // BAT_DET / SOC1 / SOCF / DSG
              if ((u8LocalReadBuffer[0] & 0x10) != 0x10) //check CFGUPMODE = true
                  return HAL_ERROR;
      }
       
      //Put the Class and Offset, of the BlockData to be accessed, into  BlockData and BlockData+1
      u8LocalWriteBuffer[0] = DATACLASS;     //DATACLASS = 0x3E;
      u8LocalWriteBuffer[1] = CLASS;         //e.g., 0x52;
      u8LocalWriteBuffer[2] = (OFFSET / 32); //BLOCK_#: 0, 1, 2, etc.;
      HalReturn = I2C_Master_Transmit(&hi2c1, 0xAA, u8LocalWriteBuffer, 3, BQ27425_TIMEOUT);
     
      //Write BLOCKDATACONTROL(0x61) & 0x00
      u8LocalWriteBuffer[0] = BLOCKDATACONTROL; //0x61;
      u8LocalWriteBuffer[1] = 0x00;             //0x00;
      HalReturn = I2C_Master_Transmit(&hi2c1, 0xAA, u8LocalWriteBuffer, 2, BQ27425_TIMEOUT);

      //Write the bytes of the designated WriteBuffer[] to the BLOCKDATA at addresses 0x40 - 0x5F
      if (Init == true)
      {
        HalReturn = I2C_Mem_Write(&hi2c1, 0xAA, BLOCKDATA, 1, u8GasGaugeStateInit, 32, BQ27425_TIMEOUT); //u8WriteBytes
      }
     
      if (toNVM)
      {
        //Compute the CheckSum of the 32-bytes just written to the DataBlock at 0x40 - 0x5F
        i8Sum = 0x00;
        for (x=0; x<32; ++x)
            i8Sum += u8LocalWriteBuffer[x];
        u8CheckSumBuffer[0] = 0xFF - i8Sum; //compute 1's complement of the CheckSum
            
        //Write the CheckSum to BLOCKDATACHECKSUM            
        HalReturn = I2C_Mem_Write(&hi2c1, 0xAA, BLOCKDATACHECKSUM, 1, u8CheckSumBuffer, 1, BQ27425_TIMEOUT);
      }
     
    //Clear the CFGUPDATE flag
    HalReturn = WriteStandardInfo(CONTROL, SOFT_RESET, u8CheckSumBuffer);
    Delay(0x100); //100ms
    
    return  HalReturn;
}