2023-08-01 02:57 AM
Hi Everyone,
Below Linux driver for LSM6DSL device has no method to read the temperature sensor.
https://elixir.bootlin.com/linux/latest/source/drivers/iio/imu/st_lsm6dsx
Is there a complete Linux driver which reads the temperature as well?
thanks,
Solved! Go to Solution.
2023-08-07 12:45 AM
Hi @RAlma.1 ,
the read_oneshot only reads one register at a time, so you should perform it for both registers and then use a int16_t variable to store the total output.
the stored value is a 2-complement number, that has to be divided by the temperature sensitivity, found in Table 5 of the datasheet, to get the degrees
as written in the application note, the temperature is expressed as the sum of 25 degree C and the value of the temperature sensor, so
Tout = 25 + (((OUT_TEMP_H<<8)|OUT_TEMP_L)/256)
(you can find examples in section 9.1 of the application note)
If this answers your question, please, mark this as "best answer", by clicking on the "accept as solution" to help the other users of the community
Niccolò
2023-08-03 02:33 AM
Hi @RAlma.1 ,
first of all, here https://github.com/torvalds/linux/tree/master/drivers/iio/imu/st_lsm6dsx you can find the official drivers on github (I'm not sure which version is the one you linked)
anyway the function to read the temperature is not present, but you can use the st_lsm6dsx_read_oneshot function reading the register with the temperature value (20h and 21h, you can find everything in the datasheet )
If this answers your question, please, mark this as "best answer", by clicking on the "accept as solution" to help the other users of the community
Niccolò
2023-08-05 04:54 AM
Hi @niccolò
thanks for your reply.
OUT_TEMP_L 0x20
OUT_TEMP_H 0x21
st_lsm6dsx_read_oneshot(sensor, OUT_TEMP_L , &temp), does it read both low and high registers in one call? or I need to call it for high register as well?
thanks,
2023-08-05 06:52 AM
Could you provide a scaling method for the raw data
2023-08-07 12:45 AM
Hi @RAlma.1 ,
the read_oneshot only reads one register at a time, so you should perform it for both registers and then use a int16_t variable to store the total output.
the stored value is a 2-complement number, that has to be divided by the temperature sensitivity, found in Table 5 of the datasheet, to get the degrees
as written in the application note, the temperature is expressed as the sum of 25 degree C and the value of the temperature sensor, so
Tout = 25 + (((OUT_TEMP_H<<8)|OUT_TEMP_L)/256)
(you can find examples in section 9.1 of the application note)
If this answers your question, please, mark this as "best answer", by clicking on the "accept as solution" to help the other users of the community
Niccolò