2023-05-25 12:19 AM
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);
}
2023-05-26 01:42 AM
Hi @ggowd.1 ,
Could you write me the values (in hex or binary) of the registers from 28h to 2Dh?
Thanks
Federica
2023-05-26 02:51 AM
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???
2023-05-26 05:18 AM - edited 2023-11-20 04:38 AM
Hi @ggowd.1 ,
Register 2Ch is certainly not correct since from datasheet the last two bits of the register should be '0':
I also have some doubts about the outputs of the OUT_Y registers, how did you do the conversion from LSB to mg?
Thanks
2023-05-26 05:41 AM
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 << 😎 | out_t_y_l_data;
y_g[gl_Sample_index] = y * (4.0 / 32768.0 );
2023-05-26 06:26 AM
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 🙂
2023-05-26 09:39 PM
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
2023-05-30 04:06 AM
2023-05-30 04:27 AM
Hi @ggowd.1,
Where did you find this sensitivity value (32768.0)?
2023-05-30 04:32 AM - edited 2023-11-20 04:38 AM
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:Let me know if you read something near 1000mg.