Issue in reading Magnetometer data.

By abhishekoct18 , 29 November 2017

I am using InvenSense Motion Sensor Universal Evaluation Board (UEVB). I am able to read & write Accelerometer and Gyroscope data. But when i trying to Read/Write magnetometer(AK8963) register, I am only able to read WAI register. As given in AK8963 datasheet device will initially go in power-down mode. We have to change the mode to other mode, when i trying to write data on that register and reading back that register or any measurement data register, device is only returing 0xFF value. After changing the mode to continous/single mode i tried to read the magnetometer measurement data, but it also returning 0xFF.
I also tried the method given in AK8963 datasheet , switch mode to single measurement then wait for drdy bit in ST1 register, when bit will high read the magnetometer register. But it always stucking in loop, as drdy bit is always 0.

Below is my code for reading data:
/*change mode to single measurement*/
/*0x0A=> register addr, 0x01=> single measurement value*/
sensor_write(0x0A, 0x01, NULL);
nrf_delay_ms(10);
while (true)
{
do
{
__WFE();
}while (m_xfer_done == false);
/*check for drdy bit*/
while(read_value == NULL) {
read_value = read_data(0x02, NULL);
NRF_LOG_INFO("CTRL = %x", read_value);
nrf_delay_ms(20);
}
/*read magnetometer X-axis data*/
read_value = read_data(0x03, NULL);
NRF_LOG_INFO("x_axis = %x", read_value);
nrf_delay_ms(20);
}
}

phpbb Topic ID
36619