@peekay123 Just trying to adjust the conversion now, so that it yields a correct reading. In 12-bit mode, in the response, byte 0 is (MSB)XXXX SDDD(LSB) and byte 1 is DDDD DDDD, where 'X' bits are ignored, 'S' is the sign bit and 'D' bits are the data.
The interface board I'm using has an Op-Amp which means it can accept a larger voltage range. On the datasheet, they give the equation to convert the binary 'code' received into a voltage, as follows:
V = (code/2047)(2.048/PGA)(180/33).
I've modified the 'switch' case in the library to realise this equation, but it's just returning zeros. I'd originally placed the values straight in-line, but decided to define them 'long' so that all arithmetic operations used the same type. I'll comment each line so you can see my understanding:
_resultat = _Buffer; //originally assigning _resultat to the first byte
_resultat&=0b00001111; //ANDING this to 'mask' the unwanted bits
_resultat = _resultat << 8; //Shifting 8 bits in the MSB direction
_resultat |= _Buffer; //OR to add byte 1 to the end of the first byte
_resultat=_resultat-4096-1; //not sure what this bit is
long maxCode = 2047;
long vRef = 2.048;
long invGain = (180/33); //all from datasheet
_resultat = (_resultat/maxCode)*(vRef/_PGA)*invGain; //equation from datasheet
If I just return 'resultat' before doing this last arithmetic calculation, it yields the pure binary code. If I work out the equation on pen and paper, it works out! FYI _resultat is of 'long' type and _Buffer and _PGA are 'uint8'