Had a question about the 2's complement conversion and the calculation described in equation 10 of the TMAG5273 datasheet and the implementation. I have a hard time verifying from the data itself whether the implementation is correct, but what I have is
//Holds bytes read over I2C
uint8_t temp[2]; // should be uint8_t or int8_t?
// 16 bit result
int16_t temp_mt;
//read out the data
temp[0] = I2C.readByte(); //MSB
temp[1] = I2C.readByte(); //LSB
// combine to make the 2's complement
temp_mt = ((temp[0] << 8) | temp[1]);
// equation 10
const uint8_t range = 40; // assuming for now range is 40
const float divisor = 32768; // 2^16 / 2
float B = temp_mt * range / divisor; // not sure if this is correct
I have a hard time verifying:
- whether the temp array should be uint or int.
- whether the 2's complement combination is correct
- how to implement the negative sign only on bit 15 of the data