cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DTW12 IC of z axis acceleration in FIFO mode

ggowd.1
Associate III

Hello

I would like to configure for z axis acceleration in LIS2DTW12 IC and read the data in FIFO mode. Kindly take a look at the below code for which i have configured as FIFO mode and 5 samples of data in that. let me know any correction!

int main() 

{

InitialiseHardware();

InitialiseModules();             

whoamI = I2C1_ReadRegister(who_i_am);  /* Check device ID */

if(whoamI != LIS2DTW12_ID)

while (1) {

   /* manage here device not found */

  }

// v1 = I2C1_ReadRegister(0x21);

I2C_WriteRegister(SLAVE_ADDR, 0x20, 0x60); /* set ODR 4000hz in ctrl1*/

I2C_WriteRegister(SLAVE_ADDR, 0x25, 0x10); /* set 4g in ctrl6 */

I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0x25); /* fifo mode and 5 samples */

// reg.fth = 10;

//lis2dtw12_full_scale_set(&dev_ctx, LIS2DTW12_2g);

// lis2dtw12_filter_path_set(&dev_ctx, LIS2DTW12_LPF_ON_OUT);

/* Infinite loop */

while(1)

{

I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0x25); /* fifo mode */

out_t_z_l_data = I2C1_ReadRegister(0x2C);

out_t_z_h_data = I2C1_ReadRegister(0x2D);

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

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

index++;

if(index >= 5)

{

index=0;

for(fl_i = 0; fl_i >= 32 ; fl_i++)

{

z_g[fl_i] = 0;

}

I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0x00); /* fifo mode */

I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0x25); /* fifo mode */

}

1 ACCEPTED SOLUTION

Accepted Solutions
Federica Bossi
ST Employee

Hi @ggowd.1​ ,

Please follow the steps reported in our PID.

If you write two times in the same reg you are overwriting the previous value, you need to make a mask in order to enable only the bits you need.

For example, if you want to set ODR 1600Hz and high_performance mode in ctrl1, you need to write 94h in reg 20h. Please follow the same recommendation also for reg 25h and 2Eh.

If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer 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.

View solution in original post

5 REPLIES 5
Federica Bossi
ST Employee

Hi @ggowd.1​ ,

Have you already look at our PID on Github?

In addition, if you are using a STEVAL-MKI190V1, here you can find an example that shows you how to get data from sensor FIFO. In case you have a different hardware, you could use it as a starting point.

If my reply helps you, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer 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

Hii Federica Bossi,

Thank you for Answer.

I have done interfacing between LIS2DTW12 sensor along with STM32F103RCT6 microcontroller, here I am using I2C peripherals to communicate between them. I would like to configure 1600hz frequency and high-performance mode in LIS2DTW12.I have configured 400khz frequency in STM32F103RCT6 microcontroller. But it's not working, kindly help me out. Where i am wrong.

Kindly go throw the code below.

int main()  

{

InitialiseHardware();

InitialiseModules();

//USART1_Configuration(BaudRate_36Mhz_9600ps);

//Startupwait(2.0);

//I2C_WriteRegister(SLAVE_ADDR, CTRL1_ADDR, ctrl1_data);              //FUNCTION STAND FOR MASS ERASE 

whoamI = I2C1_ReadRegister(who_i_am);   /* Check device ID */

if(whoamI != LIS2DTW12_ID)

while (1) {

    /* manage here device not found */

   }

// v1 = I2C1_ReadRegister(0x21);

I2C_WriteRegister(SLAVE_ADDR, 0x21, 0x08); /* set bdu in ctrl1 */

I2C_WriteRegister(SLAVE_ADDR, 0x20, 0x90);  /* set ODR 1600hz in ctrl1*/

I2C_WriteRegister(SLAVE_ADDR, 0x25, 0x10);  /* set 4g in ctrl6 */

I2C_WriteRegister(SLAVE_ADDR, 0x25, 0x00);  /* set low_pass_filter in ctrl6 */

I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0x00);  /* Bypasso mode */

I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0xCA);  /* fifo mode */

I2C_WriteRegister(SLAVE_ADDR, 0x20, 0x04);  /* set high_performance mode in ctrl1 */

I2C_WriteRegister(SLAVE_ADDR, 0x3F, 0x10); /* set USR_OFF_ON_OUT in ctrl7 */

/* Infinite loop */

while(1)

{

MB1_process();

FIFO_Status.byte.Status = I2C1_ReadRegister(0x2F);

if((FIFO_Status.byte.bit.FIFO_FTH == 1) && (FIFO_Status.byte.bit.FIFO_OVR == 0))

{

__nop();

l_UnreadSamples = FIFO_Status.byte.bit.UnreadSamples ;

gl_Sample_Count = l_UnreadSamples + gl_Sample_index; 

for(fl_i = gl_Sample_index; fl_i < gl_Sample_Count ; fl_i++)

{

out_t_z_l_data = I2C1_ReadRegister(0x2C);

out_t_z_h_data = I2C1_ReadRegister(0x2D);

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

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

gl_Sample_index++;

}

if(gl_Sample_index >= 1024)

{

  //I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0x00);  /* Bypasso mode */

//gl_Sample_index = 0;

// I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0x00);

gl_Sample_index = 0;

FIFO_Status.byte.Status = I2C1_ReadRegister(0x2F);

__nop();

}

FIFO_Status.byte.Status = I2C1_ReadRegister(0x2F);

__nop();

}

else if (FIFO_Status.byte.bit.FIFO_OVR == 1)

{

__nop();

I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0x00);  /* Bypasso mode */

I2C_WriteRegister(SLAVE_ADDR, 0x2E, 0xCA);  /* fifo mode */

}

Federica Bossi
ST Employee

Hi @ggowd.1​ ,

Please follow the steps reported in our PID.

If you write two times in the same reg you are overwriting the previous value, you need to make a mask in order to enable only the bits you need.

For example, if you want to set ODR 1600Hz and high_performance mode in ctrl1, you need to write 94h in reg 20h. Please follow the same recommendation also for reg 25h and 2Eh.

If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer 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.

Hii Federica Bossi,

Thank you for Answer.

I have tried for single tap detection in acceleration on LIS2DTW12 IC but i am unable detect the tap but i am getting 0x41 in below code in variable "V" without tapping on this LIS2DTW12 IC along withSTM32F10RCT6 Microcontroller

Please find the code below for your reference

whoamI = I2C1_ReadRegister(who_i_am);   /* Check device ID */

if(whoamI != LIS2DTW12_ID)

while (1) {

    /* manage here device not found */

   }

// v1 = I2C1_ReadRegister(0x21);

I2C_WriteRegister(SLAVE_ADDR, 0x20, 0x60);  /* set 200hz in ctrl1 */

I2C_WriteRegister(SLAVE_ADDR, 0x25, 0x00);  /* set ODR 2g in ctrl6*/

I2C_WriteRegister(SLAVE_ADDR, 0x32, 0xEA);  /* set x axis y axis z axis and thershold level of z */

I2C_WriteRegister(SLAVE_ADDR, 0x30, 0x0A);  /* set thershold level of x axis */

I2C_WriteRegister(SLAVE_ADDR, 0x31, 0xAA);  /* set thershold level of y axis*/

I2C_WriteRegister(SLAVE_ADDR, 0x33, 0x05);  /* set queit shock in Interrupt duration register*/

I2C_WriteRegister(SLAVE_ADDR, 0x34, 0x00);   /* set signal tap in wake up register  */

I2C_WriteRegister(SLAVE_ADDR, 0x23, 0x40);   /* set signal tap34p[]\7dfjklm,./in wake up register  */

/* Infinite loop */

while(1)

{

//MB1_process();

v = I2C1_ReadRegister(0x37);

Hi @ggowd.1​ ,

Please for TAP Functions refer to our PID :)

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.