Skip to main content
Visitor II
April 5, 2023
Solved

Regarding the Lis2dtw12

  • April 5, 2023
  • 4 replies
  • 1398 views

Dear Sir\Madam

I have been using steval-mki190v1 (LIS2DTW12 IC), Trying to communicate through I2C with STM32F103RCT6  microcontroller in LIS2DTW12 IC by default how does it act SPI or I2C. Let me know how to configure the I2C pin configuration of LIS2DTW12 communication with the STM32F103RCT6 microcontroller.   

Best regards,

Gagan Gowda

Embedded Engineer

    This topic has been closed for replies.
    Best answer by Federica Bossi

    Hi @ggowd.1​ ,

    The i2c protocol on the LIS2DTW12 is enabled by keeping the CS pin (pin2) high. 

    then, you need to send an i2c command with one of the two device address. 

    the device address is either 0x30 or 0x32 and can be selected by keeping the SA0 pin (pin3) high or low respectively.

    Refer to chapter 6.1.1 of the datasheet for more informations about this. 

    The WHO_AM_I register reports 0x44.

    For example, assuming you're using an STM32, the i2c1 interface and SA0 is low 

    #define SAD 0x30

    uint8_t who_am_i;

    HAL_I2C_Mem_Read(&hi2c1, SAD, 0x0f, 1, &who_am_i, 1, 0xff);

    For more example and reference code you can look at the official repository:

    GitHub - STMicroelectronics/lis2dtw12-pid: lis2dtw12 platform independent driver based on Standard C language and compliant with MISRA standard

    4 replies

    Technical Moderator
    April 7, 2023

    Hi @ggowd.1​ ,

    Welcome to ST Community!

    Using the utility STM32CubeMX you need to select the i2c peripheral under connectivity:
    _legacyfs_online_stmicro_images_0693W00000bhitYQAQ.png 

    Bear in mind that you need pull-ups on the SCL and SDA lanes.

    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!

    ggowd.1Author
    Visitor II
    April 8, 2023

    Hii Federica Bossi,

    I am asking u how to configure the LIS2DTW12 sensor IC using i2c peripherals. And if I send who_i_am_register 0x0f what will be response from LIS2DTW12 sensor IC

    Technical Moderator
    April 11, 2023

    Hi @ggowd.1​ ,

    The i2c protocol on the LIS2DTW12 is enabled by keeping the CS pin (pin2) high. 

    then, you need to send an i2c command with one of the two device address. 

    the device address is either 0x30 or 0x32 and can be selected by keeping the SA0 pin (pin3) high or low respectively.

    Refer to chapter 6.1.1 of the datasheet for more informations about this. 

    The WHO_AM_I register reports 0x44.

    For example, assuming you're using an STM32, the i2c1 interface and SA0 is low 

    #define SAD 0x30

    uint8_t who_am_i;

    HAL_I2C_Mem_Read(&hi2c1, SAD, 0x0f, 1, &who_am_i, 1, 0xff);

    For more example and reference code you can look at the official repository:

    GitHub - STMicroelectronics/lis2dtw12-pid: lis2dtw12 platform independent driver based on Standard C language and compliant with MISRA standard

    ggowd.1Author
    Visitor II
    April 24, 2023

    Hii Federica Bossi,

    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 */

    }