temperature

This commit is contained in:
William Clark 2023-12-31 15:41:24 +00:00
parent 70dd2c9a1b
commit 432bf4d421
3 changed files with 24 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "lis3dh.h"
#include "registers.h"
@ -412,3 +413,18 @@ int lis3dh_read_adc(lis3dh_t *lis3dh) {
return err;
}
/* the temperature sensor only reports the difference between its current temp,
and the factory calibrated temperature, 25 celsius.
in increments of plus or negative 1 unit celsius.
the reported temperature is stored inplace of adc3
temp sensing is always in 8-bit mode
operating range: -40 to 85 celsius */
int lis3dh_read_temp(lis3dh_t *lis3dh) {
uint8_t data[2];
int err = 0;
err |= lis3dh->dev.read(REG_OUT_ADC3_L | 0x80, data, 2);
lis3dh->adc.adc3 = (float)((int16_t)(data[1] | (data[0] << 8)) >> 8) + 25.0;
return err;
}

View File

@ -225,5 +225,6 @@ int lis3dh_clear_int2(lis3dh_t *lis3dh);
int lis3dh_reference(lis3dh_t *lis3dh);
int lis3dh_reset(lis3dh_t *lis3dh);
int lis3dh_read_adc(lis3dh_t *lis3dh);
int lis3dh_read_temp(lis3dh_t *lis3dh);
#endif

6
main.c
View File

@ -62,6 +62,7 @@ int main() {
lis.cfg.filter.cutoff = LIS3DH_FILTER_CUTOFF_8;
lis.cfg.en_adc = 1;
lis.cfg.en_temp = 1;
/* write device config */
if (lis3dh_configure(&lis)) {
@ -89,6 +90,11 @@ int main() {
quit("read_adc()", &lis);
}
/* read temp from ADC3 and overwrite local ADC reading for ADC3 */
if (lis3dh_read_temp(&lis)) {
quit("read_temp()", &lis);
}
for(k=0; k<fifo.size; k++) {
printf("x: %04.04f y: %04.04f z: %04.04f mag: %04.04f ADC1:%.1f, ADC2:%.1f, ADC3:%.1f\n",
fifo.x[k], fifo.y[k], fifo.z[k],