I2C Help

Hello Im very new to I2C and I need some help trying to read a byte of information from my Li-ion battery fual gauge.

The ID of the gauge is 0xAA and I'm trying to read the SOC "State Of Charge" in reg 0x2c but im having a hard time getting it too work.
To read 1 byte the datasheet for the bq27510 states that it supports this I2C format for a 1 byte write:

START -> ADDR[6:0] 0 A -> CMD[7:0] A -> REPEATED START -> ADDR[6:0] 1 A -> DATA[7:0] N -> STOP

(ADDR = Device ID, CMD = Reg, 0= Write, 1= Read, A = Acknowledge, N = No Acknowledge, and P = Stop)

The datasheet also states that "The fuel gauge supports the standard I2C read, incremental read, one-byte write quick read, and functions. The7-bit device address (ADDR) is the most significant 7 bits of the hex address and is fixed as 1010101. The 8-bit
device address is therefore 0xaa or 0xab for write or read, respectively."

Does that mean I can keep the address 0xAA or would a have to change it too "170" the same would apply for the SOC reg address.

I've had a go at trying to solve this but with no luck. Can someone help :smiley:

This is the sketch so far:
//Include Wire I2C Library
#include <Wire.h>

int gauge_address = 0xAA; // Fual Gauge Address
int SOC = 0x2c; // State Of Charge Address
void setup()
//Create Serial Object (9600 Baud)

//Create a Wire Object

void loop()

//Send Request
Wire.beginTransmission(gauge_address); //Start talking to fual gauge
Serial.print(“Start Talking”);

Wire.write(0x2c); //Write to SOC reg (8 bit device)

delay (50);

Wire.beginTransmission(gauge_address); //Start talking

Serial.print(“End Transmission”);
Serial.print(“Waiting for relpy”);
Wire.requestFrom(SOC, 1); //Request 1 Byte
while(Wire.available() == 0); //wait for response

int c = Wire.read(); // Changed command from receive to read, Get the SOC



This is the sketch so far:

Which is improperly posted. Is your tab key broken? If so, use the space bar or Tools + Auto Format.

What does that code do that you don't want, or not do that you do want?

Your address looks wrong, by the way.