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.

BQ34Z110 I2C - How to write with read-only command.

Other Parts Discussed in Thread: BQ34Z110

Hi. 

Bq34z110 I2C

- How to write with read-only command????

I would like to know how to write in read-only command(=PackConfiguration).

※ PackConfiguration(): 0x3a, 0x3b
This Read-Word function allows the host to read the configuration of selected features of the bq34z110
pertaining to various features. Refer to PACK CONFIGURATION REGISTER.

[source]

//Pack Configuration
Command = 0x3b;
TxData[0] = 0x09;
TxData[1] = 0x61;
if(HAL_I2C_Mem_Write( &hi2c2, 0xAA, Command, 0x10, TxData, 2, 10)== HAL_OK)
{
tValue = TxData[0];
tValue = (tValue << 8) + TxData[1];

g_BattICValue.PKCon = tValue;
}

※ HAL_I2C_Mem_Write

HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
{
/* Check the parameters */
assert_param(IS_I2C_MEMADD_SIZE(MemAddSize));

if(hi2c->State == HAL_I2C_STATE_READY)
{
if((pData == NULL) || (Size == 0))
{
return HAL_ERROR;
}

if(__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET)
{
return HAL_BUSY;
}

/* Process Locked */
__HAL_LOCK(hi2c);

hi2c->State = HAL_I2C_STATE_MEM_BUSY_TX;
hi2c->ErrorCode = HAL_I2C_ERROR_NONE;

/* Send Slave Address and Memory Address */
if(I2C_RequestMemoryWrite(hi2c, DevAddress, MemAddress, MemAddSize, Timeout) != HAL_OK)
{
if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
{
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
return HAL_ERROR;
}
else
{
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
return HAL_TIMEOUT;
}
}

while(Size > 0)
{
/* Wait until TXE flag is set */
if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}

/* Write data to DR */
hi2c->Instance->DR = (*pData++);
Size--;

if((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BTF) == SET) && (Size != 0))
{
/* Write data to DR */
hi2c->Instance->DR = (*pData++);
Size--;
}
}

/* Wait until TXE flag is set */
if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TXE, RESET, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}

/* Generate Stop */
hi2c->Instance->CR1 |= I2C_CR1_STOP;

/* Wait until BUSY flag is reset */
if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_BUSY, SET, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}

hi2c->State = HAL_I2C_STATE_READY;

/* Process Unlocked */
__HAL_UNLOCK(hi2c);

return HAL_OK;
}
else
{
return HAL_BUSY;
}
}

Many Thanks.

  • The Pack Configuration register is read only using the Extended I2C commands, but you can change the register in the data flash. There is an example of the process to do this on page 13 of the datasheet. The SubClass and Offsets can be found in the Data Flash table on page 40. The SubClass for the Pack Configuration register is 64 (40H) and the Offset is 0.
  • Tom,

    Do I need to code using the 'HAL_I2C_Mem_Write' fution?

    I should be used multiple times?

    Is this method appropriate?

    ----
    //Pack Configuration
    Command = 0x3a;
    Size = 2;
    if( HAL_I2C_Mem_Read ( &hi2c2, BATT_CHK_I2C_ADDRESS, Command, 1, RxData, Size, 10 ) == HAL_OK )
    {
    }

    Command = 0x3a;
    TxData[0] = 0x00;
    TxData[1] = 0x40;
    TxData[2] = 0x00;
    if(HAL_I2C_Mem_Write( &hi2c2, 0xAA, Command, 0x10, TxData, 3, 10)== HAL_OK)
    {
    }

    Command = 0x3a;
    TxData[0] = 0x00;
    TxData[1] = 0x40;
    TxData[2] = 0x00;
    TxData[3] = 0xA7;
    if(HAL_I2C_Mem_Write( &hi2c2, 0xAA, Command, 0x10, TxData, 4, 10)== HAL_OK)
    {
    }
    ----

    Here are the steps that I don't know :

    1.Read PackConfiguration() : 0x961 .
    2.Write 0x00 to 61
    3.Write 40H (64 subclass ID) to 3E
    4.Write 0x00 (Offset) to 3F
    5.Read 20 bytes of data from 40
    6.Read the checksum from 60. I read 97H.
    7.Calculate new checksum. I calculated it to be A7.
    8.Write 0x00 to 61
    9.Write 40H (64 subclass ID) to 3E
    10.Write 0x00(Offset) to 3F
    11.Write 20 bytes of data to 40. I changed the Pack Cfg A from 961 to 951
    12.Write A7H to 60.
    13.Read the Pack Cfg A and it was 951.

    Compare please explain in the coding.