cancel
Showing results for 
Search instead for 
Did you mean: 

No data from lsm9ds1

Ole Thomsen
Associate II

Hi,

I am using the lsm9ds1 with a selfmade circuit, but I could not get any data from the sensors. The I2C works fine. I can access the registers, read and write to them and get an acknowledge from it, but when I read the data registers, the values don't change even when bdu is disabled. Does anyone know what problem could be causing this?

schematic:

0690X00000BvttxQAB.png

IMU setup:

//setup IMU
	I2C_Mem_Read(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG2_G, (uint8_t*) &ctrl_reg2_g, 1);
	I2C_Mem_Read(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG3_G, (uint8_t*) &ctrl_reg3_g, 1);
	I2C_Mem_Read(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG7_XL, (uint8_t*) &ctrl_reg7_xl, 1);
	I2C_Mem_Read(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG8, (uint8_t*) &ctrl_reg8, 1);
	I2C_Mem_Read(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG1_G, (uint8_t*) &ctrl_reg1_g, 1);
	I2C_Mem_Read(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG6_XL, (uint8_t*) &ctrl_reg6_xl, 1);
 
 
	ctrl_reg1_g.fs_g = 3;					//2000dps
	ctrl_reg1_g.bw_g = 3;					//cutoff 31Hz
	ctrl_reg1_g.odr_g = 3;					//119Hz
 
	ctrl_reg2_g.out_sel = 2;				//pass with hp and lp
	ctrl_reg3_g.hp_en = 1;					//highpass enable
	ctrl_reg3_g.hpcf_g = 6;					//highpass cut off 0.1Hz
	ctrl_reg6_xl.odr_xl = 3;				//119Hz
	ctrl_reg6_xl.fs_xl = 2;					//4g
	ctrl_reg7_xl.hr = 1;					//high resolution mode
	ctrl_reg7_xl.dcf = 1;					//accelerometer digital filter
	ctrl_reg8.bdu = 0;						//block data update
	I2C_Mem_Write(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG2_G, (uint8_t*) &ctrl_reg2_g, 1);
	I2C_Mem_Write(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG3_G, (uint8_t*) &ctrl_reg3_g, 1);
	I2C_Mem_Write(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG7_XL, (uint8_t*) &ctrl_reg7_xl, 1);
	I2C_Mem_Write(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG8, (uint8_t*) &ctrl_reg8, 1);
	I2C_Mem_Write(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG1_G, (uint8_t*) &ctrl_reg1_g, 1);
	I2C_Mem_Write(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG6_XL, (uint8_t*) &ctrl_reg6_xl, 1);
	//setup magnetometer
	I2C_Mem_Read(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG2_M, (uint8_t*) &ctrl_reg2_m, 1);
	I2C_Mem_Read(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG4_M, (uint8_t*) &ctrl_reg4_m, 1);
	I2C_Mem_Read(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG5_M, (uint8_t*) &ctrl_reg5_m, 1);
	I2C_Mem_Read(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG3_M, (uint8_t*) &ctrl_reg3_m, 1);
	I2C_Mem_Read(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG1_M, (uint8_t*) &ctrl_reg1_m, 1);
	ctrl_reg1_m.fast_odr = 0;				//normal speed
	ctrl_reg1_m._do = 7;					//80Hz
	ctrl_reg1_m.om = 3;						//ultra-high performance in x and y axis
	ctrl_reg1_m.temp_comp = 1;				//temperature compensation
	ctrl_reg2_m.fs = 3;						//16G
	ctrl_reg3_m.md = 0;						//Continuous mode
	ctrl_reg4_m.omz = 3;					//ultra-high performance in z axis
	ctrl_reg5_m.bdu = 0;					//block data update
	I2C_Mem_Write(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG2_M, (uint8_t*) &ctrl_reg2_m, 1);
	I2C_Mem_Write(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG4_M, (uint8_t*) &ctrl_reg4_m, 1);
	I2C_Mem_Write(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG5_M, (uint8_t*) &ctrl_reg5_m, 1);
	I2C_Mem_Write(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG3_M, (uint8_t*) &ctrl_reg3_m, 1);
	I2C_Mem_Write(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_CTRL_REG1_M, (uint8_t*) &ctrl_reg1_m, 1);

reading:

uint8_t mdata[6];
	uint8_t gdata[6];
	uint8_t xdata[6];
while(1)
{
	status = I2C_Mem_Read(LSM9DS1_MAG_I2C_ADD_H, LSM9DS1_OUT_X_L_M, mdata, 6);
	float mz = lsm9ds1_from_fs16gauss_to_mG(mdata[5] | (mdata[4]<<8));
	status = I2C_Mem_Read(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_OUT_X_L_G, gdata, 6);
	float gz = lsm9ds1_from_fs2000dps_to_mdps(gdata[5] | (gdata[4]<<8));
	status = I2C_Mem_Read(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_OUT_X_L_XL, xdata, 6);
	float xlz = lsm9ds1_from_fs4g_to_mg(xdata[5] | (xdata[4]<<8));
}

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @Ole Thomsen​ , you have to explicitly enable the 3 axis of the gyro writing '1' in Zen_G, Yen_G, Xen_G of CTRL_REG4 reg

>> CTRL_REG4 (1Eh) --> 1Ch // datasheet p 50

and do the same for axl enable bits in CTRL_REG5_XL reg

>> CTRL_REG5_XL (1Fh) --> 1Ch // datasheet p 51

Pseudocode
 
ctrl_reg4 = 28; // Gyroscope's axis outputs enable
I2C_Mem_Write(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG4, (uint8_t*) &ctrl_reg4, 1);
 
ctrl_reg5_xl = 28; // Accelerometer’s axis outputs enable
I2C_Mem_Write(LSM9DS1_IMU_I2C_ADD_H, LSM9DS1_CTRL_REG5_XL, (uint8_t*) &ctrl_reg5_xl, 1);

Please note that you could speed up your code by noting that you can write or read multiple bytes via I2C following the instruction in datasheet p 29/30.

You can also find further C code on Github repository for LSM9DS1 here.

Regards