cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DW12TR Accelerometer X, Y, Z values always return 0

NWang.1
Associate II

Hi ,guys:

I have use the following code to read accelerometer data but the sensor data X, Y, Z are always 0 and I check register WHO_AM_I and it is quite correct. And I also check Status register but the DRDY always 0(means Sensor data not ready).

uint8_t rst;
        float acceleration_mg[3];
        int16_t data_raw_acceleration[3];
        /* Check device ID */
        lis2dw12_device_id_get(ctx, &wai);
 
        if (wai != LIS2DW12_ID)
        while (1) {
        /* manage here device not found */
        }
 
        /* Restore default configuration */
        lis2dw12_reset_set(ctx, PROPERTY_ENABLE);
 
        do {
                lis2dw12_reset_get(ctx, &rst);
        } while (rst);
 
        /* Enable Block Data Update */
        lis2dw12_block_data_update_set(ctx, PROPERTY_DISABLE);
        /* Set full scale */
        //lis2dw12_full_scale_set(&dev_ctx, LIS2DW12_8g);
        lis2dw12_full_scale_set(ctx, LIS2DW12_2g);
        /* Configure filtering chain
         * Accelerometer - filter path / bandwidth
         */
        lis2dw12_filter_path_set(ctx, LIS2DW12_LPF_ON_OUT);
        lis2dw12_filter_bandwidth_set(ctx, LIS2DW12_ODR_DIV_4);
        /* Configure power mode */
        lis2dw12_power_mode_set(ctx, LIS2DW12_HIGH_PERFORMANCE);
        //lis2dw12_power_mode_set(&dev_ctx, LIS2DW12_CONT_LOW_PWR_LOW_NOISE_12bit);
        /* Set Output Data Rate */
        lis2dw12_data_rate_set(ctx, LIS2DW12_XL_ODR_25Hz);
        
 
        /* Read samples in polling mode (no int) */
        while (1) {
            uint8_t reg;
            /* Read output only if new value is available */
            lis2dw12_flag_data_ready_get(ctx, &reg);
 
            lis2dw12_all_sources_t all_source;
            lis2dw12_all_sources_get(ctx, &all_source);
 
 
            if (reg) {
            /* Read acceleration data */
            memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));
            lis2dw12_acceleration_raw_get(ctx, data_raw_acceleration);
            acceleration_mg[0] = lis2dw12_from_fs2_to_mg(data_raw_acceleration[0]);
            acceleration_mg[1] = lis2dw12_from_fs2_to_mg(data_raw_acceleration[1]);
            acceleration_mg[2] = lis2dw12_from_fs2_to_mg(data_raw_acceleration[2]);
            LOG_INF("Acceleration [mg]:%4.2f\t%4.2f\t%4.2f\r\n",acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
            }
            else{
                LOG_INF("No Sensor Data......");
            }
        }

we have also found that we can't write LIS2DW12 register successfully through nrf52840 using NCS so we can't configure sensor correctly. Can you give me any suggestions or ideas? Thanks.

BRs

2 REPLIES 2
Eleon BORLINI
ST Employee

Hi @NWang.1​ ,

If the WHO_AM_I and the other registers are correctly read and written, then there should be no communication issue.

Are you correctly using the multiple bit communication?

Please note that here you don't need to configure the MSb of the SUB field is ‘1’, to allow multiple data read/writes.

-Eleon

Eleon BORLINI
ST Employee

Hi @NWang.1​ ,

do you have any updates about this?

-Eleon