I am interfacing with the LSM303DLHC and the data for the linear acceleration does not seem to be correct.
When reading the data on registers 28h to 2dh, the data is all 0, 64, or 192. (it is very odd that the data across all axis is the same) Also, this data is always changing between the stated values even at rest.
The magnetic field data seems to be correct as each axis has it’s own value which changes upon turning the device
Will someone please check to see if I have setup the device correctly. (Coded in MikroC)
Init code:
// INIT LSM303DLHC_electronic_compass
// set CRA_REG_M register
// 30 Hz update rate
I2C1_Start();
I2C1_Wr(0x3c);
I2C1_Wr(0x00);
I2C1_Wr(0x14);
I2C1_Stop();
// set MR_REG_M register
// continuous-coversion mode
I2C1_Start();
I2C1_Wr(0x3c);
I2C1_Wr(0x02);
I2C1_Wr(0x00);
I2C1_Stop();
// set CTRL_REG1_A register
// enable all axis, set x Hz refresh
I2C1_Start();
I2C1_Wr(0x32);
I2C1_Wr(0x20);
I2C1_Wr(0b00100111);
I2C1_Stop();
Reading code:
I2C1_Start();
I2C1_Wr(0x3c); // LSM303DLHC board device ID
I2C1_Wr(0x03);
I2C1_Repeated_Start();
I2C1_Wr(0x3d);
USB_out_buffer[24] = I2C1_Rd (1);
USB_out_buffer[25] = I2C1_Rd (1);
USB_out_buffer[26] = I2C1_Rd (1);
USB_out_buffer[27] = I2C1_Rd (1);
USB_out_buffer[28] = I2C1_Rd (1);
USB_out_buffer[29] = I2C1_Rd (0);
I2C1_Stop();
I2C1_Start();
I2C1_Wr(0x32); // LSM303DLHC board device ID
I2C1_Wr(0x28);
I2C1_Repeated_Start();
I2C1_Wr(0x33);
USB_out_buffer[15] = I2C1_Rd (1);
USB_out_buffer[16] = I2C1_Rd (1);
USB_out_buffer[17] = I2C1_Rd (1);
USB_out_buffer[18] = I2C1_Rd (1);
USB_out_buffer[19] = I2C1_Rd (1);
USB_out_buffer[20] = I2C1_Rd (0);
I2C1_Stop();