@ScruffR @peekay123 Iām back at finishing a few missing functions with this library and now have it running on a Photon.
I need help figuring out how to isolate certain bitās from a I2C Block Read function so I can update individual variables.
So let me try to explain what I have going on:
To read the āFuel Gauge Statusā Register using the Photon I take the following steps:
1 - To read the Fuel Gauge Status Register I have to do a Block Read via Manufacturer Access command 0x44 and then call function I want to read data from, in this case we will read data from the GaugingStatus command 0x0056:
Since I have PC software that reads this info I already know the correct response we should get from command 0x0056 - GaugingStatus function is: 0x8540
2 - The read block code I have running on the Photon also reads this 0x0056 function via a Block Read function and returns the correct data.
Below is the code Iām using on the Photon to do the Block read to get the Gauging Status:
#include "application.h"
#include "BQ20Z45.h" //Include BQ78350 Header File
// Store an instance of the BQ20Z45 Sensor
BQ20Z45 bms;
char strBuffer[33]; // This is a Buffer to store 32 bit data strings read from the BQ78350 Fuel Gauge. Not Sure if this is the best place for this code.
void setup(void)
{
// We start the serial library to output our messages.
Serial.begin(115200);
// Start i2c communication.
Wire.begin();
}
void loop(void)
{
//Serial.println("Gauging Status");
bms.GaugingStatus(strBuffer);
delay(4000);
}
Here is the .H file:
#ifndef BQ20Z45_h
#define BQ20Z45_h
#define BQ20Z45_Address 0x0B
#define BQ20Z45_ManBlockAccess 0x44
#define BQ20Z45_ManAccess 0x00
#define BQ20Z45_GaugingStatus 0x56
class BQ20Z45
{
public:
int GaugingStatus(char *result);
protected:
private:
int readStringB(uint8_t address, char* result);
};
#endif
Here is the cpp file:
#include "application.h"
#include "BQ20Z45.h"
//#include "Arduino.h"
#include "application.h"
/////////////////////////////////////////////////////////////////////////////
// Functions Below
// pass a pointer to a char[] that can take up to 33 chars
// will return the length of the string received
int BQ20Z45::readStringB(uint8_t address, char* result)
{
int pos = 0;
int len;
// Read the length of the string
Wire.beginTransmission(BQ20Z45_Address); //Setup Write to Gauge
Wire.write(0x44); //Manufacturer Block Read
Wire.write(0x02); //How Many Bytes to expect Next
Wire.write(address); //Manufacturer Access Command - Example 0x01 Device Type
Wire.write(0x00); //First Byte of Command
Wire.endTransmission(true); //Repeated Start = True
Wire.beginTransmission(BQ20Z45_Address); //Setup Write to Gauge
Wire.write(0x44); //Manufacturer Block Read
Wire.endTransmission(true); //Repeated Start
Wire.requestFrom(BQ20Z45_Address, 1, true); //Setup Reading of Returned Data
len = Wire.read(); // length of the string thats about to return
len++; // plus one to allow for the length byte on the reread
// if len > 32 then the it will be truncated to 32 by requestFrom
len = Wire.requestFrom(BQ20Z45_Address, len, true); // readRequest returns # bytes actually read
len--; // we won't move the first 3 bytes as its not part of the string
len--;
len--;
if (len > 0)
{
Wire.read();
Wire.read();
Wire.read();
for (pos = 0; pos < len; pos++)
result[pos] = Wire.read();
}
result[pos] = '\0'; // append the zero terminator
return len;
}
/////////////////////////////////////////////////////////////////////////////
// Class Methods Below
int BQ20Z45::GaugingStatus(char *result)
{
return readStringB(BQ20Z45_GaugingStatus, result);
}
Now when I run the code below and view what happens on the Saleae Logic analyzer I see that the ReadStringB function correctly reads the status of function 0x0056 as shown in the screen shot below:

So the Gaguing Status is returned in these 2 lines:

This matches the data returned in the PC evaluation software as shown below:
Great! I have verified the ReadBlockB function successfully returns data for all the other block read functions also.
What I now need to do is to be able to update an individual variable based on the status of the individual bits in the returned status readings like what was returned for Gaguing status.
For example this is what the individual bits in the Gauging Status return stand for:
- How should I go about getting the successfully returned data from the ReadBlock command into a variable that I can then take and update the status of the individual items contained in the 16 individual bits?
I guess just having the 0x8540 store in a variable
would allow me to then create code that can read that varaible bit by bit and update the status of the 16 items those bits reffer to.
What do I need to change to get the
return to store in a variable called GaugeStatus?
Then I would just need to figure out how to read each bit of that variable and update the state of other variables.
Let me know if that makes sense or not. I think Iām on the right track but not sure 
Thanks taking the time to read this 