Skip to main content
Visitor II
May 25, 2023
Question

LIS2DTW12 SENSOR IC

  • May 25, 2023
  • 12 replies
  • 2561 views

Dear Sir/Madam,

I am trying to configure x axis, y axis and z axis in LIS2DTW12 SENSOR IC interfacing with NUCLEO-L476RG microcontroller when board is towards sky direction. These are the values in z axis1.26 in (+-2g configuration), 2.046 in (+-4g configuration) ,4.125 in (+-8g configuration) and8.254 in (+-16g configuration). Can you conform if the above values are correct?

Find the code below for your reference.

lis2dtw12_device_id_get(&dev_ctx, &whoamI);

   if (whoamI != LIS2DTW12_ID)

    while (1) {

     /* manage here device not found */

    }

  /* Configure power mode */

    lis2dtw12_power_mode_set(&dev_ctx, LIS2DTW12_HIGH_PERFORMANCE);

  /* Set Output Data Rate */

    lis2dtw12_data_rate_set(&dev_ctx, LIS2DTW12_XL_ODR_1k6Hz);

   /* Set full scale */

    lis2dtw12_full_scale_set(&dev_ctx, LIS2DTW12_4g);

   /* Configure FIFO continous mode */

   lis2dtw12_fifo_mode_set(&dev_ctx, LIS2DTW12_BYPASS_MODE);

   /* Configure FIFO continous mode */

    lis2dtw12_fifo_watermark_set(&dev_ctx, 10);

    lis2dtw12_fifo_mode_set(&dev_ctx, LIS2DTW12_STREAM_MODE);

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

 uint8_t val,i,val_1;

 lis2dtw12_fifo_wtm_flag_get(&dev_ctx, &val);

if(val)

{

lis2dtw12_fifo_data_level_get(&dev_ctx, &val);

gl_Sample_Count = val+gl_Sample_index;

for (i = gl_Sample_index; i < gl_Sample_Count; i++) {

  /* Read acceleration data */

memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));

lis2dtw12_acceleration_raw_get(&dev_ctx, data_raw_acceleration);

acceleration_mg_x[gl_Sample_index] = lis2dtw12_from_fs4_to_mg(data_raw_acceleration[0]);

acceleration_mg_y[gl_Sample_index] = lis2dtw12_from_fs4_to_mg(data_raw_acceleration[1]);

acceleration_mg_z[gl_Sample_index] = lis2dtw12_from_fs4_to_mg(data_raw_acceleration[2]);

gl_Sample_index++;

if(gl_Sample_index >= 1023)

{

gl_Sample_index = 0;

//lis2dtw12_fifo_data_level_get(&dev_ctx, &val);

}

//lis2dtw12_fifo_data_level_get(&dev_ctx, &val);

  }

  }

lis2dtw12_fifo_ovr_flag_get(&dev_ctx, &val_1);

if(val_1)

{

lis2dtw12_fifo_mode_set(&dev_ctx, LIS2DTW12_BYPASS_MODE);

lis2dtw12_fifo_mode_set(&dev_ctx, LIS2DTW12_STREAM_MODE);

}

    This topic has been closed for replies.

    12 replies

    Technical Moderator
    June 1, 2023

    Hi @ggowd.1​ ,

    First you don't have to divide by 4, just multiply the value in LSB by the sensitivity given on datasheet.

    Then, can you give me the values you write in registers 20h and 25h?

    Thanks

    ggowd.1Author
    Visitor II
    June 1, 2023

    Hi Federica Bossi,

    z =(int16_t)(out_t_z_h_data << 8) | out_t_z_l_data;

    z_g[gl_Sample_index] = z * 0.488 ;

    8227.67969 is the value after multiply the value in LSB by the sensitivity given on datasheet.

    Below are the values of registers:

    20h-=0x94;

    25h=0x10;

    Thanks

    ggowd.1Author
    Visitor II
    June 7, 2023

    Hi Federica Bossi,

    Please treat the above message as urgent and reply asap.