cancel
Showing results for 
Search instead for 
Did you mean: 

Accelerometer Reading Issue

K_P_D
Associate II
Posted on May 14, 2018 at 15:01

Hi There,

I am using the STM Accelerometer(LIS2DE12) with STM(stm32l432kb) controller.

While getting the readings from the Accelerometer it gives the random value continuously. Even it shows false value at steady position.

Here some how I am facing problem and need some idea and suggestion to solve this issue. If some one has the document , relevant data and sample code for it please let me know and help me.

Thanks

12 REPLIES 12
Miroslav BATEK
ST Employee
Posted on May 14, 2018 at 16:56

Are you able successfully to read the WHO_AM_I register?

Posted on May 15, 2018 at 11:33

Yes Miroslav B, I am getting 0x33 after reading the WHO_AM_I register....

Posted on May 15, 2018 at 22:10

OK, good.

So please share your sensor configuration, and the data which you read.

Posted on May 16, 2018 at 07:08

OK ... Sure 

Codes

//   For Writing , ACC_ADDMW = 0x32

Used to configure the Registers

tx_data = 0x0F; // CTRL_REG1 register(0x20) with value 0x0F

result = HAL_I2C_Mem_Write(&hi2c3, ACC_ADDMW, 0x20, I2C_MEMADD_SIZE_8BIT, &tx_data, 1, 1000);

tx_data = 0x00; // CTRL_REG5 register(0x24) with value 0x00

result = HAL_I2C_Mem_Write(&hi2c3, ACC_ADDMW, 0x24, I2C_MEMADD_SIZE_8BIT, &tx_data, 1, 1000);

tx_data = 0x00; // FIFO_CTRL_REG(0x2E) with value 0x00

result = HAL_I2C_Mem_Write(&hi2c3, ACC_ADDMW, 0x2E, I2C_MEMADD_SIZE_8BIT, &tx_data, 1, 1000);

//    For reading , ACC_ADDMR = 0x33

Used for Who Am I ....

HAL_I2C_Mem_Read(&hi2c3, ACC_ADDMR, 0x0F, I2C_MEMADD_SIZE_8BIT, &read_mem, 1, 1000);

Used to Read the register 0x28

HAL_I2C_Mem_Read(&hi2c3, ACC_ADDMR, 0x28, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&read_mem, 2, 1000);

Used to Read the X-Axies

HAL_I2C_Mem_Read(&hi2c3, ACC_ADDMR, 0x29, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&read_mem_x, 2, 1000);

Used to Read the Y-Axies

HAL_I2C_Mem_Read(&hi2c3, ACC_ADDMR, 0x2B, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&read_mem_y, 2, 1000);

Used to Read the Z-axies

HAL_I2C_Mem_Read(&hi2c3, ACC_ADDMR, 0x2D, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&read_mem_z, 2, 1000);
Posted on May 16, 2018 at 07:25

Hi Miroslav, 

i think im having the same issue with LIS2DH12:

config:

{0x20, 0x27}; //10Hz Normal

{0x22, 0x10}; //interrupt on 1 if data ready

{0x23, 0x00}; //default

{0x24, 0x00}; //no fifo

{0x2E, 0x00}; //no fifo

{0x1E, 0x90}; //disable pullup

reading xyz registry with auto-increment (0x80 | 0x28) on interrupt. values are stored in m_sample array.

expecting values to be returned in the same order as registry (X_L, X_H, Y_L, Y_H, etc)

it seems the values are ordered ok but shifting as in circular buffer. 

As you can see below the first value is last on the second RX event, then second on the third event etc.

i am not sure which is x, y or z....

(m_sample[0] |(m_sample[1] << 8), 

(m_sample[2] |(m_sample[3] << 8), (m_sample[4] |(m_sample[5] << 8)

<info> app: data ready

<info> app: RX event done 61568, 64000, 16256 

<info> app: data ready

<info> app: RX event done 64000, 16384, 61824 

<info> app: data ready

<info> app: RX event done 16256, 61760, 64064 

<info> app: data ready

<info> app: RX event done 61760, 64064, 16320

<info> app: data ready

<info> app: RX event done 64064, 16384, 61760 

<info> app: data ready

<info> app: RX event done 16192, 61632, 63872
Posted on May 16, 2018 at 09:04

Hi

Batek.Miroslav

‌,

It will be great of yours if you can share me the details for control register(with its configuration in FIFO and WITHOUT FIFO mode) for running program.

K_P_D
Associate II
Posted on May 21, 2018 at 15:13

Hi

Batek.Miroslav

I getting the output now i have configure the register with below details:-

(Reg_Add,Loaded_value)

(0x1E, 0x10) // CTRL_REG0 register

(0x20,0x9F) // CTRL_REG1 register

(0x23, 0x00)// CTRL_REG4 register

(0x24, 0x00) // CTRL_REG5 register

(0x2E, 0x00) // FIFO_CTRL_REG register

while (1)

{

MemAdd = 0x29; // 0x29 address for the X-Axis

HAL_I2C_Mem_Read(&hi2c3, ACC_ADDRMR, MemAdd, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&rx_data_x, 1, 1000);

MemAdd = 0x2B; // 0x2B address for the Y-Axis

HAL_I2C_Mem_Read(&hi2c3, ACC_ADDRMR, MemAdd, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&rx_data_y, 1, 1000);

MemAdd = 0x2D; // 0x2D address for the Z-Axis

HAL_I2C_Mem_Read(&hi2c3, ACC_ADDRMR, MemAdd, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&rx_data_z, 1, 1000);

HAL_Delay(100);

}

In the output i am getting the value but it not showing the constant value. It shows 0, 255, 254 at steady position in X and Y-Axis. In Z-Axis it shows 64(or 63,62) constantly. But yes when we move it, it shows the change value as per the movement.

So here I am little bit confused for my output that it is okay or not.

Is it so? or am I wrong?

All correction will be helpful and welcome.

Best regards.

Sachin

Miroslav BATEK
ST Employee
Posted on May 22, 2018 at 21:00

Your measurement is correct.

To get the acceleration value in g unit, you have to firts convert the raw data into signed value and then multiply it by sensitivity defined in datasheet.

0690X0000060KstQAE.png

So in your case for X, Y axis: 0 ... 0g, 255 ... -16mg, 254 ... -32 mg (basicaly noise). for Z axis 64 ... 1024 mg (gravity).

Posted on May 23, 2018 at 14:34

Hi

Batek.Miroslav

,

For sure, that's all I need! ...

All the answers are really useful.

Many Thanks for your kind response.

I am trying to get speed(velocity) using

Accelerometer(LIS2DE12) this for my hobbyist project. I have searched a lotfor that, it would be great if you can give a suggestion from your experience.

Thanks &Regards

Sachin