Home        Store        Learn        Blog

Problem reading TSYS01 sensor

Hi all !

I’m trying to read this sensor with no succes. I need to use software I2C (to many risk with hardware one).
Here is my code:

#define TSY01_Adress 0xEE
#define TSY01_Reset 0x1E
#define TSY01_K0 0xAA
#define TSY01_K1 0xA8
#define TSY01_K2 0xA6
#define TSY01_K3 0xA4
#define TSY01_K4 0xA2
#define TSY01_ADC_Read 0x00
#define TSY01_ADC_Temp_Conv 0x48
#define TSY01_PROM_Read 0xA0

unsigned int TSYS01_K0;
unsigned int TSYS01_K1;
unsigned int TSYS01_K2;
unsigned int TSYS01_K3;
unsigned int TSYS01_K4;

unsigned int ReadK(char Adress)
{
unsigned int Result=0;

Soft_I2C_Start();
Soft_I2C_Write( TSY01_Adress  );
Soft_I2C_Write( TSY01_K0 );
//reading datas
Soft_I2C_Start();
Soft_I2C_Write( TSY01_Adress +1);
Result=(Soft_I2C_Read(1))<<8;
Result=Result+Soft_I2C_Read(0);
Soft_I2C_Stop();
delay_ms(10);

}

//------------------------------------------------------------------------------

void TSYS01_Init()
{
Soft_I2C_Start();
Soft_I2C_Write( TSY01_Adress );
Soft_I2C_Write( TSY01_Reset ); // 0b11110
Soft_I2C_Stop();
delay_ms(10);
// calibration reading
TSYS01_K0=ReadK(TSY01_K0);
TSYS01_K1=ReadK(TSY01_K1);
TSYS01_K2=ReadK(TSY01_K2);
TSYS01_K3=ReadK(TSY01_K3);
TSYS01_K4=ReadK(TSY01_K4);

}

//------------------------------------------------------------------------------

float TSYS01_ReadTemperature()
{
float Result=0;
unsigned ADC=0;

Soft_I2C_Start();
Soft_I2C_Write( TSY01_Adress );
Soft_I2C_Write( TSY01_ADC_Temp_Conv );
delay_ms(10); // (>8.2ms)
Soft_I2C_Write( TSY01_Adress);
Soft_I2C_Write( TSY01_ADC_Read );
Soft_I2C_Start();
Soft_I2C_Write( TSY01_Adress +1);

ADC=(Soft_I2C_Read(1))<<8;
ADC=(ADC+(Soft_I2C_Read(1)))<<8;
ADC=ADC+(Soft_I2C_Read(0));
ADC=ADC+(Soft_I2C_Read(0));
Soft_I2C_Stop();

Result = (-2.0)*TSYS01_K4*pow(10, -21)*pow(ADC, 4) +
            4.0 *TSYS01_K3*pow(10, -16)*pow(ADC, 3) +
            (-2.0)*TSYS01_K2*pow(10, -11)*pow(ADC, 2) +
            1.0*TSYS01_K1*pow(10, -6)*ADC +
            (-1.5)*TSYS01_K0*pow(10,-2);
            
return Result;

}