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.

I2C Writing and Reading to the bq34z100

Other Parts Discussed in Thread: BQ34Z100EVM, BQ34Z100

I am having difficulty reading data from the bq34z100EVM over I2C. I am using an Arduino Mega and have connected SDA to SDA, SCL to SCL and made sure both devices are sharing a ground. However, I cannot seem to read any of the device's statuses, such as the StateofCharge() or Voltage(). The manual confuses me and I was hoping someone might be able to explain to me step-by-step what bits need to be sent to the chip.

I have been able to get two Arduinos communicating over I2C using the Wire library, so I know that part is working, but I don't seem to understand the procedure for communicating with the bq34z100. Also, I have successfully connected the bq34z100 with the TI evaluation software, calibrated it, and discharged and charged a battery pack through it with the values updating as expected, so I don't believe there is anything wrong with my EVM.

Right now I am sending the address, then the two bytes of command and code and then writing the receive address and trying to read to bytes. So to get the StateofCharge():

Send -->  0xAA, 0x02, 0x03, 0xAB

The relevant Arduino code, using the Wire library is:

void loop()
 {
   Wire.beginTransmission(0xAA);    // Transmits device address
   Wire.write(0x02);                               // Transmit command              
   Wire.write(0x03);                               // Transmit code
   Wire.endTransmission();
   
   delay(0.1);                                          // 100us delay; have read from another user on the forum that at least 40us is required between sending and receiving
   
   Wire.requestFrom(0xAB, 2);           // Send device address (with read bit high) and indicate two bytes to be received
   

// Wait for bytes and print out to the terminal
   while(Wire.available())
   {
     char c = Wire.read();
     Serial.print('y');
   }
   
   delay(500);                   // Delay for 500 ms, allow for data to be received and written to terminal
   
 }

Am I going about this the right way?

  • I figured out why I couldn't get data back from the bq34z100. The Arduino "Wire" library automatically takes care of sending the read and write bit to the slave so all it needs is the 7-bit device address. When I changed 0xAA and 0XAB to 0x55 I started receiving values back from the gas gauge chip. I guess I asked my question too soon, but maybe this post will help someone else out.

  • Thanks Samuel. Understand that it can be frustrating sometimes. We appreciate your input.

  • Hello Samuel,

    Do you have final working code for arduino?

    I'm having problem to do basic thing...get battery voltage.

    Thanks.

  • Samuel is there any way you could share your Arduino code that you are using to communicate with the Bq34z100 fuel gauge via I2C? I really need it! I'll pay you for it. 

    Email me if you can @ Sales@PortableSolarPower.Biz if you are still around get this message. 

  • Hamayak did you ever find working Arduino code for the Bq34z100 chip? If so could you please share it? 

  • Ryan,

    I'll dig through my files and see what I have and then I'll email it to you or post a link to github so you can download it. I don't remember what the status of the code is but I'll check. No money necessary.

  • Thank you very much Samuel! I've been pulling my hair out trying to get this working so I can move forward with what I'm trying to accomplish. Thanks again :) 

  • Samuel, I didn't get an email from you but I did find your code and I can't thank you enough! You made my week :-)

  • Hey Samuel, I got your code up and running but I'm curious if you also get  the single digit readings for the following readings.  Shouldn't these show actual current readings? 

    Instantaneous Current Draw: 7
    Instantaneous Current Draw LSB: 7
    Instantantous Current MSB: 0

  • This is test code for verifying the functionality of reading the different status values so may not be 100% functional. I was having issues with the instantaneous current readings because they require writing to the registers in a specific order and sending both the control command and the specific subcommand. This is why I broke out the value into LSB and MSB, for troubleshooting. If I get a chance I'll take a look at the code this weekend and hook my Arduino up to a battery and see if I can figure out why the instantaneous current isn't returning the result in milliamps like the Average Current is.  

  • Cool, glad its just not on my end. I'm sure with TI's help we should be able to figure it out and get it working. 

    I figured out how to add the other commands in Table 19 in this Bq34z100 user guide http://www.ti.com/lit/ds/symlink/bq34z100.pdf  

    I have the TimeToEmpty reading now displaying on the serial output. Adding these other data points seems to be really easy so far. Awesome!

    Let me know what you find out about the Instantaneous current code. We should ask Thomas Cosby who is on this forum since he can probably get us the answer to your question. 

  • Any luck with finding time to try to get the Instantaneous Current working? 

    I'll send you $100 if you get it working : -)

  • i have all the standard commands up and working now! 

    The only thing I cant get to work is the instantaneous current reading. 

    This is data that is supposed to help understand how to do it. http://e2e.ti.com/support/power_management/battery_management/f/180/p/213060/820268.aspx#820268

    I'll send ya $100 if you can figure out how to get the Instantaneous current reading working. 

  • Hi Ryan

    Is it possible you could help me out with Samuals code, if you require money I will be happy to pay.

    Justin.murray@madisontech.com.au

  • Hey Samuel,
    I am referring to your code for my project and am trying to get the EVM module working with the Arduino to establish the I2C communication. However, for some reason, the Arduino is not recognizing the EVM. My circuit consists of the battery powering the EVM and the SDA and SCL are connected between the arduino and the evm, sharing a common ground. I have not used the EV2300 component at all as I do not wish to establish the USB communication with the computer. Is there anything else besides the battery connection and the i2c connection that is required for the gas gauge to obtain accurate data values? Kindly let me know. I am really clueless at this point
  • Hi Somnath, please share a few information with us.
    Which EVM and which Arduino library are you using ?
  • Hi Somnath,

    Unfortunately this project was several years ago and I don't think I have access to a BQ32Z100 chip or evaluation module anymore so don't know how much help I'll be. If you post a schematic of your set up with the Arduino and EVM I'll take a look, though. Also, if you want to refer to the code I used it's at my GitHub account: github.com/.../bq34z100_status_arduino.ino. Note, I haven't done anything with this code in a couple of years but it seemed to help some previous posters in this thread so thought I'd include it in case it's useful to you.

    One thing to check is that you are using pull-up resistors on your I2C communication lines, they should be included by default in the Arduino board but worth checking. Other than that and I need more info on what you're doing and what your code and set up is to be able to troubleshoot.

    Sam
  • Hello,

    Want to manage a bq34z100 with an arduino is not very serious and especially not industrial at all ...
    This μC is a technical nonsense, just good for hobbyists.
    I am a little surprised to see this kind of request on a forum such as this one.