Skip to main content
Visitor II
September 16, 2025
Question

Cannot read samples from LSM6DSL sensor

  • September 16, 2025
  • 1 reply
  • 397 views

Hi, 

 

I am using LSM6DSL accelerometer sensor.

I have configure it to use acc only, +-16g, @27Hz, and using FIFO.

Here is the configuration I am doing:

uint8_t val = 0x04;
 err = lsm6dsl_write_reg(p_ctx, LSM6DSL_CTRL3_C, &val, 1);
 val = 0x24;
 err = lsm6dsl_write_reg(p_ctx, LSM6DSL_CTRL1_XL, &val, 1);
 val = 0x0;
 err = lsm6dsl_write_reg(p_ctx, LSM6DSL_CTRL2_G, &val, 1);
 val = 0x0;
 err = lsm6dsl_write_reg(p_ctx, LSM6DSL_FIFO_CTRL1, &val, 1);
 val = 0x0;
 err = lsm6dsl_write_reg(p_ctx, LSM6DSL_FIFO_CTRL2, &val, 1);
 val = 0x09;
 err = lsm6dsl_write_reg(p_ctx, LSM6DSL_FIFO_CTRL3, &val, 1);
 val = 0x0;
 err = lsm6dsl_write_reg(p_ctx, LSM6DSL_FIFO_CTRL4, &val, 1);
 val = 0x16;
 err = lsm6dsl_write_reg(p_ctx, LSM6DSL_FIFO_CTRL5, &val, 1);
 val = 0xF0;
 err = lsm6dsl_write_reg(p_ctx, 0x18, &val, 1);
 val = 0x00;
 err = lsm6dsl_write_reg(p_ctx, 0x19, &val, 1);
 
After that I am reading the fifo level:
 
ret = lsm6dsl_read_reg(ctx, LSM6DSL_FIFO_STATUS1, (uint8_t*)&fifo_status1, 1);
 if(ret == 0) {
 ret = lsm6dsl_read_reg(ctx, LSM6DSL_FIFO_STATUS2, (uint8_t*)&fifo_status2, 1);
 if(ret == 0) {
 *val = (uint8_t)fifo_status1.diff_fifo | ((uint16_t)((uint8_t)fifo_status2.diff_fifo & 0x07) << 8);
 }
 }
If the fiflo level id greater then 0, I am reading the FIFO output register:
 
ret = lsm6dsl_read_reg(ctx, LSM6DSL_FIFO_DATA_OUT_L, buff, 6);
 
But the reading iss always 0.
 
What am I doing wrong?
 
Thanks.

Edited to apply source code formatting - please see How to insert source code for future reference.

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    October 1, 2025

    Hi @saarpartush ,

    Are you reading 0 in the FIFO status data or in the output data?

     

    In general, there some things to consider in your code:

     

    For register CTRL3_C. you should also write 1 for BDU, because its needed for correct FIFO operation as stated in the Application Note (Application note - AN5040 - LSM6DSL: always-on 3D accelerometer and 3D gyroscope). It's generally a good practice to enable it for example is used in order to perform accurate readings of FIFO_STATUS.

     

    If you want only accel data in the FIFO, make sure to configure the DEC_FIFO _GYRO bits with the option gyro not in FIFO in the FIFO_CTRL3 register.

     

    Why are you reading 6 times the FIFO_DATA_OUT registers?

     

    When you read the FIFO, remember to read both FIFO_DATA_OUT_L and FIFO_DATA_OUT_H and concatenate them accordingly. The number of times you should read both (so the 16 bits words) depends on the value read on DIFF_FIFO [10:0] (FIFO_STATUS bits) until data is empty. 

     

    Remember that for this register the rounding function is automatically enabled. You can find more details on the Application Note dedicated FIFO section. 

     

    If you are still having issues after these fixes, you could also consider using the official drivers

     

    Hope this helps!