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
Federica Bossi
ST Employee

Hi @ggowd.1​ ,

Could you write me the values (in hex or binary) of the registers from 28h to 2Dh?

Thanks

Federica

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,

28h = 0X34

29h = 0X00

2Ah= 0X6C

2Bh = 0XFB

2Ch= 0X0C

2Dh = 0X41

these is the value when the controller is pointed towards the sky.

can u confirm if the values are correct???

Federica Bossi
ST Employee

Hi @ggowd.1​ ,

Register 2Ch is certainly not correct since from datasheet the last two bits of the register should be '0':


_legacyfs_online_stmicro_images_0693W00000bkwnQQAQ.pngI also have some doubts about the outputs of the OUT_Y registers, how did you do the conversion from LSB to mg?

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,

Thank you for the reply. Can you let me know how to correct register 2Ch

Below is the code for OUT_Y register conversion from LSB to mg.

y =(int16_t)(out_t_y_h_data << 8) | out_t_y_l_data;

y_g[gl_Sample_index] = y * (4.0 / 32768.0 );

Federica Bossi
ST Employee

Hi @ggowd.1​ ,

Initially I was seeing different values of the registers, the answer had not updated after your change.

Can you confirm that you set FS=4g? Your data seems correct but if you set FS=2g and HP mode.

Also, your calculation is wrong, you should multiply the LSB value by the sensitivity value. If the sensor is in static position on the Z axis you should read about 1000mg.

If this solves your problem, please mark my answer as "Best Answer" by clicking on the "Select as Best" button, this can be helpful for Community users to find this solution faster :)

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,

Thank you for the reply. I have set for +-4g configuration and high performance mode and the calculation

z_g[gl_Sample_index] = z * (4.0 / 32768.0 ); instead of this i need use this formula

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

if i use this formula z_g[gl_Sample_index] = z / 4.0 *(32768.0 ); output will be in z axis 0.1241g

ggowd.1
Associate III

Hi Federica Bossi,

Please treat the above message as urgent and reply asap.

Thank you

Federica Bossi
ST Employee

Hi @ggowd.1​,

Where did you find this sensitivity value (32768.0)?

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.
Federica Bossi
ST Employee

To obtain a value about 1000mg on Z axis when the sensor is in a steady state you should multiply your output in LSB by sensitivity reported in Datasheet corresponding to your full scale and power mode:
_legacyfs_online_stmicro_images_0693W00000bl8NPQAY.pngLet me know if you read something near 1000mg.

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.