MPU9250 Magnetometer is working arbitrarily

By ghada123 , 16 August 2017

Hi all,

I am using STM32L4 microcontroller and MPU9250 sensor using I2C interface.

I2C speed frequency is configured as 300 KHz.
I configured MPU9250 sensor and I’m able to read Accelerometer, Gyroscope and temperature value from registers.

As a second step, I have to configure Magnetometer and acquire data.
I configured AK8963 CTRL1 register using: Continuous_Measurement_1 (mode) and 16 bit output (bit) using all of these steps:

MPU9250_SetRegValue(USER_CTRL, I2C_MST_EN_BitCtrl);
MPU9250_SetRegValue(I2C_SLV4_ADDR, AK8963_ID|WriteEnable);
MPU9250_SetRegValue(I2C_SLV4_REG, Register);
MPU9250_SetRegValue(I2C_SLV4_DO, value);
MPU9250_SetRegValue(I2C_SLV4_CTRL, I2C_SLV4_EN);

and next:
MPU9250_SetRegValue(I2C_SLV0_ADDR, AK8963_ID|ReadEnable);
MPU9250_SetRegValue(I2C_SLV0_REG, AK8963_HXL);
MPU9250_SetRegValue(I2C_SLV0_CTRL, 0x87);

finally, to read Magnetometer chip ID (0x48 from register 0x00) I followed these steps:
MPU9250_SetRegValue(USER_CTRL, I2C_MST_EN_BitCtrl);
MPU9250_SetRegValue(I2C_SLV4_ADDR, AK8963_ID|ReadEnable);
MPU9250_SetRegValue(I2C_SLV4_REG, Register);
MPU9250_SetRegValue(I2C_SLV4_CTRL, I2C_SLV4_EN);
MPU9250_GetRegValue(I2C_SLV4_DI, value);

My problem that I can read Magnetometer chip ID or data randomly, in some cases chip ID is correct, and in other cases, data are 0x00.

Did I miss some configuration ?
Is there any electrical or software issue ?
Why Did I have Zero data ? (neither chip ID is zero)

Thank you.

phpbb Topic ID
36415