I read the data of the accelerometer and magnetic sensor from STEVAL-MKI173V using I2C communication. However, 0 is output for the magnetic sensor data. How can I read the value of the magnetic sensor accurately? Please teach.
In addition, what formula do you use to convert the magnetic sensor data to azimuth?
There was no error in the I2C communication itself.
In addition, I2C communication was performed according to the communication format of LSM303AH.
The program is as follows.
Write 0x04 to the CTRL2_A register // I2C interface enabled
// Register address automatically incremented
// during multiple byte access with a serial
// interface.
Write 0x01 to the CTRL5_A register // Configure INT3 pin as digital output and route
//data-ready signal
Write 0x40 to the CTRL1_A register // Turn on the accelerometer, ODR = 100 Hz,
//HR(High-Resolution) modes, Full Scale = ±2 g
Write 0x01 to the CFG_REG_C_M register // Configure INT3 pin as digital output and route data-ready signal
Write 0x02 to the CFG_REG_B_M register // Enable offset cancellation of magnetic sensor
Write 0x8C to the CFG_REG_A_M register // Temperature compensation enabled,
//ODR = 100 Hz
//Continuous and High-Resolution modes
Read the DRDY in STATUS_A register
When DRDY = 1
Read the
OUT_X_L_A_REG,OUT_X_H_A_REG,
OUT_Y_L_A_REG,OUT_Y_H_A_REG,
OUT_Z_L_A_REG and OUT_Z_H_A_REG register
Store the read data in a defined variable.
Read the Zyxda in STATUS_REG_M register
When Zyxda = 1
Read the
OUT_X_L_M_REG,OUT_X_H_M_REG, // Read 0x00
OUT_Y_L_M_REG,OUT_Y_H_M_REG, //
OUT_Z_L_M_REG and OUT_Z_H_M_REG register
Store the read data in a defined variable.
