Skip to main content
WSpar.1
Associate III
September 28, 2020
Solved

LIS2HH12 and IIS2DLPC two's complement temp compared

  • September 28, 2020
  • 4 replies
  • 3545 views

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

This topic has been closed for replies.
Best answer by Eleon BORLINI

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

4 replies

Eleon BORLINI
ST Employee
September 29, 2020

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
WSpar.1Author
Associate III
September 29, 2020

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

Eleon BORLINI
ST Employee
September 29, 2020

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

WSpar.1
WSpar.1Author
Associate III
September 29, 2020

Yes just the room thermostat.

Is my bit shifting correct?

WSpar.1
WSpar.1Author
Associate III
April 19, 2021

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.

Eleon BORLINI
ST Employee
April 20, 2021

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

WSpar.1
WSpar.1Author
Associate III
April 20, 2021

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?

WSpar.1
WSpar.1Author
Associate III
April 20, 2021

Yes, so I have the onboard IIS2DLPC on SA0 = 3.3v (0x19 + R/W) and the Accel 13 click board on SA0 = GND (0x18 + R/W)

But both devices act the same.

Maybe I'm having an issue in I2C read implementation?

I can write, otherwise I would not be able to configure the chip.

Eleon BORLINI
Eleon BORLINIBest answer
ST Employee
April 21, 2021

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

WSpar.1
WSpar.1Author
Associate III
April 21, 2021

Ok that sounds promising.

I just tried to scope our project again, but now requesting the 0x26 8 bit register and turned on the scope option to show R/W bit in the decoder

The chip on this board gets its ODR setting etc.

0693W00000AM8SrQAL.png 

It returns 0xff or 0x00 nothing else.

Maybe my I2C read is not correct?

static int32_t platform_read(uint8_t reg, uint8_t *bufp, uint16_t len)
{
 
 //HAL_I2C_Mem_Read(handle, LIS2HH12_I2C_ADD_L, reg, I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
	if (len == 2)
	{
		bufp[0] = I2C_0_read1ByteRegister(IIS2DLPC_I2C_ADDRESS, reg);
		reg++;
		bufp[1] = I2C_0_read1ByteRegister(IIS2DLPC_I2C_ADDRESS, reg);
		
	} else {
		bufp[0] = I2C_0_read1ByteRegister(IIS2DLPC_I2C_ADDRESS, reg);
	}
	
	
	
 
 return 0;
}