cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2HH12 and IIS2DLPC two's complement temp compared

WSpar.1
Associate III

Hi all,

I'm currently deploying hardware that can have either the LIS2HH12 or IIS2DLPC

According to the datasheet the LIS2HH12 stores the temperature as two's complement / 11 bit / 8 digit per degrees celcius.

So I convert it this way:

int16_t tilt_read_temp(void)
{
	uint8_t temperature[2];
	int32_t temp;
 
	lis2hh12_temperature_raw_get(&dev_ctx, temperature);
 
	temp = (temperature[1] << 8) | temperature[0];
	temp = temp>>5;
	temp = ((temp * 125) / 10) + 2500;
	temp = temp / 10;
	
	return temp;
}

This gives me 211 my notation for 21.1 degrees

The other sensor IIS2DLPC should be 12 bits, two's complement 16 lsb per degrees celcius.

So I convert that one as:

int16_t tilt_read_temp(void)
{
	uint8_t temperature[2];
	int32_t temp;
 
	iis2dlpc_temperature_raw_get(&dev_ctx, temperature);
 
	temp = (temperature[1] << 8) | temperature[0];
	temp = temp>>4;
	temp = ((temp * 625) / 100) + 2500;
	temp = temp / 10;
	
	return temp;
}

But this one returns 273, my notation for 27.3 degrees celcius.

Both boards are in the same room and I think 21 degrees is most likely the temperature in the room.

Am I converting the last one wrong?

 BTW: I'm running both on 3.3v supply

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @WSpar.1​ ,

maybe the values you are receiving are correct... while the Github code calculation is wrong.

As reported in the datasheet:

0693W00000AM89AQAT.png0693W00000AM89KQAT.pngSo, basically you have to further divide

The conversion formula gives actually the following:

  • 0230h --> two's complement --> 608dec --> conversion formula with further /16 division taking into account the sensitivity --> 2.375 + 25 deg = 27.375 deg

which looks a little more plausible for an ambient temperature...

I will report it internally...

-Eleon

View solution in original post

19 REPLIES 19
Eleon BORLINI
ST Employee

Hi @WSpar.1​ ,

do you have the possibility to compare the temperature measure from other similar devices?

Btw, your temperature decoding seems ok, comparing it also with the ST C drivers on Github

For example for the LIS2HH12 you have (lis2hh12_reg.c):

float_t lis2hh12_from_lsb_to_celsius(int16_t lsb)
{
  return (((float_t)lsb / 8.0f) + 25.0f);
}

While for the IIS2DLPC (iis2dlpc_reg.c):

float_t iis2dlpc_from_lsb_to_celsius(int16_t lsb)
{
  return (((float_t)lsb / 16.0f) + 25.0f);
}

I agree with you that the 21°C is most probably the correct value, considering also that, as reported in the IIS2DLPC datasheet, there could be a temperature offset of a few degrees.

0693W000004I7UoQAK.png

-Eleon

WSpar.1
Associate III

Yes a 3th device measured around 21 degrees.

I noticed both datasheet have the 25 degrees / 0 LSB point measured with different supply voltage.

One is measured with 1.8v and the other 2.5v supply voltage

The 3rd device is another LIS2HH12, an IIS2DLPC  or an external reference?

Ps: there should not be such a dependency of the temperature with the power supply voltage...

-Eleon

Yes just the room thermostat.

Is my bit shifting correct?

It should, but please try also with the other two formulas.

Tks

-Eleon

WSpar.1
Associate III

0693W000008zzQTQAY.jpg 

Can someone help me out to what degrees of Celsius this should convert?

My code converts this into somewhere around 60 degrees (didn't log it exactly)

When reading the temperature every 500 ms, I'm seeing massive jumps from 34 to 58 degrees.

Hi @WSpar.1​ ,

did you already tried with the above formulas?

Are you facing this issue for both the sensors in the title of this post?

I'm supposing that the refer to IIS2DLPC device, since the temperature registers are 0D and 0E.

The conversion formula gives actually the following:

  • 0230h --> two's complement --> 608dec --> conversion formula --> 38 + 25 deg

That is indeed a little high if you are measuring ambient temperature...

Can you also have the possibility to test other similar devices?

-Eleon

Hi Eleon,

LIS2HH12 is not part of our design anymore, because it had 0 stock.

Now we are facing the same stock issues with IIS2DLPC but it should still be in production.

I tried many formulas but the result didn't make any sense.

That is why I moved to scope measurements to be sure it is not a software issue.

On ambient temperature the IIS2DLPC replies with 0230h, and when I hold my finger on the chip I see register 0E increasing to 05, 06

Does manually heat solder this chip easily damage the internal temperature sensor?

Or did I maybe forget to configure the chip properly?

Hi Eleon,

I connected a Accel Click board to our device (https://www.mikroe.com/accel-13-click)

These boards are professionally reflowed and is on a different address.

0693W00000ALyo8QAD.jpg 

So also very high temperature and fluctuating heavily.