2020-09-29 10:24 PM
Hi Team.
We are using LSM9DS1 with MCU (S32K146) via I2C.
We have tried enabling the acc and gyro with CTRL_REG1_G and CTRL_REG6_XL .
We can able to read the Who am I register properly. But the data output registers of acc/gyro are giving different values even if the board is in rest condition.
Please provide an reference LSM9DS1 example code for the necessary configuration and calculations.
2020-09-30 06:50 AM
Hi @LG.2 ,
you can find C drivers and examples for the LSM9DS1 interface on Github repository. In particular:
-Eleon
2020-10-02 12:52 AM
Hi @LG.2 ,
did you succeed in solving your data read issue?
-Eleon
2020-10-04 09:10 PM
Hi Eloen,
We are Still facing issue in getting the correct data from the sensor.
The registers we are setting is
Register Data
CTRL_REG5_XL (0X1F) - 0x38
CTRL_REG7_XL (0X21) - 0xA5
CTRL_REG9 (0X23) - 0x02
FIFO_CTRL (0X2E) - 0xc0
CTRL_REG10 (0x24) - 0x01
CTRL_REG8 (0x22) - 0x04
CTRL_REG6_XL (0x20) - 0x47
After setting these registers we are reading the data registers and calculating the values. I have attached the code snippet for calculation and output screenshot.
In the output the values of x,y,z keep on changing.
We can't figure it out, can you please tell us what we are missing.
Code snippet:
--------------------
// I2C transaction for reading the data registers
LPI2C_DRV_MasterSendData(INST_LPI2C0, x_low_reg, 1, 0);
while ((ret_Code = LPI2C_DRV_MasterGetTransferStatus(INST_LPI2C0, NULL)) == STATUS_BUSY){}
while(LPI2C_DRV_MasterReceiveData(INST_LPI2C0, x_low_rx, 6,0)!= STATUS_SUCCESS){}
OUTX_L_XL = x_low_rx[0];
OUTX_H_XL = x_low_rx[1];
OUTY_L_XL = x_low_rx[2];
OUTY_H_XL = x_low_rx[3];
OUTZ_L_XL = x_low_rx[4];
OUTZ_H_XL = x_low_rx[5];
OUT_X_XL = (((int) OUTX_H_XL) << 8) | (OUTX_L_XL & 0xFF);
OUT_Y_XL = (((int) OUTY_H_XL) << 8) | (OUTY_L_XL & 0xFF);
OUT_Z_XL = (((int) OUTZ_H_XL) << 8) | (OUTZ_L_XL & 0xFF);
//Calculation
double x, y, z;
uint16_t chk1 = OUT_X_XL, chk2 = OUT_Y_XL, chk3 = OUT_Z_XL;
uint16_t acc_x_data, acc_y_data, acc_z_data;
acc_x_data = (~OUT_X_XL);
acc_x_data += 1;
x = (acc_x_data * 0.000061); /*Sensitivity for 2 g*/
x = (x) *(9.8);
printf("Linear acceleration of OUTX_XL: %.2lf m/s^2\n\r", x);
acc_y_data = ~OUT_Y_XL;
acc_y_data += 1;
y = (acc_y_data * 0.000061); /*Sensitivity for 2 g*/
y = (y) *(9.8);
printf("Linear acceleration of OUTY_XL: %.2f m/s^2\n\r", y);
acc_z_data = ~OUT_Z_XL;
acc_z_data += 1;
z = (acc_z_data * 0.000061); /*Sensitivity for 2 g*/
z = (z) *(9.8);
printf("Linear acceleration of OUTZ_XL: %.2f m/s^2\n\r", z);
PFA of the attached output logs of Accelerometer.
2020-10-09 08:58 AM
Hi @LG.2 ,
it looks like data are multiplied by a factor of 4.. are you sure you did the two's complement and in general the LSB to physical units data conversion in the right way?
float_t lsm9ds1_from_fs2g_to_mg(int16_t lsb)
{
return ((float_t)lsb *0.061f);
}
I'm referring to this part of your code:
acc_x_data = (~OUT_X_XL);
acc_x_data += 1;
-Eleon