Tool/software:
Dear TI Team,
I am currently attempting to access the FET register subcommand to enable the FETs for charging. However, the command appears to be failing during execution. Could you please suggest any alternative methods to enable the FETs?
For communication, I am using the I2C protocol with an STM32G4 MCU.
Kindly find the attached code snippet used for enabling the FETs.
Thank you for your support.
Best regards,
Harsh
#define BQ76972_I2C_ADDR_WRITE 0x10
void BQ76972_Unseal(I2C_HandleTypeDef *hi2c3)
{
char message[64];
uint8_t unseal_key1[] = { 0x14, 0x04 };
uint8_t unseal_key2[] = { 0x72, 0x36 };
HAL_GPIO_WritePin(MCU_BMS_RESET_GPIO_Port, MCU_BMS_RESET_Pin, GPIO_PIN_SET);
HAL_Delay(100);
HAL_GPIO_WritePin(MCU_BMS_RESET_GPIO_Port, MCU_BMS_RESET_Pin, GPIO_PIN_RESET);
HAL_Delay(300);
if(HAL_I2C_Mem_Write(hi2c3, BQ76972_I2C_ADDR_WRITE, 0x00, I2C_MEMADD_SIZE_8BIT, unseal_key1, 2, 100) == HAL_OK)
{
snprintf(message, sizeof(message),"Unseal success\r\n");
RS485_Transmit((uint8_t*)message, strlen(message));
}
else
{
snprintf(message, sizeof(message), "Unseal Step 1 failed\r\n");
RS485_Transmit((uint8_t*)message, strlen(message));
}
HAL_Delay(5);
HAL_I2C_Mem_Write(hi2c3, BQ76972_I2C_ADDR_WRITE, 0x74, I2C_MEMADD_SIZE_8BIT, unseal_key2, 4, 100);
HAL_Delay(5);
}
void BQ76972_Enter_ConfigUpdate(I2C_HandleTypeDef *hi2c3)
{
char config_msg_1[30];
uint8_t cfgupdate_cmd[] = { 0x90, 0x00 }; // Subcommand = 0x0090
if(HAL_I2C_Mem_Write(hi2c3, BQ76972_I2C_ADDR_WRITE, CMD_SUBCOMMAND, I2C_MEMADD_SIZE_8BIT, cfgupdate_cmd, 2, 100) == HAL_OK)
{
snprintf(config_msg_1, sizeof(config_msg_1),"Config. mode success\r\n");
RS485_Transmit((uint8_t*)config_msg_1, strlen(config_msg_1));
}
HAL_Delay(5);
}
void BQ76972_WriteFETOptions(I2C_HandleTypeDef *hi2c3)
{
char msg[64];
uint8_t offset_subclass[2] = { 0x40, 0x80 }; // Offset = 0x40 (FET Options), Subclass = 0x80
uint8_t value = 0x07; // FET_CTRL_EN=1, HOST_FET_EN=1, DCHG_EN=1
uint8_t len = 1;
if(HAL_I2C_Mem_Write(hi2c3, 0x10, 0x3E, I2C_MEMADD_SIZE_8BIT, offset_subclass, 2, 1000) != HAL_OK)
{
snprintf(msg, sizeof(msg), "FET 0x3E Fail\r\n");
RS485_Transmit((uint8_t*)msg, strlen(msg));
return;
}
HAL_Delay(2);
if(HAL_I2C_Mem_Write(hi2c3, 0x10, 0x40, I2C_MEMADD_SIZE_8BIT, &value, 1, 1000) != HAL_OK)
{
snprintf(msg, sizeof(msg), "FET 0x40 Fail\r\n");
RS485_Transmit((uint8_t*)msg, strlen(msg));
return;
}
HAL_Delay(2);
if(HAL_I2C_Mem_Write(hi2c3, 0x10, 0x61, I2C_MEMADD_SIZE_8BIT, &len, 1, 1000) != HAL_OK)
{
snprintf(msg, sizeof(msg), "FET 0x61 Fail\r\n");
RS485_Transmit((uint8_t*)msg, strlen(msg));
return;
}
HAL_Delay(5);
snprintf(msg, sizeof(msg), "FET Options write successfully\r\n");
RS485_Transmit((uint8_t*)msg, strlen(msg));
}
void BQ76972_Exit_ConfigUpdate(I2C_HandleTypeDef *hi2c3)
{
char exit_msg[30];
uint8_t exit_cmd[] = {0x92, 0x00};
if(HAL_I2C_Mem_Write(hi2c3, BQ76972_I2C_ADDR_WRITE, CMD_SUBCOMMAND, I2C_MEMADD_SIZE_8BIT, exit_cmd, 2, 100) == HAL_OK)
{
snprintf(exit_msg, sizeof(exit_msg), "Exit config. Success\r\n");
RS485_Transmit((uint8_t*)exit_msg, strlen(exit_msg));
}
}
void BQ76972_Enable_AllFETs(I2C_HandleTypeDef *hi2c3)
{
uint8_t all_fets_on_cmd[] = {0x0096, 0x00}; // Subcommand for ALL_FETS_ON
char tx_msg[64];
if (HAL_I2C_Mem_Write(hi2c3, 0x10, 0x00, I2C_MEMADD_SIZE_8BIT, all_fets_on_cmd, 2, 1000) == HAL_OK)
{
snprintf(tx_msg, sizeof(tx_msg), "ALL_FETS_ON command success\r\n");
}
else
{
snprintf(tx_msg, sizeof(tx_msg), "ALL_FETS_ON command failed\r\n");
}
RS485_Transmit((uint8_t*)tx_msg, strlen(tx_msg));
}