Bug in lis2dh temperature reading
Closed this issue · 1 comments
Hi,
I am trying to make sense of MG100 GW and having a problem where battery voltage is rubbish. This seems to be because it is compensated using temperature measured from LIS2DH and that temperature is sometimes hundreds of degrees.
Temperature measurement seems to be very poorly documented by ST, but I believe that relative temperature might be signed. I added some debug logs to here in the driver and I observe for example something like this:
[00:00:09.667,236] <err> lis2dh: raw temp=253
[00:00:09.667,236] <wrn> lc_battery: Temperature: 278.0
and
[00:02:46.506,866] <err> lis2dh: raw temp=2
[00:02:46.506,866] <wrn> lc_battery: Temperature: 27.0
So, I believe changing
lis2dh->temp_sample = TEMP_REFERENCE + temp_raw[1];
to
lis2dh->temp_sample = TEMP_REFERENCE + (int8_t)temp_raw[1];
in here:
https://github.com/LairdCP/zephyr_lib/blob/master/drivers/mg100_lis2dh/mg100_lis2dh.c#L80
might be a good idea. Without that, nothing works in under 25C temperatures. Cheers.
Hi,
Ran into the same issue on my end, datasheet 2.1.1 for the LIS2DH states:
"Temperature data is stored inside OUT_TEMP_H as 2’s complement data in 8 bit format left justified."
Looking at section 2.2 it says 8 bit resolution, with -40 to 85C.
This forum provides a little more insight into the temperature format for the lis2dh
Thanks for saving me debugging time, I'll go ahead and create a PR for the fix.