cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DH12 acceleration data not changing

GChan_02
Associate

Dear All, 

I am using the LIS2DH12 accelerometer that is incorporated within a Decawave DWM1001-DEV board. I am attempting to write a C program using the dwm.h library functions to display the acceleration values for the X, Y and Z axes via I2C constantly. 

However, after writing my program, I realised that the program only outputs a constant reading of -32640 for all axes as shown below even when I move the accelerometer.

GChan_02_0-1711436593131.png

My code mainly uses the dwm_i2c_write() and dwm_i2c_read() functions from the dwm.h library with the descriptions of the functions as shown:

GChan_02_1-1711437056735.pngGChan_02_2-1711437118612.png

The main file and header files for my program are attached below. I would appreciate any help on shedding some light on any errors I have made in my program which might have resulted in my problem.

Main function:

void app_thread_entry(uint32_t data)
{
uint8_t writeData[2];
// Enable X, Y, Z axes and set ODR (data rate) - for example, to 10 Hz
writeData[0] = 0x20;
writeData[1] = 0x27;
dwm_i2c_write(0x19, writeData, 2, false);

// Set full-scale to +/-2g
writeData[0] = 0x23;
writeData[1] = 0x08;
dwm_i2c_write(0x19, writeData, 2, false);

// Set FIFO enable
writeData[0] = 0x24;
writeData[1] = 0x40;
dwm_i2c_write(0x19, writeData, 2, false);

// Set accelerometer to stream mode
writeData[0] = 0x2e;
writeData[1] = 0x80;
dwm_i2c_write(0x19, writeData, 2, false);


while(1) {

uint8_t status;
uint8_t out_x_l, out_x_h, out_y_l, out_y_h, out_z_l, out_z_h; // To store X, Y, Z high and low bytes
int16_t x, y, z;

out_x_l = 0x28;
out_x_h = 0x29;
out_y_l = 0x2a;
out_y_h = 0x2b;
out_z_l = 0x2c;
out_z_h = 0x2d;

// Read FIFO_SRC_REG to check if data is available
dwm_i2c_read(0x2f, &status, 1);

// If FIFO is not empty, read acceleration data
if (!(status & 0x20)) {
// Read sequential data output registers from OUT_X_LO to OUT_Z_HI
dwm_i2c_read(0x19, &out_x_l, 1);
dwm_i2c_read(0x19, &out_x_h, 1);
dwm_i2c_read(0x19, &out_y_l, 1);
dwm_i2c_read(0x19, &out_y_h, 1);
dwm_i2c_read(0x19, &out_z_l, 1);
dwm_i2c_read(0x19, &out_z_h, 1);

// Combine high and low bytes
x = (int16_t)((out_x_h << 8   | out_x_l);
y = (int16_t)((out_y_h << 8   | out_y_l);
z = (int16_t)((out_z_h << 8   | out_z_l);

// Print acceleration values
printf("X: %d, Y: %d, Z: %d\n", x, y, z);
}

// Sleep or delay to match the read rate with the ODR of accelerometer
dwm_thread_delay(100); // For example, delay 100ms
}

}

Thank you all in advance.

1 REPLY 1
Federica Bossi
ST Employee

Hi @GChan_02 ,

Welcome to ST Community!

I can't support you with that library is not provided by ST.

However, I suggest you to look at our official drivers 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.