cancel
Showing results for 
Search instead for 
Did you mean: 

LSM6DSL Linux driver, Temperature reading not implemented

RAlma.1
Associate III

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, 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

niccol_0-1691393976248.png

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ò

View solution in original post

4 REPLIES 4
niccolò
ST Employee

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ò

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,

 

Could you provide a scaling method for the raw data

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

niccol_0-1691393976248.png

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ò