Skip to main content
LLoid.1
Associate
April 9, 2020
Question

The LIS3MDL magnetic data are 16bit left-justified. I deserialised the the Data to a int-16 value. How can I interprete the "left-justified" remark? Do I have to shift the Answer?

  • April 9, 2020
  • 1 reply
  • 592 views

..

    This topic has been closed for replies.

    1 reply

    Eleon BORLINI
    ST Employee
    April 9, 2020

    Hi @LLoid.1​ , please consider the example library an d driver on Github repository.

    In order to get physical units from register data content you have just to convert the 16-bit value obtained concatenating the two dataout registers into decimal value through two's complement conversion and then divide for the FullScale-related sensitivity

    /**
     * @defgroup LIS3MDL_Sensitivity
     * @brief These functions convert raw-data into engineering units.
     * @{
     *
     */
     
    float lis3mdl_from_fs4_to_gauss(int16_t lsb)
    {
     return ((float)lsb / 6842.0f);
    }
     
    float lis3mdl_from_fs8_to_gauss(int16_t lsb)
    {
     return ((float)lsb / 3421.0f);
    }
     
    float lis3mdl_from_fs12_to_gauss(int16_t lsb)
    {
     return ((float)lsb / 2281.0f);
    }
     
    float lis3mdl_from_fs16_to_gauss(int16_t lsb)
    {
     return ((float)lsb / 1711.0f);
    }

    Regards