My Goal
I'm trying to read and write data to the BQ27441-G1 LiPo battery fuel gauge using a Raspberry Pi 4. I was able to read data (voltage, state of charge, current draw, etc.) by porting the Sparkfun BQ27411 Arduino to use the bcm2835 library, but I can't set things like design capacity, terminate voltage, taper rate, etc. To be clear, using the same BQ27441 hardware, I can set these parameters with an Arduino and the above Sparkfun Library.
What Other People Have Tried
It seems like other people have had this problem. An arthurfbs posted to this forum with my exact problem but doesn't seem to have come up with a solution, or at least didn't post it. I believe this same person (username Arthur Santos) posted the same question to the TI forum and was told that the BQ27441 device was sending a NACK. The modified code doesn't seem to work and GitHub user airbiscuity agrees with me. There's also a Chintan Pathak who posted several questions (first, second, third) that reference his custom firmware but I haven't been able to set parameters with it. Based on the dates of the forum questions and the repo's last commit, I don't believe Chintan solved this problem either. There's a question on the stack exchange that suggests changing the device tree and compiling a DTB file. I tried to do so but I've never done something like this and am probably not doing it right, but ultimately failed to talk to the BQ27441. Unfortunately I don't have a logic analyzer to very the data being sent, but it's strange that this has been a problem for years yet no one (publicly) posted a solution.
What I Have Tried
I thought changing the I2C read and write commands of the Sparkfun Library would be enough to port the code. This was true for reading values like voltage and temperature, but setting parameters of the BQ27441 is proving more difficult. Here were my exact changes. Can you spot a problem translating the Arduino Wire library to the bcm2835 library?I've also tried writing my own firmware from scratch using the technical reference manual, specifically the instructions on page 14, section 3.1. However I've been unsuccessful.
![Image]()
I think the chance of greatest success is standing on the shoulders of giants and porting the Sparkfun library. Can anyone provide hints, insights, or suggestions for how to set BQ27441 parameters? Anyone have working code?
I'm trying to read and write data to the BQ27441-G1 LiPo battery fuel gauge using a Raspberry Pi 4. I was able to read data (voltage, state of charge, current draw, etc.) by porting the Sparkfun BQ27411 Arduino to use the bcm2835 library, but I can't set things like design capacity, terminate voltage, taper rate, etc. To be clear, using the same BQ27441 hardware, I can set these parameters with an Arduino and the above Sparkfun Library.
What Other People Have Tried
It seems like other people have had this problem. An arthurfbs posted to this forum with my exact problem but doesn't seem to have come up with a solution, or at least didn't post it. I believe this same person (username Arthur Santos) posted the same question to the TI forum and was told that the BQ27441 device was sending a NACK. The modified code doesn't seem to work and GitHub user airbiscuity agrees with me. There's also a Chintan Pathak who posted several questions (first, second, third) that reference his custom firmware but I haven't been able to set parameters with it. Based on the dates of the forum questions and the repo's last commit, I don't believe Chintan solved this problem either. There's a question on the stack exchange that suggests changing the device tree and compiling a DTB file. I tried to do so but I've never done something like this and am probably not doing it right, but ultimately failed to talk to the BQ27441. Unfortunately I don't have a logic analyzer to very the data being sent, but it's strange that this has been a problem for years yet no one (publicly) posted a solution.
What I Have Tried
I thought changing the I2C read and write commands of the Sparkfun Library would be enough to port the code. This was true for reading values like voltage and temperature, but setting parameters of the BQ27441 is proving more difficult. Here were my exact changes. Can you spot a problem translating the Arduino Wire library to the bcm2835 library?
Code:
// This modified code worksint16_t BQ27441::i2cReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count){bcm2835_i2c_begin();bcm2835_i2c_setSlaveAddress (BQ72441_I2C_ADDRESS); // 0x55bcm2835_i2c_set_baudrate(200000);bcm2835_i2c_write((char *)&subAddress, sizeof(subAddress));bcm2835_i2c_read((char *)dest, count);bcm2835_i2c_end();return 1;/* this is the functional code from the Sparkfun Arduino Library *///int16_t timeout = BQ72441_I2C_TIMEOUT;//Wire.beginTransmission(_deviceAddress);//Wire.write(subAddress);//Wire.endTransmission(true);////Wire.requestFrom(_deviceAddress, count);////for (int i=0; i<count; i++)//{//dest[i] = Wire.read();//}////return timeout;}// This modified code DOES NOT workuint16_t BQ27441::i2cWriteBytes(uint8_t subAddress, uint8_t * src, uint8_t count){bcm2835_i2c_begin();bcm2835_i2c_setSlaveAddress (BQ72441_I2C_ADDRESS); // 0x55bcm2835_i2c_set_baudrate(200000);bcm2835_i2c_write((char *)&subAddress, sizeof(subAddress));bcm2835_i2c_read((char *)src, count); // I have a feeling the problem is herebcm2835_i2c_end();/* this is the functional code from the Sparkfun Arduino Library *///Wire.beginTransmission(_deviceAddress);//Wire.write(subAddress);//for (int i=0; i<count; i++)//{//Wire.write(src[i]);//}//Wire.endTransmission(true);return true;}
I think the chance of greatest success is standing on the shoulders of giants and porting the Sparkfun library. Can anyone provide hints, insights, or suggestions for how to set BQ27441 parameters? Anyone have working code?
Statistics: Posted by rapwiyeko — Fri Mar 22, 2024 4:01 am — Replies 0 — Views 18