This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BQ34110EVM-796: read voltage without bqstudio

Part Number: BQ34110EVM-796
Other Parts Discussed in Thread: BQSTUDIO, BQ34110

Hello everyone, I am using the bq34110EVM-796 module without using the bqstudio software. I want to retrieve the real-time voltage() of my battery. The battery I'm using is a 6s LiPo, so I'm using the jumper on the 36V setting. My goal was to communicate via I2C with an Arduino board and check if I could retrieve the voltage across my battery terminals. For this, I used the "slua790comI2C" datasheet to write my code.

Here's my code:

#include <Wire.h>

#define DEVICE_ADDRESS 0x55 // Address of the bq34110 module

void setup() {

Wire.begin(); // Initialize the Wire library

Serial.begin(9600); // Initialize serial communication to display results

int voltage = readVoltage(); // Call the function to read the voltage

Serial.print("Voltage: ");

Serial.print(voltage);

Serial.println(" mV");

delay(1000); // Wait for a second before reading the voltage again

}

int readVoltage() {

int voltage = 0;

Wire.beginTransmission(DEVICE_ADDRESS);

Wire.write(0x55); // address writing

delay(250);

Wire.write(0x08); // cmd voltage

delay(250);

Wire.write(0x56); // address reading

delay(250);

Wire.requestFrom(DEVICE_ADDRESS, 2); // Read 2 bytes (the 2 voltage bits)

// Wait for data to be available
if (Wire.available() >= 2) { // Both bytes are available
byte lowByte = Wire.read();
byte highByte = Wire.read();


Serial.println(highByte);
Serial.println(lowByte); // Calculate the voltage from the received bytes (assuming millivolt representation)
voltage = (highByte << 8) | lowByte;
}

int error1 = Wire.endTransmission(); Serial.println(error1);

return voltage;

}


void loop() { Serial.println("Finished");

delay(1000000);

}

After running this code, I get 0 mV as the result, which is very strange because the I2C communication seems to be working fine. Additionally, if I execute the 3 Wire.write commands in separate communications, I get 22016 mV regardless of the battery voltage. Can you help me solve these issues? Thank you in advance for your time.

  • Hello Erwan,

    I would recommend using bqStudio to first familiarize yourself with the commands.

    You can then compare the communication between bqStudio and your implementation.

    What is the purpose of the line Wire.write(0x56); // address reading ?

  • Hello thanks for your help, 

    For bqStudio I don't have the adaptor to connect the module to my computer. 

    For the different address, I used the Slua790 and we can find an exemple to communicate on I2C. This is the example : 

    So the address of my device is 0x55; so the 0xAB = 0x56 for me. But maybe I am wrong. 

    Thank you in advance for your time.

  • Hello Erwan,

    If you are not having success, then i would recommend reading firmware version.

    In the document it is section 2 Example 2: Reading the Firmware Version

    This is a fixed value. I believe the MSB is 00 and LSB is either 01 or 02

    This will be easier to verify

  • Hello, 

    Thanks for your help, I tried to do the example to read the Firmware Version. I made this code : 

    // preparing to communicate
      Wire.beginTransmission(DEVICE_ADDRESS);
      Wire.write(0x55); // address bq34110
      delay(250); //waiting for aknowledge
      Wire.write(0x00); //cmd
      delay(250); //waiting for aknowledge
      Wire.write(0x02); //cmd
      delay(250); //waiting for aknowledge
      Wire.write(0x00); //cmd
      delay(250); //waiting for aknowledge
      Wire.endTransmission();

      // Communication
      Wire.beginTransmission(DEVICE_ADDRESS);
      Wire.write(0x55);
      delay(250);
      Wire.write(0x00);
      delay(250);
      Wire.write(0x56);
      delay(250);
      // reading bits
      Wire.requestFrom(DEVICE_ADDRESS, 2);
      if (Wire.available() >= 2) {
        // data are ready
        byte lowByte = Wire.read();  
        byte highByte = Wire.read();  

        Serial.println(highByte);
        Serial.println(lowByte);
      }
      int error1 = Wire.endTransmission();
    Unfortunately, I have 0x00 for the MSB and LSB. I don't know what is wrong in my code. 
    Thanks for your time. 
  • I have test another code : 

    Wire.beginTransmission(BQ34110_ADDRESS);
      Wire.write(0x55);
      verif = Wire.endTransmission();
      Serial.print("verif 1 :");
      Serial.println(verif);

      Wire.beginTransmission(BQ34110_ADDRESS);
      Wire.write(byte(0x00));
      verif = Wire.endTransmission();
      Serial.print("verif 2 :");
      Serial.println(verif);


      Wire.beginTransmission(BQ34110_ADDRESS);
      Wire.write(0x02);
      verif = Wire.endTransmission();
      Serial.print("verif 3 :");
      Serial.println(verif);

      Wire.beginTransmission(BQ34110_ADDRESS);
      Wire.write(0x00);
      verif = Wire.endTransmission();
      Serial.print("verif 4 :");
      Serial.println(verif);
     
      Wire.beginTransmission(BQ34110_ADDRESS);
      Wire.write(0x55);
      verif = Wire.endTransmission();
      Serial.print("verif 5 :");
      Serial.println(verif);

      Wire.beginTransmission(BQ34110_ADDRESS);
      Wire.write(0x00);
      verif = Wire.endTransmission();
      Serial.print("verif 6 :");
      Serial.println(verif);

      Wire.beginTransmission(BQ34110_ADDRESS);
      Wire.write(0x56);
      verif = Wire.endTransmission();
      Serial.print("verif 7 :");
      Serial.println(verif);
    And i have 0 for MSB and 2 for LSB. So I think I have to use this architecture, but if i use this architecture for the voltage, I have 0 for MSB and 2 for LSB too. So i don't understand if I have to restore the module to ask the voltage. And if I have to, I don't know the CMD.
    Thanks for your help. 
  • Hello Erwan,

    After the second address write , you cannot do endtransmission. Try removing it

    Wire.write(0x55);
      verif = Wire.endTransmission();
  • Hello,

    By removing this line, it doesn't change anything. I noticed that I was getting this response because in the first code sent for this example, I had forgotten the last 'Wire.Endtransmission'. This meant that my second code was giving me the correct value. Additionally, the communication for command 0x02 is not working; the module doesn't understand it. The command 0x02 should only be executed if command 0x00 is given, and I believe the module is not retaining the command 0x00. So, I'm back to square one...

    Thanks for your help.

  • Hello Erwan,

    The best way without bqStudio is to capture the communication using a scope or capture device and analyze it. I think there may be some timing issue or non-compliance with spec

  • Hello,

    I am analyzing it with the scope, I will tell you what I find.

    Thank you for your help

  • Hello, 

    I think with the library SoftWire, I succed to comunicate with the module, but when I ask voltage I still have 0.

    I think my module is on SLEEPMODE, I don't know how to comeback to a NORMAL MODE. 

    Can you give me the address that I need to change? 

    Thanks for your help

  • Hello Erwan,

    Voltage readings should report correctly even in sleep mode

  • hello, 

    I managed to display the voltage by removing the jumper on the "VEN", so I have 5D on my LSB and 4 on my MSB. So I have the impression that my bits are reversed compared to the datasheet because if I put my LSB in MSB I find more than 23V, so which corresponds to my 24V battery. So I don't understand why there is this reverse. In addition, the returned value is returned only in a limited time, after I go back to 0. I have to turn off the module for 3-4 min to find the voltage.


    thank you for your help

  • First byte is LSB, second is MSB

  • okay, so I have a problem with my voltage because the voltage is true is the first byte is MSB and second is MSB. 

    Do you know why i can read the voltage only few minutes after turn the module ON? 

    thanks for your help

  • Hello Erwan,

    The gauge has an initialization time of 4 seconds. There may be some other issue if you have to wait a few minutes. Check if the gauge has power and if the communication lines are pulled up as soon as power is turned on. That is all that the gauge will need to report voltage.

  • Hello, 

    Thanks for your help. I will check that. 

    Can you explain the difference between the command ManufacturerAccessControl() and the command MACData() . 

    thanks for your time 

  • Hello Erwan,

    Section 3.23 and 3.24 of the TRM has this information.

    ManufacturerAccessControl() identifies the data command

  • hello, thanks a lot 

    I would like to set the ALARM 1 pin manually. I found a working code architecture for the ACCUM_RESET() function, which is normally the same. But my pin does not set to 1 when I apply this code. Is there a setting to change first?
    Here is my code:

      myWire.begin();
      myWire.startWrite(0x55);
      myWire.llWrite(0x00);
      myWire.llWrite(0X68);
      myWire.llWrite(0X00);
      myWire.endTransmission();

    Thank you very much for your answers

  • Hello Erwan,

    I would refer to the TRM or use bqStudio