I2C and LTC2944 Battery Gas Gauge [SOLVED]


#1

Hi

I have code running on my Arduino Uno to get the information from LTC2944 over I2C, but when I port the code to Particle Electron, my readings are 240 (or 1111 0000 in binary).

Do you guys have any idea why I am getting that response?

I have 4.7k I2C pull-ups.
I ran the I2C scanner and I get the response that “I2C device found at address 0x64”, which is good.
I am utilizing the Wire library and the LTC2944 library from here.
https://www.analog.com/en/products/ltc2944.html#product-tools

My setup includes the following lines.

Wire.setSpeed(CLOCK_SPEED_100KHZ);
Wire.stretchClock(true);
Wire.begin();
LTC2944_mode = LTC2944_AUTOMATIC_MODE | prescalar_mode | alcc_mode ;
ack |= LTC2944_write(LTC2944_I2C_ADDRESS, LTC2944_CONTROL_REG, LTC2944_mode);

My main loop includes the following lines.

// Read 16-bit charge measurement
ack |= LTC2944_read_16_bits(LTC2944_I2C_ADDRESS, LTC2944_VOLTAGE_MSB_REG, &voltage_measurement);
// Convert voltage reading to Volts
batteryState.voltage_V = LTC2944_code_to_voltage(voltage_measurement);
Serial.print("Raw Battery Voltage: ");
Serial.println(voltage_measurement);

The result is

Raw Battery Voltage: 240
  • Rob

#2

@rob_iot

  1. Looking at the application sheet the pull-ups recommended are 2K to 3.3V. You only mentioned 4.7K pull-ups but not what voltage to.
  2. I don’t understand why you need the Wire.setSpeed() and Wire.stretchClock().
  3. If you look in the Particle Community Library you will find a driver for a LTC2943 https://build.particle.io/libs/LTC2943/1.0.0 I imagine the LTC2943 is close to the 2944. This has been written in a different way than I would - C instead of C++? Typically these drivers have an object constructor and (destructor) with an initialiser (.begin) method that stores mode, pin connections and I2C address in private variables.
  4. Serial.println(batteryState.voltage_V)? rather than voltage_measurement?

#3

Thanks for your reply.

  1. I tried using 2k to 3.3V just now, without any luck.
  2. I removed those commands. I think I originally used them because I thought they were mandatory (misread the Wire (I2C) in the Particle’s Reference docs).
  3. I am using the LTC2944 library which seems to be pretty close to the LTC2943 library and I think I use it properly because the code works with Arduino.
  4. The result is 0.26V (converted).

Using Arduino I get 24425 (raw reading) and 26.09 V (converted), which is within 0.05V or so of the real value. From what I’ve been seeing there is clearly something wrong with my setup of the Particle.


#4

@armor Thanks for pointing me to the LTC2943 library.
I made the following changes to the LTC2944 library to make it work with the Particle Electron.

  1. Remove Wire.h include from the LTC2944.h
  2. Remove Arduino.h, stdint.h, Linduino.h, LT_I2C.h, and Wire.h includes from LTC2944.cpp.
  3. Add Particle.h include to LTC2944.cpp.

As a result I am reading appropriate voltages, current, charge, and temperature.

Raw Charge Energy: 32743
Raw Battery Voltage: 23433
Raw Charge Current: 32576
Raw Temperature: 38816
Raw Status code: 0
Converted Charge Energy: 46.39
Converted Battery Voltage: 25.03
Converted Charge Current: -0.03
Converted Temperature: 28.92

#5
  1. I also had to copy the read and write commands from LTC2943 to LTC2944 because the original read and write commands from LTC2944 are not compatible with the Particle Electron.

P.S. The reason why I did not use the LTC2943 library is because the conversion factors are different for the two chips.


#6

Is the “converted charge energy” the batteries SOC level?


#7

I don’t see how your original code was storing the result value, but judging by the values you considered valid I’d assume 16bit return values and hence the difference in endianness between Arduino and Particle devices might be part of your previous problem.


#8

Hi,

I am using LTC2943 IC to measure the battery voltage. I am getting the voltage value but it doesn’t seem to be perfect.
For an example, If my battery voltage is 7.45V then It will show 7.2V. It always shows the voltage lesser than it actually is. Strangely, The difference always remains 0.2V.
I am using Android 7.1 SDK and I have downloaded the ltc2943 driver from official site.
Everything else seems to be all right.

Thanx in advance.


closed #9

Due to double posting the same question as dedicated thread here

this topic gets closed and the discussion should continue over there.


@Parth9731, double posting is not appreciated as it will just scatter the discussion, tie up resources multiple times and not really bring any extra benefit.