Skip to main content
Associate
August 23, 2025
Solved

LIS2DW12TR weird artifacts (or maybe incorrect processing of data???)

  • August 23, 2025
  • 2 replies
  • 663 views

Hello,

I am working on interfacing with a LIS2DW12TR sensor over I2C. I currently am able to read/write registers, and am working on processing the data coming out of the fifo. I currently have the following:

 

int read_LIS2DW12TR_buffer(int x[32], int y[32], int z[32]) {
 static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C_NODE_LIS2DW12TR);
 uint8_t reg = LIS2DW12_OUT_X_L; // Start reading from the X-axis low byte
 uint8_t data[32 * 3]; // 32 samples, each with 3 axes (X, Y, Z)
 
 int ret = i2c_write_read_dt(&dev_i2c, &reg, sizeof(reg), data, sizeof(data));
 if (ret < 0) {
 LOG_ERR("Failed to read from LIS2DW12TR sensor: %d", ret);
 return ret;
 }

 // Process the data into x, y, z arrays
 for (int i = 0; i < 32; i++) {
 x[i] = (data[i * 3] | (data[i * 3 + 1] << 8)); // X-axis
 y[i] = (data[i * 3 + 2] | (data[i * 3 + 3] << 8)); // Y-axis
 z[i] = (data[i * 3 + 4] | (data[i * 3 + 5] << 8)); // Z-axis
 }

 // print first values for debugging
 // LOG_INF("LIS2DW12TR buffer read: X[0]=%d, Y[0]=%d, Z[0]=%d", x[0], y[0], z[0]);

 return 0; // Return 0 on success
}

 

Along with the following registers set:

 

 config.ctrl1.ODR = 0b0100; // 50Hz
 config.ctrl1.MODE = 0b00; // low performance
 config.ctrl1.LP_MODE = 0b01; // low power mode 2

 config.ctrl2.BOOT = 1; // reboot memory content
 config.ctrl2.CS_PU_DIS = 1; // disable internal pull-ups on SDO/SA0
 config.ctrl2.BDU = 1; // block data update

 config.ctrl6.BW_FILT = 0b10; // ODR/2
 config.ctrl6.FS = 0b00; // +/- 2g
 config.ctrl6.FDS = 0; // filter data selection
 config.ctrl6.LOW_NOISE = 1; // low-noise mode enable

 config.fifo_ctrl.F_MODE = 0b110;
 config.fifo_ctrl.FTH = 0x1f;

note: some of the comments may be wrong, it's certainly been a long day of tweaking :)

 

This has resulted in the following data output: (this is a small snapshot)

jcorn_ps_0-1755907501309.png

 

I will also post part of the .csv with raw data

 

 

What I am wondering is:

1. How do I interpret the data? What are the units here?

2. Are the artifacts I am seeing here just noise or am I processing the data wrong? To me it looks like the solid line is the actual data (the sensor was not moving as I did this) but I am not 100% sure of this.

Thank you all in advance for the help!

JC

Best answer by Federica Bossi

Hi @jcorn_ps ,

You are getting data in LSB, to convert them to mg you need to multiply the output by the correct sensitivity accordingly to the FS:

FedericaBossi_0-1756387022796.png

Yes, the artifacts could be noise, but I suggest you to check your code with our official examples on Github.

2 replies

Federica Bossi
Federica BossiBest answer
Technical Moderator
August 28, 2025

Hi @jcorn_ps ,

You are getting data in LSB, to convert them to mg you need to multiply the output by the correct sensitivity accordingly to the FS:

FedericaBossi_0-1756387022796.png

Yes, the artifacts could be noise, but I suggest you to check your code with our official examples on Github.

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.
jcorn_psAuthor
Associate
August 28, 2025

Thank you so much!!! I will look into the examples to get a better idea of implementation!

 

JC