2015-06-03 08:02 AM
While working with the LSM303D, I ran into the following problem:
The application:To detect disturbances in the local magnetic field (the sensor is stationary). I average a set of readings, and then subtract this offset from the raw magnetic data. I would like to utilize the threshold interrupts on the sensor, so rather than subtract in software, I would prefer to offset the data in the sensor. The problem: I am able to write data to the appropriate X, Y, and Z offset registers, and confirmed via a readback the the data is correct, but the sensor readings are nowhere near zero. If I subtract the same readings in my program, the results are approximately zero. Configuration:i2c_start_wait( (LSM303D_ADDR) + (I2C_WRITE) );
i2c_write(INT_CTRL_M);
i2c_write(0xF1);
//Enable int recog for x,y,z axes; open drain; active low; no latch; enable generation
i2c_stop();
i2c_start_wait( (LSM303D_ADDR) + (I2C_WRITE) );
i2c_write(CTRL1);
i2c_write(0x67);
//Acc ODR must be > 50 Hz for 100 Hz AMR ODR; enable acc X,Y,Z for later
i2c_stop();
i2c_start_wait( (LSM303D_ADDR) + (I2C_WRITE) );
i2c_write(CTRL3);
i2c_write(0x02);
//Magnetometer data-ready signal on INT1
i2c_stop();
i2c_start_wait( (LSM303D_ADDR) + (I2C_WRITE) );
i2c_write(CTRL5);
i2c_write(0x74);
//High resolution; 100 Hz mag ODR
i2c_stop();
i2c_start_wait( (LSM303D_ADDR) + (I2C_WRITE) );
i2c_write(CTRL6);
i2c_write(0x40);
//8 gauss operation
i2c_stop();
i2c_start_wait( (LSM303D_ADDR) + (I2C_WRITE) );
i2c_write(CTRL7);
i2c_write(0x00);
//Continuous conversion
i2c_stop();
Writing to offset registers:
i2c_start_wait((LSM303D_ADDR) + (I2C_WRITE));
i2c_write(OFFSET_X_L_M | CTRL_MULTI);
//multi-byte write
i2c_write( (px->nullValue & 0xFF) );
//write x-axis lower byte
i2c_write( (px->nullValue >> 8) & 0xFF );
//x-axis upper byte
i2c_write( (py->nullValue & 0xFF) );
//y-axis lower byte
i2c_write( (py->nullValue >> 8) & 0xFF );
//y-axis upper byte
i2c_write( (pz->nullValue & 0xFF) );
//z-axis lower byte
i2c_write( (pz->nullValue >> 8) & 0xFF );
//z-axis upper byte
i2c_stop();
Is there a control register configuration setting that I am overlooking, or is the implementation of the offsets not a simple subtraction as assumed in the datasheet. Thank you for your time.
-Ryan
#lsm303d-offset-registers