Skip to main content
Explorer II
August 1, 2023
Solved

LSM6DSL Linux driver, Temperature reading not implemented

  • August 1, 2023
  • 1 reply
  • 2095 views

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, 

 

 

    This topic has been closed for replies.
    Best answer by niccolò

    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ò

    1 reply

    ST Employee
    August 3, 2023

    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ò

    RAlma.1Author
    Explorer II
    August 5, 2023

    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,