cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DTW12 SENSOR IC

ggowd.1
Associate III

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);

}

13 REPLIES 13
ggowd.1
Associate III

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

z_g[gl_Sample_index] =( z / 4.0) * 0.488 ;

As told by you on 26th May, I have divided the data in LSB by 4 and then multiply by the sensitivity value. But I am reading 2000mg in z-axis but the actual value should be 1000mg.

Thanks

Federica Bossi
ST Employee

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

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
ggowd.1
Associate III

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

Hi Federica Bossi,

Please treat the above message as urgent and reply asap.