The datasheet is not 100% clear, but I think that two-byte data can be written at once (probably more) and it is allowed to read multiple bytes. A repeated start is allowed between writing the command (the register address) and reading data.
For the control register the datasheet says that it “…requires a subsequent two-byte subcommand”. The word “requires” could indicate that it must be done that way.
The hard part is to retrieve data and the different modes of the chip. Sometimes data has to be copied before it can be read.
In the setup() there is no initialization for the chip ? Does it need to be awaken from a sleep mode or is some kind of initialization needed ?
It can be in “SEALED”, “UNSEALED”, “BOOTROM”, “FULL SLEEP”, “CALIBRATION” or “FULL ACCESS” mode, but I don’t know what they are. There is even a “NORMAL” mode :o
You can start to check if you are at least communicating with the chip.
byte error = Wire.endTransmission();
if( error == 0)
Serial.println("The chip is found");
Serial.println("Error, not connected to the chip");
If that does not work, try a I2C scanner until it works.
The next step would be to read fixed data, for example a WHO_AM_I register. The “Manufacturer Info Block” can not be read without selecting that page in the control register. Maybe you can add that later.
The first thing you do is read two bytes, but SOC data is only one byte. You are combining the “ME” register data with it.
Perhaps it is easier to start with the temperature. You can add this to setup(), but only after that is confirmed that you are communicating with the chip.
Wire.write( 0x0C); // command for temperature register
Wire.requestFrom( BQ34Z100, 2); // temperature is two bytes
uint16_t x = Wire.read(); // MSB first
x <<= 8;
x |= Wire.read();
float celcius = (float( x) / 10.0) - 273.15;
Serial.print( "Temperature = ");
Serial.print( " Celcius (0x");
Serial.print( x, HEX);
Serial.println( ")" );
The hexadecimal value should be around 0x0B73 for 20 degrees.
Oops, it is lowest byte first.
uint16_t x = Wire.read() ; // lowest byte first
x |= Wire.read() << 8 ;