主题: BQSTUDIO 中讨论的其他器件
工具/软件:
您好、
我对电气工程和 TI 平台非常不熟悉、请原谅我在格式化、文档编写等方面犯的任何错误
我设计了定制 PCB 作为 BMS、并使用了 BQ76952芯片、下面您可以看到原理图、也包括电池布线、以及源代码 I 在具有 I2C 通信的 Arduino IDE 中测试 esp32。 我搜索网络,与聊天机器人交谈,但仍然可以得到一个软件解决方案,我的问题,充电和放电闸门关闭。 您认为我的示意图或电池接线可能有问题吗? 是否有比使用代码更好的测试方法? 不确定 BQSTUDIO 是否起作用? 非常感谢您的帮助。 我很感激每一个答案。
这是控制台中代码的输出
Cell 1 voltage: 3.686 V Cell 2 voltage: 4.102 V Cell 3 voltage: 3.686 V Cell 4 voltage: 3.666 V Cell 5 voltage: 0.000 V Cell 6 voltage: 0.000 V Cell 7 voltage: 0.000 V Cell 8 voltage: 0.000 V Cell 9 voltage: 0.000 V Cell 10 voltage: 0.000 V Cell 11 voltage: 0.000 V Cell 12 voltage: 0.000 V Cell 13 voltage: 0.000 V Cell 14 voltage: 0.000 V Cell 15 voltage: 0.000 V Cell 16 voltage: 3.839 V FET Status: 1110000
e2e.ti.com/.../SCH_5F00_Schematic1_5F00_2025_2D00_04_2D00_03.pdf
#include <Wire.h>
// BQ76952 I2C address (7-bit)
#define BQ76952_I2C_ADDR 0x08
// Command addresses
#define CONTROL_STATUS 0x00
#define BATTERY_STATUS 0x12
#define CELL1_VOLTAGE_L 0x14
#define CELL1_VOLTAGE_H 0x15
#define FET_STATUS 0x7F
// Variables to track communication status
bool commEstablished = false;
int retryCount = 0;
const int maxRetries = 5;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22, 400000); // Initialize I2C with default pins (SDA=21, SCL=22)
// Try to establish communication
while (!commEstablished && retryCount < maxRetries) {
if (checkCommunication()) {
commEstablished = true;
Serial.println("Communication with BQ76952 established successfully!");
} else {
retryCount++;
Serial.print("Communication failed, retry ");
Serial.print(retryCount);
Serial.println("/5");
delay(1000);
}
}
if (!commEstablished) {
Serial.println("Failed to establish communication with BQ76952");
while(1); // Halt if communication fails
}
}
void loop() {
// Read and print cell voltages (example for cells 1-4)
for (int cell = 1; cell <= 16; cell++) {
float voltage = readCellVoltage(cell);
Serial.print("Cell ");
Serial.print(cell);
Serial.print(" voltage: ");
Serial.print(voltage, 3);
Serial.println(" V");
}
// Read and print FET status
uint8_t fetStatus = readRegister(FET_STATUS);
Serial.print("FET Status: ");
Serial.println(fetStatus, BIN);
// Check if FETs are enabled
bool chgEnabled = (fetStatus & 0x01) != 0;
bool dsgEnabled = (fetStatus & 0x02) != 0;
Serial.print("CHG FET: ");
Serial.println(chgEnabled ? "ENABLED" : "DISABLED");
Serial.print("DSG FET: ");
Serial.println(dsgEnabled ? "ENABLED" : "DISABLED");
Serial.println("---------------------");
delay(1000); // Delay between readings
}
bool checkCommunication() {
// Try to read the Battery Status register
Wire.beginTransmission(BQ76952_I2C_ADDR);
Wire.write(BATTERY_STATUS);
if (Wire.endTransmission(false) != 0) { // Send repeated start
return false;
}
// Request 2 bytes (Battery Status is 16-bit)
if (Wire.requestFrom(BQ76952_I2C_ADDR, 2) != 2) {
return false;
}
// If we got data, communication is working
uint16_t batteryStatus = Wire.read() | (Wire.read() << 8);
return true;
}
float readCellVoltage(int cellNumber) {
// Calculate register addresses for the cell
uint8_t regLow = CELL1_VOLTAGE_L + (2 * (cellNumber - 1));
uint8_t regHigh = regLow + 1;
// Read low and high bytes
uint8_t lowByte = readRegister(regLow);
uint8_t highByte = readRegister(regHigh);
// Combine bytes and convert to voltage (mV to V)
int16_t voltage_mV = (highByte << 8) | lowByte;
return voltage_mV / 1000.0;
}
uint8_t readRegister(uint8_t reg) {
Wire.beginTransmission(BQ76952_I2C_ADDR);
Wire.write(reg);
Wire.endTransmission(false); // Send repeated start
Wire.requestFrom(BQ76952_I2C_ADDR, 1);
while (Wire.available() < 1); // Wait for data
return Wire.read();
}