请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:BQ76972 工具/软件:
TI 团队大家好、
我正在根据数据表和技术参考手册使用准确的数据编写 TS3 配置、但它失败了。 我附加了代码、输出日志和波形。 根据我的理解、我未在 I2C 通道上收到 ACK。 请告诉我是否有任何关于这方面的建议。
void BQ76972_Unseal(I2C_HandleTypeDef *hi2c3) { char message[64]; uint8_t unseal_key1[] = { 0x14, 0x04 }; uint8_t unseal_key2[] = { 0x72, 0x36 }; 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_WriteTS3Config(I2C_HandleTypeDef *hi2c3) { char wr_ts3_msg[64]; // Step 1: Set offset and subclass uint8_t offset_subclass[2] = { 0x5C, 0x80 }; if(HAL_I2C_Mem_Write(hi2c3, BQ76972_I2C_ADDR_WRITE, 0x3E, I2C_MEMADD_SIZE_8BIT, offset_subclass, 2, 100) == HAL_OK) { snprintf(wr_ts3_msg, sizeof(wr_ts3_msg),"Offset and Subclass pass\r\n"); RS485_Transmit((uint8_t*)wr_ts3_msg, strlen(wr_ts3_msg)); } else { snprintf(wr_ts3_msg, sizeof(wr_ts3_msg),"Offset and Subclass fail\r\n"); RS485_Transmit((uint8_t*)wr_ts3_msg, strlen(wr_ts3_msg)); return; } HAL_Delay(2); // allow time for memory map // Step 2: Write TS3 config value into data buffer (0x40) uint8_t ts3_cfg_value = 0x03; if(HAL_I2C_Mem_Write(hi2c3, BQ76972_I2C_ADDR_WRITE, 0x40, I2C_MEMADD_SIZE_8BIT, &ts3_cfg_value, 1, 100) != HAL_OK) { snprintf(wr_ts3_msg, sizeof(wr_ts3_msg),"TS3 Data Write fail\r\n"); RS485_Transmit((uint8_t*)wr_ts3_msg, strlen(wr_ts3_msg)); return; } HAL_Delay(2); // Step 3: Write length = 0x01 to 0x61 (tells BQ to commit 1 byte) uint8_t len = 0x01; if(HAL_I2C_Mem_Write(hi2c3, BQ76972_I2C_ADDR_WRITE, 0x61, I2C_MEMADD_SIZE_8BIT, &len, 1, 100) != HAL_OK) { snprintf(wr_ts3_msg, sizeof(wr_ts3_msg),"Length commit fail\r\n"); RS485_Transmit((uint8_t*)wr_ts3_msg, strlen(wr_ts3_msg)); return; } HAL_Delay(5); snprintf(wr_ts3_msg, sizeof(wr_ts3_msg),"TS3 Config. Write Success\r\n"); RS485_Transmit((uint8_t*)wr_ts3_msg, strlen(wr_ts3_msg)); }