我正在对 BMS 进行逆向工程。我已经关闭了所有硬件连接。它有一个 stm32f103c8 和带有 CRC 的 bq7693003。该芯片有 2 个库,但都不起作用!这是 BMS 的图片。这是 BMS 的模型。我正在使用 github 存储库中的示例代码。我正在使用的库称为:10s_Ti_BQ76930_BMS
将其中一个 GPIO 作为 BQ7693003 的启动引脚后,它会启动并在串行控制台中显示以下内容:
8
0x08
Starting BMS object
Starting wire.begin
starting variable initialization
Starting boot pin check
Determining i2c address and whether CRC is enabled
Address and CRC detection successful
Address: 8
CRC Enabled: 1
它被卡在那里。
在
bq769x0.cpp
中,我取消注释了 BootPin 代码以自动启动我的 bq7693003。在它没有打开之前。但现在它确实如此,并且如上所述陷入困境。
// Boot IC if pin is defined (else: manual boot via push button has to be
// done before calling this method)
Serial.println("Starting boot pin check");
if (bootPin >= 0)
{
pinMode(bootPin, OUTPUT);
digitalWrite(bootPin, HIGH);
delay(5); // wait 5 ms for device to receive boot signal (datasheet: max. 2 ms)
//pinMode(bootPin, INPUT); // don't disturb temperature measurement
delay(1000); // wait for device to boot up completely (datasheet: max. 10 ms)
}
还有另一个问题,因此无法编译:
// check for overrun of millis() or very slow running program
if (abs(secSinceInterrupt - secSinceErrorCounter) > 2) {
secSinceErrorCounter = secSinceInterrupt;
}
我想我通过使用
fabs
而不是 abs
解决了这个问题。
我在代码中添加了各种延迟,但它仍然无法正常工作。
我真的不知道该怎么做,因为我不知道如何为 I2C 和这个芯片编写代码。另外,我尝试过 LibreSolar 库,它可以很好地清除各种错误,例如 XR、Alert、UV、OV .. 等,但在清除 XR 错误后会卡住。
问候
因此,在从头开始部分重写整个库后,我意识到原作者有一些错误或我不确定的东西......如果有人知道请分享,以便此修复背后有一个原因。
首先我在
byte bq769x0::updateBalancingSwitches(void)
中将
void bq769x0::updateBalancingSwitches(void)
更改为
bq769x0.cpp
然后我在
byte updateBalancingSwitches(void);
中将
void updateBalancingSwitches(void);
更改为
bq769x0.h
最后我改变了这部分代码:
if (determineAddressAndCrc())
{
//debug prints to show that initial comms were successful
Serial.println("Address and CRC detection successful");
Serial.print("Address: ");
Serial.println(I2CAddress, HEX);
Serial.print("CRC Enabled: ");
Serial.println(crcEnabled);
// initial settings for bq769x0
writeRegister(SYS_CTRL1, 0b00010000); // Turn ADC on and use internal die temp
writeRegister(SYS_CTRL2, 0b01000000); // switch CC_EN on
// attach ALERT interrupt to this instance
instancePointer = this; //taken from arduino compatible code
attachInterrupt(digitalPinToInterrupt(alertPin), bq769x0::alertISR, RISING); //taken from arduino compatible code
// get ADC offset and gain
adcOffset = (signed int) readRegister(ADCOFFSET); // convert from 2's complement
adcGain = 365 + (((readRegister(ADCGAIN1) & 0b00001100) << 1) |
((readRegister(ADCGAIN2) & 0b11100000) >> 5)); // uV/LSB
}
else {
// TODO: do something else... e.g. set error flag
#if BQ769X0_DEBUG
Serial.println("BMS communication error\n");
#endif
}
/* // From original arduino startup code
if (readRegister(CC_CFG) == 0x19)
{
Serial.println("Inside readregister for cc_cfg if");
// initial settings for bq769x0
writeRegister(SYS_CTRL1, B00011000); // switch external thermistor and ADC on
writeRegister(SYS_CTRL2, B01000000); // switch CC_EN on
// attach ALERT interrupt to this instance
instancePointer = this;
attachInterrupt(digitalPinToInterrupt(alertPin), bq769x0::alertISR, RISING);
// get ADC offset and gain
adcOffset = (signed int) readRegister(ADCOFFSET); // convert from 2's complement
adcGain = 365 + (((readRegister(ADCGAIN1) & B00001100) << 1) |
((readRegister(ADCGAIN2) & B11100000) >> 5)); // uV/LSB
return 0;
}
bq769x0.cpp 文件中的这一点:
if (determineAddressAndCrc())
{
//debug prints to show that initial comms were successful
Serial.println("Address and CRC detection successful");
Serial.print("Address: ");
Serial.println(I2CAddress, HEX);
Serial.print("CRC Enabled: ");
Serial.println(crcEnabled);
}
// From original arduino startup code
if (readRegister(CC_CFG) == 0x19)
{
Serial.println("Inside readregister for cc_cfg if");
// initial settings for bq769x0
writeRegister(SYS_CTRL1, B00011000); // switch external thermistor and ADC on
writeRegister(SYS_CTRL2, B01000000); // switch CC_EN on
// attach ALERT interrupt to this instance
instancePointer = this;
attachInterrupt(digitalPinToInterrupt(alertPin), bq769x0::alertISR, RISING);
// get ADC offset and gain
adcOffset = (signed int) readRegister(ADCOFFSET); // convert from 2's complement
adcGain = 365 + (((readRegister(ADCGAIN1) & B00001100) << 1) |
((readRegister(ADCGAIN2) & B11100000) >> 5)); // uV/LSB
return 0;
}