Problem with accelerometer value read via C API

Hello,

I’m currently working with module DWM1001 and I faced some problems with reading the accelerometer values via C code Api. To read from i2c I use the following code within the thread loop:

	rv = dwm_i2c_read(0x33 >> 1, i2cbyte, 2);
	if (rv == DWM_OK) {
		printf("Accelerometer: %u , %u\n", *i2cbyte , *(i2cbyte + 1));			
	} else {
		printf("i2c: read failed (%d)\n", rv);
	}

I have already figured out that I need to disable stationary detection to make it work.

The problem is I always read 0s unless I issue “av” command after which I start getting some values at address i2cbyte and i2cbyte + 1 but they seem to be random and independent of module’s orientation.

I have the following questions:

  1. Why do I need to use “av” shell comand to start reading some non 0 values from i2c and how to avoid it ?
  2. How to understand those two 8-bit integers as acceleration values ?

Thanks in advance,
Filip

Hi Filip,

  1. When stationary detection is disabled the Accelerometer is unconfigured after the reset. The sensor is inactive and you will need to configure it. The “av” command configures it so that explains your observation.

Please refer to the sensor documentation for more details:

This is an example:

write_reg8(LIS2DX_CTRL_REG1, 0);
write_reg8(LIS2DX_CTRL_REG5, LIS2DX_BOOT);
write_reg8(LIS2DX_CTRL_REG1, LIS2DX_ODR_50 | LIS2DX_ZEN | LIS2DX_YEN | LIS2DX_XEN);
write_reg8(LIS2DX_CTRL_REG2, 0);
write_reg8(LIS2DX_CTRL_REG3, LIS2DX_I1_ZYXDA);
write_reg8(LIS2DX_CTRL_REG4, LIS2DX_HR | LIS2DX_FS_2G);
write_reg8(LIS2DX_CTRL_REG6, 0);

  1. The raw values are 16-bit so you should read 2 bytes for each axis, e.g.

x = read_reg16(LIS2DX_OUT_X_L);
y = read_reg16(LIS2DX_OUT_Y_L);
z = read_reg16(LIS2DX_OUT_Z_L);

Cheers,
TDK

2 Likes

Thank You, that was very helpfull.

Cheers,
Filip