2020-09-28 08:54 AM
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
Solved! Go to Solution.
2021-04-20 07:15 AM
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)
-Eleon
2021-04-20 09:54 AM
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.
2021-04-21 07:12 AM
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:
It returns 0x44 as expected.
But reading OUT_T 8bit temperature register returns always 0
BTW this is without configuring the device.
2021-04-21 07:38 AM
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
2021-04-21 07:42 AM
Hi @WSpar.1 ,
maybe the values you are receiving are correct... while the Github code calculation is wrong.
As reported in the datasheet:
So, basically you have to further divide
The conversion formula gives actually the following:
which looks a little more plausible for an ambient temperature...
I will report it internally...
-Eleon
2021-04-21 08:25 AM
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.
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;
}
2021-04-21 08:46 AM
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:
2021-04-21 09:16 AM
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
2021-04-21 09:23 AM
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?
2021-04-22 03:30 AM
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