I am currently trying to connect a battery gauge (BQ27510-G3 from TI) to an Arduino MKR 1010 Wifi via I2C. I don't have that much experience with serial communication and registers, but with example codes I was able to read the values provided by the gauge.
To obtain the correct values, it is necessary to calibrate the battery gauge (e.g. battery capacity, ....). Here the trouble starts, I am not able to read or write calibration parameters in the register (more precisely: classes with offsets). I have checked the data sheets and my code looks correct, but I am not able to read even the default calibration parameters.
Does anyone have a working sample code for the above mentioned gauge with an Arduino?
I copied the code from a Sparkfun project on GIT. The big difference between my gauge and the gauge of Sparkfun is that the gauge of Sparkfun uses a ROM, while the BQ27510-G3 uses a FLASH. The FLASH does not have to go into the config mode. I mainly adjusted the addresses of the registers and deleted some things not needed. The working principle should however be the same as for the Sparkfun gauge (BQ27441), according to the data sheet.
Reading and writing from the registers works well. I only have problems with the calibration (reading and writing of the classes/offsets).
That code doesn't compile, it's not complete. You don't even try to implement the calibration process as described by this document. Am I wrong and you try to implement something different? If yes, please specify what you're actually trying to do.
thanks for the answer!
I have seen your document, but the data sheet of the bq27510-G3 does not contain control commands (0x81 and 0x80) as defined in the other gauges in this document. So I am confused. However, the enable control command (0x2d) exists, unlike in the older bq27510 versions.
I tried to get into this configuration mode but had no success. The value I wanted to write was not written.
PS: It should be possible to compile the files. I call the function "setupBQ27441(void)" in the setup part of my main program and the function "printBatteryStats()" in the loop part.
I have now implemented the communication with the BQ27510-G3 from scratch. Reading the output parameters from the gauge works well.
The problem remains reading and writing the calibration parameters to the gauge.
The purpose of the attached code script is to read the standard calibration values (check function: "Read_Classes" ), I followed the description in the datasheet (Chapter 4). The data sheet has recently been updated, but the communication process should not have changed.
It looks like I have an access problem, but the gauge should be in unsealed mode.
I have been stuck at this point for some time now, so any help would be appreciated.
So the Unsealing was not succesful.
What am I doing wrong? Or are my assumptions wrong? Unfortunately, I have no possibilities to check what is happening on the line.
Thanks for any help!
PS: The functions for this job are:
int ModifClasses(){
// Reset
int e[2]={0x41, 0x00};
bytesending(e);
// Unsealing
int a= readControlWord(0x0000); // Pre Command status
Serial.print("StatusCommandPre:");
Serial.println(a,BIN);
Serial.println();
int c[2]={0x14,0x04};
bytesending(c);
int d[2]={0x72,0x36};
bytesending(d);
int b= readControlWord(0x0000); // Post Command status
Serial.print("StatusCommandPost:");
Serial.println(b,BIN);
Serial.println();
return true;
}
With the sub-functions:
int bytesending(int *command){
if (i2cWrite((int) 0x00, command, 2))
return true;
return false;
}
int i2cWrite(int subAddress, int *data, int count)
{
Wire.beginTransmission(BQ27510G3_Address);
Wire.write(subAddress);
for (int i=0; i<count; i++)
{
Wire.write(data[i]);
}
Wire.endTransmission(true);
//int f=Wire.endTransmission(true);
//Serial.println(f);
return true;
}
int i2cRead(int subAddress, int *data, int count)
{
Wire.beginTransmission(BQ27510G3_Address);
Wire.write(subAddress);
Wire.endTransmission(true);
Wire.requestFrom(BQ27510G3_Address, count);
for (int i=0; i<count; i++)
{
data[i] = Wire.read();
}
return true;
}