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

19 REPLIES 19

Hi @WSpar.1​ ,

I'm wondering if the de-codification is correct... I mean, is the I2C address the right one?

The blue pattern looks like it is on a different scale than the yellow one...

Do you have two different SA0 pin configuration? (now the value is 18h, before was 19h)

0693W00000AM0F1QAL.png-Eleon

WSpar.1
Associate III

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.

Hi Eleon,

I connected now the Accel 13 board to a bus pirate tool.

So everything is proven hardware.

Reading the who_am_i register goes fine:

0693W00000AM7ssQAD.jpgIt returns 0x44 as expected.

But reading OUT_T 8bit temperature register returns always 0

0693W00000AM7uKQAT.jpg 

BTW this is without configuring the device.

Hi @WSpar.1​ ,

to get temperature values from the sensor, you have to configure at least the ODR, in the CTRL1 (20h) register.

This will tell the internal clock tree the down-sampling: otherwise you'll get only zeros.

-Eleon

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

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;
}

I think you might be correct here

temp6 = (temp6 / 16 / 16) + 25;

I'm now printing stable 25 degrees (should be around 19) and with freeze spray -15.

maybe for the 8bit register you have to be in low power mode or something?

[UPDATE]

Oh wait when reading 0x26 8bit register, it flips perfectly around 0x00 0xff the midpoint.

Makes sense.

I guess it is harder to debug in labs that are around 25 degrees :squinting_face_with_tongue:

Ya, it could be that you have the MSB at FFh, meaning -1 in two's complement.

To configure the 8-bit resolution you have to set the low power modes, that are selected by writing the LP_MODE[1:0] bits in CTRL1 (20h).

-Eleon

So conclusion is probably that github code is wrong?

It is somehow working, only a bit high.

I noticed the datasheet mention temperature offset of +- 15 degrees.

This is different for every chip?

Ya, apparently it is wrong.

I would suggest you to "characterize" the ambient temperature offset, especially if you can compare it with a reference thermometer.

The +-15°C is the maximum range for the offset, but usually it is below 2/3°C at ambient temperature.

-Eleon