This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

WHO_AM_I with MPU9250

Hi,

I was trying nrf5-mpu-simple example with MPU9250 - SDK 14.2.0, it is giving me x, y & z axis values.

When I try WHO_AM_I with it, I am unable to do so. I have added the following code in nrf_drv_mpu_twi.c file.

static void read_whoAmIdata()
{
	#define MPU_REG_WHO_AM_I           0x75
	static volatile bool m_xfer_done = false;
		ret_code_t err_code;
		uint8_t addr8 = MPU_REG_WHO_AM_I;
	
		printf("WHO_AM_I Tx\r\n");

    m_xfer_done = false;
		err_code = nrf_drv_twi_tx(&m_twi_instance, MPU_ADDRESS, &addr8, 1, false);
		while (m_xfer_done == false);	

		printf("WHO_AM_I Tx\r\n");
	
		m_xfer_done = false;
		err_code = nrf_drv_twi_rx(&m_twi_instance, MPU_ADDRESS, &addr8, 1);
		APP_ERROR_CHECK(err_code);

		printf("read_data() done\r\n");
}

Please let me know where I am committing mistake.

Parents Reply
  • If you are using the drivers and libraries provided in the github repository you can simply use:

    nrf_drv_mpu_read_registers(MPU_REG_WHO_AM_I, who_am_i, 1);

    Then use printf, or whatever method you have to print data to a terminal, and print the returned value. 

    I noticed that in your code, you have this line:

    static volatile bool m_xfer_done = false;

    Is this variable ever set to true in an event handler? Otherwise your code would never get past the first while(m_xfer_done == false);.

Children
Related