I am trying to communicate with AT30TS75A-MA8M-T with below code, the problem is converting the 16 bit output to float so I can read temp:
Base on data sheet
I suppose to remove first 5 bit in order to read correctly but I am not converting it correctly.
Ex: (0b001001001100000 AND 0 b0111111111100000) = 0b1001001100000 0b1001001100000 >> 5 = 0b10010011 = 147
void Atemp::begin()
{
Wire.begin();
// Check if sensor temp sensor is avilable
// if (mySensor.beginI2C() == false)
// {
// data[9] = 5; // Error Code
// }
// Set registor for two decimal
Wire.beginTransmission(_i2cAddress);
Wire.write(1);
Wire.write(0b01100000);
Wire.endTransmission();
}
void Atemp::read()
{
Wire.beginTransmission(_i2cAddress);
Wire.write(0);
result = Wire.endTransmission();
// result is 0-4
if (result != 0)
{
data[9] = 5; // Error Code
}
result = Wire.requestFrom(_i2cAddress, (uint8_t)2);
if (result != 2)
{
data[9] = 5; // Error Code
}
else
{
uint8_t part1 = Wire.read();
uint8_t part2 = Wire.read();
data[7] = part1;
data[8] = part2;
int16_t rawval = (part1 << 8 | part2) ;
// rawval >>= 6;
float temp = rawval / 256.0f;
floatconv(temp);
}
}
The resolution of the temperature measurement data can be configured to 9, 10, 11, or 12 bits which corresponds to temperature increments of 0.5̊C, 0.25̊C, 0.125̊C, and 0.0625̊C, respectively.– Majenko Aug 18 '22 at 21:33