cancel
Showing results for 
Search instead for 
Did you mean: 

lsm6dso accelerometer not working

santhosh_maxwell
Associate

hello , i am using lsmds0 sensor with nxp board below is the section of my code 

int main(void)
{
    /* Write your code here */
Clock_Ip_StatusType clockStatus;
clockStatus = Clock_Ip_Init(&Clock_Ip_aClockConfig[0]);
Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
Siul2_Dio_Ip_WritePin(MEMS_CS_DRIVE_ENABLE_PORT ,MEMS_CS_DRIVE_ENABLE_PIN,1);
i2c_int();
//i2c_scan_bus();
i2c_bustest();
// I2C_ManualBusRecovery();
dev_ctx.write_reg = accelero_write;//assigning read and write pointers to ST driver context
dev_ctx.read_reg = accelero_read;
dev_ctx.handle = NULL;
uint8_t who_am_i = 0;
uint8_t ctrl1;

int16_t raw_accel_data[3];// variable to store raw 16 bit accelerometer value
volatile float acceleration_mg[3];// converted acceleration in milli-g
lsm6dso_status_reg_t reg_status; // structure store the register flags

lsm6dso_device_id_get(&dev_ctx, &who_am_i);
lsm6dso_reset_set(&dev_ctx, PROPERTY_ENABLE);// starting resetting process
uint8_t rst;
uint8_t odr_check = 0;
//lsm6dso_reset_get(&dev_ctx, &rst);
do
{
lsm6dso_reset_get(&dev_ctx, &rst);
}while(rst);//waits for completion of resetting
lsm6dso_xl_data_rate_set(&dev_ctx, LSM6DSO_XL_ODR_104Hz);// sampling frequency = 104Hz

lsm6dso_xl_full_scale_set(&dev_ctx, LSM6DSO_2g);// measurement range +- 2g
lsm6dso_xl_full_scale_get(&dev_ctx, &odr_check);
lsm6dso_read_reg(&dev_ctx, 0x10, &ctrl1, 1);

lsm6dso_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);// Data consistency
memset(raw_accel_data, 0 , sizeof(raw_accel_data));
while (1)
{
// read the status register to check if new data is available
lsm6dso_status_reg_get(&dev_ctx,&reg_status);
if(reg_status.xlda) // it indicates that new data is available
{
lsm6dso_acceleration_raw_get(&dev_ctx, raw_accel_data);

acceleration_mg[0] = lsm6dso_from_fs2_to_mg(raw_accel_data[0]);
acceleration_mg[1] = lsm6dso_from_fs2_to_mg(raw_accel_data[1]);
acceleration_mg[2] = lsm6dso_from_fs2_to_mg(raw_accel_data[2]);
}
}
    return exit_code;
}


everything works fine till first reading, i am getting first reading and for next reading i am getting raw values as 136, 8256,-36 and repeats same, values are not getting updated.  i request you please help me solve this issue


Edited to apply source code formatting - please see How to insert source code for future reference.

2 REPLIES 2
Federica Bossi
ST Employee

Hi @santhosh_maxwell ,

Can you try to test with a known working example from ST’s sensor driver package

Let me know if you still have the same issue.

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.
Andrew Neil
Super User

Have you looked at the I2C lines using an analyser to see what's actually happening on the wires?

Compare & contrast what happens on the first read (working) to what happens on the subsequent reads (failing).

Also check with an oscilloscope that the signals are clean, at the right levels, etc.

Please post your schematic

 

See: How to write your question to maximize your chances to find a solution

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.