请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:BQ76972 工具/软件:
尊敬的 TI 团队:
我目前正在尝试访问 FET 寄存器子命令以启用 FET 进行充电。 但是、该命令在执行期间似乎失败。 您能提出任何启用 FET 的替代方法吗?
对于通信、我将使用 I2C 协议与 STM32G4 MCU。
请查找所附用于启用 FET 的代码片段。
感谢您的支持。
此致、
恶劣
#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)); }