hi, we are also using AD7414 chip on I2C to read the negative and positive temperature, we are facing problem for negative temperature, just see a glance tell the issue where it is in code. here I am sending snapshot of reading of negative temperature, please suggest the error:
Below functions is working fine for positive temperature but not negative temperature, please tell the where is the issue in negative temperature.
WORD Temperature_Value;
BYTE Low_Voltage_Value, High_Voltage_Value;
void VIDEO_Temperature(BYTE num[], BYTE k);
gmt_RET_STAT Read_Temperature(B_DevAddr)
{
gmt_RET_STAT W_Result;
BYTE B_TemperatureBuffer[2];
float temperature;
WORD Tempy;
W_Result = I2C_Dev_Write(B_DevAddr,0x00,0x00);
if(W_Result == FAILED)
{
return FAILED;
}
W_Result = I2C_Dev_Read(B_DevAddr,0x00, B_TemperatureBuffer, 2);
if(W_Result == FAILED)
{
return FAILED;
}
Tempy = TEMP_Decode(B_TemperatureBuffer);
Temperature_Value = Tempy;
return OK;
}
WORD TEMP_Decode(BYTE *Bp_Buf)
{
BYTE B_TemperaureBuffer[2];
WORD Tempy;
B_TemperaureBuffer[0] = Bp_Buf[0];
B_TemperaureBuffer[1] = Bp_Buf[1];
Tempy = B_TemperaureBuffer[0] & 0x00FF;
Tempy = Tempy << 2 ;
B_TemperaureBuffer[1] = B_TemperaureBuffer[1] >> 6 ;
B_TemperaureBuffer[1] &= 0x03;
Tempy |= B_TemperaureBuffer[1];
if(Tempy > 200)//negative temperaure, greater than 200(512)
{
Tempy = (Tempy-200)/4 ;
}
else // positive temprature
{
Tempy = (Tempy)/4 ;
}
return Tempy;
}
regards -- riya