cancel
Showing results for 
Search instead for 
Did you mean: 

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?

LLoid.1
Associate
 
1 REPLY 1
Eleon BORLINI
ST Employee

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