I2C value problem

Hello.
I want to make a SMBUS powered smart powerbank.
anyway. i used i2c master lib and created one sketch. It reads cycle count , SOC level and Current.
but other values. they are awful. voltage is must be like 12000 mV , full charge , design , remain capacity is must be 4400mAh . Same was happening with temperature. but i removed it from sketch.

battery's smbus manual : http://sbs-forum.org/specs/sbdat110.pdf
i used this lib : DssCircuits.com is for sale | HugeDomains
I'm sure , i used correct adresses . but i tried everything. nothing fixes these values. (working with this sketch for 5 days . FIVE ! ) .
please help. how can i fix this situration (im really bored , and i see i2c adresses in my dreams.)

batt.ino (1.73 KB)

Why are you reading 8 bytes and the you store those bytes in an integer variable (only 2 bytes)?

  I2c.read(0x0b, 0x17 ,8); //Read 0x17 address in 0x0b device 

int CYCT = I2c.receive();

Are you sure that you don't want to read only 2 bytes?

  I2c.read(0x0b, 0x17 ,2); //Read 0x17 address in 0x0b device 
  int CYCT = I2c.receive();

i was tried "2" too. i changed to 8 later. i dont know why i did this. but writing "2" doesnt fixes too :confused:

Other problem that you have is that the function "receive()" only read out 1 byte:

Function: I2c.receive() - returns the first unread byte of the internal buffer.

Parameters: none

Return: first unread byte of the internal buffer

if you want to read more than 1 byte you need to do that in a different way.
Did you try the following function?

Function: I2c.read(address, registerAddress, numberBytes, *dataBuffer) -initiate a write operation

to set the pointer to the registerAddress, then sending a repeated start (not a stop then start)

and store the number of bytes in the dataBuffer.

As a side note there is no restriction on how many bytes may be received unlike the Wire

library which has a 32 byte restriction

Parameters: (uint8_t)address: 7 bit I2C slave address

(uint8_t)registerAddress: Starting register address to read data from

(uint8_t)numberBytes: The number of bytes to be read

(uint8_t)*dataBuffer: array to store read data

Return: More details to come. Returns actual error code per Atmel Datasheet. Unlike the Wire

library the read operation will not return the number of bytes read, instead it will return

the error code which can be used for debugging.

for the last sample code, I think you must do something like:

int CYCT; 
I2c.read(0x0b, 0x17 ,2, (uint8_t*) &CYCT); //Read 0x17 address in 0x0b device

same output. nothing happened :frowning:

luisilva:
Other problem that you have is that the function "receive()" only read out 1 byte:if you want to read more than 1 byte you need to do that in a different way.
Did you try the following function?
for the last sample code, I think you must do something like:

int CYCT; 

I2c.read(0x0b, 0x17 ,2, (uint8_t*) &CYCT); //Read 0x17 address in 0x0b device

well. you are right. cycle count and soc uses 1 byte. but when i tried Vbatt , it needs 2 byte. but how can i read 2 byte with this library ? .
"I2c.read(0x0b, 0x09 ,2, (uint8_t*) &VBAT)" didnt worked.
i found something like this in forum. i think i will use wire lib. ;
"one= Wire.read();
second=Wire.read();"

What does it mean "didnt worked"? If you with this can't read the 2 bytes it's because you are not reading anything at all.

i think im blind. i didnt see u said "int CYCT; "

Thanks so much.i can get 11910mV now . :slight_smile:
now i will try same think for Full charge cap and every other things.