cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to using LDM6DSL just for it's linear acceleration sensor to detect movement. The values i receive from the sensor are fluctuating a lot even when the sensor is in a steady position?

TGhau.2088
Associate II

I have only used the CTRL6_C(15h) and CTRL1_XL(10h) register to configure the linear acceleration sensor and I am reader the value from register 28h to 2Dh.

void i2c_write(uint8_t imudevaddr, uint8_t* write_2_reg_addr_data,int No_of_bytes)

{

HAL_I2C_Master_Transmit(&hi2c2,imudevaddr,write_2_reg_addr_data,No_of_bytes,100);

HAL_Delay(10);

}

float i2c_read(uint8_t imudevaddr,uint8_t regaddr)

{

uint8_t accelerometer[2];

float Acc;

unsigned int raw;

HAL_I2C_Master_Transmit(&hi2c2,imudevaddr,&regaddr,1,10);

HAL_I2C_Master_Receive(&hi2c2,imudevaddr,&accelerometer[0],2,10);

raw = (accelerometer[1]<<8|accelerometer[0]);

Acc=(((float)raw)*0.122f);

return Acc;

}

void imu_accelerometer_read(uint8_t imudevaddr)

{

//uint8_t imudevaddr=0xD4; imu address

uint8_t LASCR[2]; //LASCR linear acceleration sensor control register 1 (CTRL1_XL(0x10) in docs)

LASCR[0]=0x10;

LASCR[1]=0x90;

i2c_write(imudevaddr,LASCR,2);

LASCR[0]=0x15;

LASCR[1]=0x00;

i2c_write(imudevaddr,LASCR,2);

float x=0.0,y=0.0,z=0.0;

imudevaddr = imudevaddr+0x01;

x=i2c_read(imudevaddr,0x28);

y=i2c_read(imudevaddr,0x2A);

z=i2c_read(imudevaddr,0x2C);

sprintf(i2c2_buffer,"accel-x<%f>accel-y<%f>accel-z<%f>",x,y,z);

uprintf(i2c2_buffer);

uprintf("\r\n");

HAL_Delay(500);

}

1 REPLY 1
Ozone
Lead II

> unsigned int raw;

Aren't the sensor values signed ?

> Acc=(((float)raw)*0.122f);

Where is this factor coming from ? Your screenshot shows no units.

In other words, get the raw return values, and check their plausibility.