cancel
Showing results for 
Search instead for 
Did you mean: 

HTS221 can't return humidity values below 32%

RKrau.8
Associate

Hello,

I got the problem, that the humidity sensor can't return values below 32.

My code is the same like in the documentation (only in C): https://www.st.com/content/ccc/resource/technical/document/technical_note/group0/82/97/c8/ab/c6/da/41/ed/DM00208001/files/DM00208001.pdf/jcr:content/translations/en.DM00208001.pdf

/* read coefficients */
 
int _H0_rH_x2, _H1_rH_x2, _H0_T0_OUT, _H1_T0_OUT;
 
        _H0_rH_x2 = i2c_read_register(address,0x30);
        _H1_rH_x2 = i2c_read_register(address,0x31);
 
        _H0_T0_OUT = i2c_read_register(address,0x37) <<8;
        _H0_T0_OUT |= i2c_read_register(address,0x36);
 
        _H1_T0_OUT = i2c_read_register(address,0x3b) <<8;
        _H1_T0_OUT |= i2c_read_register(address,0x3a);
 
/* calculate humidity */
 
unsigned conversation_status = 0;
        int H_OUT;
        int t_H0_rH, t_H1_rH;
        int humidity_ = 0;
        unsigned humidity;
 
        if(!i2c_humidity_sensor_status(address)){
 
            H_OUT = (unsigned int)i2c_read_register(address,0x29) <<8;
            H_OUT |= (unsigned int)i2c_read_register(address,0x28);
 
            printf("H_OUT 0x29 : %d\n", i2c_read_register(address,0x29));
            printf("H_OUT 0x28 : %d\n", i2c_read_register(address,0x28));
 
            t_H0_rH = _H0_rH_x2>>1;         //divided by 2
            t_H1_rH = _H1_rH_x2>>1;         //divided by 2
 
            humidity_ = ((int)(H_OUT - _H0_T0_OUT)) * ((int)(t_H1_rH - t_H0_rH));
            humidity_ = (int)(humidity_ / (int)(_H1_T0_OUT - _H0_T0_OUT) + t_H0_rH);
 
            printf("H_OUT: %d \nt_H0_rH: %d \nt_H1_rH: %d \n_H0_T0_OUT: %d \n_H1_T0_OUT: %d \n", H_OUT,t_H0_rH,t_H1_rH,_H0_T0_OUT, _H1_T0_OUT );
 
            printf("humidity: %d\n", humidity_);
            humidity = (unsigned)humidity_;
            if (humidity > 100){
                humidity = 100;
            }
            return humidity;
        } else {
            printf("No data available!\n\n");
            return 101;
        }

My output is this:

H_OUT 0x29 : 254

H_OUT 0x28 : 102

H_OUT: 65126

H0_rH: 32

H1_rH: 70

_H0_T0_OUT: 65529

_H1_T0_OUT: 52304

humidity: 33

humidity: 33 %

H_OUT 0x29 : 255

H_OUT 0x28 : 20

H_OUT: 65300

H0_rH: 32

H1_rH: 70

_H0_T0_OUT: 65529

_H1_T0_OUT: 52304

humidity: 32

humidity: 32 %

H_OUT 0x29 : 0

H_OUT 0x28 : 34

H_OUT: 34

H0_rH: 32

H1_rH: 70

_H0_T0_OUT: 65529

_H1_T0_OUT: 52304

humidity: 220

humidity: 100 %

H_OUT 0x29 : 0

H_OUT 0x28 : 87

H_OUT: 87

H0_rH: 32

H1_rH: 70

_H0_T0_OUT: 65529

_H1_T0_OUT: 52304

humidity: 220

humidity: 100 %

H_OUT 0x29 : 1

H_OUT 0x28 : 104

H_OUT: 360

H0_rH: 32

H1_rH: 70

H0_T0_OUT: 65529

H1_T0_OUT: 52304

humidity: 219

humidity: 100 %

H_OUT 0x29 : 2

H_OUT 0x28 : 7

H_OUT: 519

H0_rH: 32

H1_rH: 70

_H0_T0_OUT: 65529

_H1_T0_OUT: 52304

humidity: 218

humidity: 100 %

The register value from H_OUT drops from 6500 to ~ 0.

I see the same on my oscilloscope, how is the possible ?

1 REPLY 1
Eleon BORLINI
ST Employee

HI @RKrau.8​ , did you consider that H_OUT 0x29 (MSB) + H_OUT 0x28 (LSB) has to be decoded in two's complement? H_OUT 0x29 : 255 means -1 and H_OUT 0x29 : 0 is 0. I think you just have to set the two's complement conversion. Regards