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

magnetomter error after enable MPU92532 DMP

Hi all,

I develop program code based on nrf-mpu-magnetomter examples.  I code the DMP and complied well . However the program is always stay an error when it starts  running as below:

and here is the partial code

The problem is that the accel and gyro values can be reading after the function of Read magnetometer sensor values was commented.

Not sure the DMP setting caused this or the compass does not initialize properly?

thx your attention.

  • Which function is reporting the error? You have not included line numbers in your code image.

  • *------------------------------------------------------------------
     * nRF52 reading MPU 
     * The code (based on nrf52-mpu-simple Martin Børs-Lind).
     *
     * Project: FWD_Motion_Detection
     * SDK      : SDK14.2.0
     * 
     * 
     *-------------------------------------------------------------------
     * 
     *
     * 
     *  
     *   
     * 
     * 
     *  
     * 
     * 
     *------------------------------------------------------------------*/
    
    #include <stdio.h>
    #include "boards.h"
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    
    
    
    //nRF5_to_Invensense API headers
    #include "app_mpu.h"                //MPU9250 API functions 
    
    //$$ DMP_MPL API headers
    #include "inv_mpu.h"
    #include "inv_mpu_dmp_motion_driver.h" 
    
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    
    // LEDs definitions on P0.08 for MVP
    //#define LED     8
    
    //LED definitions on P0.20 LED_4 for PCA100404
    #define LED     20
    
    /**@brief Function for initializing the nrf log module. */
    static void log_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    
    /* MPU 9250 setup and initialization */
    void mpu_9250_init(void)                                        //$$rename original mpu_init() to mpu_9250_init(), conflict to mpl library
    {
        ret_code_t ret_code;
        /* Configure MPU driver */
        ret_code = app_mpu_init();                                  //reset MPU and config the MPU TWI interface
        APP_ERROR_CHECK(ret_code); 					// Check for errors in return value
        
        
    //    // Setup and configure the MPU with initial values
    //    app_mpu_config_t p_mpu_config = MPU_DEFAULT_CONFIG();       // Load default values
    //    p_mpu_config.smplrt_div = 19;                               // Change sampelrate. Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV). 19 gives a sample rate of 50Hz
    //    p_mpu_config.accel_config.afs_sel = AFS_2G; 		// Set accelerometer full scale range to 2G
    //    ret_code = app_mpu_config(&p_mpu_config); 			// Configure the MPU with above values
    //    APP_ERROR_CHECK(ret_code); 					// Check for errors in return value 
    //
    //    // Enable magnetometer
    //    app_mpu_magn_config_t magnetometer_config;
    //    magnetometer_config.mode = CONTINUOUS_MEASUREMENT_100Hz_MODE;
    //    ret_code = app_mpu_magnetometer_init(&magnetometer_config);
    //    APP_ERROR_CHECK(ret_code);                                  // Check for errors in return value
        
    }
    
    
    
    /**
     * @brief Function for main application entry.
     */
     /*************** main() ********************/
    int main(void)
    {    
        uint32_t err_code;
    
        // Initialize.
        log_init();
        NRF_LOG_INFO("***** MPU9250_Simple *****");         //Check point
        nrf_delay_ms(250);
        
        //TWI initialize
        mpu_9250_init();                                     //reset MPU and config the MPU TWI interfac, gyro, accel and magnet
        NRF_LOG_INFO("***** MPU9250_start! *****");        //Check Point
        nrf_delay_ms(250);
    
        //MPU9250 and DMP initial
        while(mpu_dmp_init())         
        {   
            NRF_LOG_INFO("***** MPU9250 and DMP fail! *****");
            nrf_delay_ms(200);
    
        }
        NRF_LOG_INFO("***** MPU9250 and DMP start! *****");
        nrf_delay_ms(200);
    
    
        // enable LED 
        nrf_gpio_cfg_output(LED);   //config the LED pin and output, drive the LED 
        nrf_gpio_pin_set(LED);      //set the LED states as Low
    
        
        // Start execution.
        NRF_LOG_INFO("***** MPU Raw data Reading *****");
        nrf_delay_ms(250);
    
        //Test purpose
        accel_values_t acc_values;
        gyro_values_t gyro_values;
        magn_values_t magn_values;
        float pitch,roll,yaw; 	//Euler angles
    
        uint32_t sample_number = 0;
    
        const uint8_t MAG_DATA_SIZE = 10;
        uint8_t magn_data[MAG_DATA_SIZE];
        memset(magn_data, 0, MAG_DATA_SIZE);
        
    
        while(1)
        {
            if(NRF_LOG_PROCESS() == false)
            {
                // Read accelerometer and Gyro sensor values
                err_code = app_mpu_read_accel(&acc_values);
                APP_ERROR_CHECK(err_code);
                
                err_code = app_mpu_read_gyro(&gyro_values);
                APP_ERROR_CHECK(err_code);
    
                // Read magnetometer sensor values
                err_code = app_mpu_read_magnetometer(&magn_values, NULL);
                APP_ERROR_CHECK(err_code);
        
    //        if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
    //            {
    //                NRF_LOG_RAW_INFO("Euler angle: \r\t roll: %06d\r\t pitch: %06d\r\t yaw: %06d\r\n",(int)(roll*100),(int)(pitch*100),(int)(yaw*10));
    //            }
    
               // print values
                NRF_LOG_INFO("Sample count # %d\r", ++sample_number);
                NRF_LOG_INFO("The Acc  X: %06d\r Y: %06d\r Z: %06d", acc_values.x, acc_values.y, acc_values.z);
                NRF_LOG_INFO("The Gyro X: %06d\r Y: %06d\r Z: %06d", gyro_values.x, gyro_values.y, gyro_values.z);
                NRF_LOG_INFO("The Magn X: %06d\r Y: %06d\r Z: %06d", magn_values.x, magn_values.y, magn_values.z);
                NRF_LOG_RAW_INFO(" \n ");
                
                NRF_LOG_RAW_INFO("******************* \n ");
                nrf_gpio_pin_toggle(LED);
                nrf_delay_ms(150);
            }
        }
    }
    
    /** @} */
    
    

    here the code attached.

    The Time out error away happened on this statement whne it presents on the code

    err_code = app_mpu_read_magnetometer(&magn_values, NULL);
     APP_ERROR_CHECK(err_code);

    I just simply add the DMP initialize routines, and print 9-axis values only. The DMP works fine for both gyro and Accel reading.

  • Did you connect and configure the MPU device with TWI or SPI interface? Did you test the magnetometer example?

Related