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.