NRF528540 with MPU9255 Problem

Hello guys, i currently applying the example about MPU9255 following this:GitHub - Martinsbl/nrf5-mpu-examples

i'm using the app_mpu.c, app_mpu.h, mpu9255_register_map.h, nrf_drv_mpu.h, nrf_drv_mpu_twi.c to create new project with the main.c and sdk config in nrf5-mpu-simple. 

when i build and log showing this error. Could anyone help me with this, many thank,

Kyle. 

Parents
  • Hello,

    Line 35 in main.c in the nrf5-mpu-simple application is just a comment, so obviously you did some modifications, at least removed the comments on the top. 

    What function returned the error 13 that was passed into your APP_ERROR_CHECK(err_code) in main.c on line 35?

    Are you using Keil? Did you add the preprocessor definitions MPU9255 and MPU_USES_TWI to your project settings, according to the readme file in the github repository that you linked to?

    Best regards,

    Edvin

  • Hello Edvin, 

    The line 35 in my main.c is ret_code = app_mpu_config(&p_mpu_config); // Configure the MPU with above values

    The function that return error 13 is the mpu_init function.

    I'm using segger embedded studio but i'm already add the preprocessor definitions MPU9255 and MPU_USES_TWI.

    Best regards,

    Kyle

  • Hello,

    Can you please send me the main.c file (your latest version) with the corresponding error log. The log would not say what it says if your line 35 is ret_code_t = app_mpu_config(...).

    mpu_init() doesn't return any parameters (at least not in the unmodified nrf5-mpu-init\main.c file). 

    But I guess it is app_mpu_config() that returns 13, then. If that is the case, it looks like the nrf_drv_mpu_write_registers() returns NRF_ERROR_TIMEOUT, meaning that nrf_drv_twi_xfer() doesn't receive a callback. Is the MPU powered? Have you tried to analyze the TWI pins using a logic analyzer? Is the TWI data sent from the nRF? And does the MPU reply over TWI?

    Best regards,

    Edvin

  • Hello, 

    This is my main.c file 

     /* 
      * This example is not extensively tested and only 
      * meant as a simple explanation and for inspiration. 
      * NO WARRANTY of ANY KIND is provided. 
      */
    
    #include <stdio.h>
    #include "boards.h"
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "app_mpu.h"
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    
    /**@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();
    }
    
    
    void mpu_init(void)
    {
        ret_code_t ret_code;
        // Initiate MPU driver
        ret_code = app_mpu_init();
        APP_ERROR_CHECK(ret_code); // Check for errors in return value
        
        // Setup and configure the MPU with intial 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 
    }
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {    
        uint32_t err_code;
        
        // Initialize.
        log_init();
    	NRF_LOG_INFO("\033[2J\033[;H"); // Clear screen
        
        mpu_init();
        
        // Start execution.
        NRF_LOG_INFO("MPU Free Fall Interrupt example.");
        
        accel_values_t acc_values;
        uint32_t sample_number = 0;
        
        while(1)
        {
            if(NRF_LOG_PROCESS() == false)
            {
                // Read accelerometer sensor values
                err_code = app_mpu_read_accel(&acc_values);
                APP_ERROR_CHECK(err_code);
                // Clear terminal and print values
                NRF_LOG_INFO("\033[3;1HSample # %d\r\nX: %06d\r\nY: %06d\r\nZ: %06d", ++sample_number, acc_values.x, acc_values.y, acc_values.z);
                nrf_delay_ms(250);
            }
        }
    }
    
    /** @} */
    
    
     

    The MPU was powered and i have built 1 project before to test the response of TWI it's work normally, but the init of MPU is fail, idk why?

     

    Best regards,

    Kyle

Reply
  • Hello, 

    This is my main.c file 

     /* 
      * This example is not extensively tested and only 
      * meant as a simple explanation and for inspiration. 
      * NO WARRANTY of ANY KIND is provided. 
      */
    
    #include <stdio.h>
    #include "boards.h"
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "app_mpu.h"
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    
    /**@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();
    }
    
    
    void mpu_init(void)
    {
        ret_code_t ret_code;
        // Initiate MPU driver
        ret_code = app_mpu_init();
        APP_ERROR_CHECK(ret_code); // Check for errors in return value
        
        // Setup and configure the MPU with intial 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 
    }
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {    
        uint32_t err_code;
        
        // Initialize.
        log_init();
    	NRF_LOG_INFO("\033[2J\033[;H"); // Clear screen
        
        mpu_init();
        
        // Start execution.
        NRF_LOG_INFO("MPU Free Fall Interrupt example.");
        
        accel_values_t acc_values;
        uint32_t sample_number = 0;
        
        while(1)
        {
            if(NRF_LOG_PROCESS() == false)
            {
                // Read accelerometer sensor values
                err_code = app_mpu_read_accel(&acc_values);
                APP_ERROR_CHECK(err_code);
                // Clear terminal and print values
                NRF_LOG_INFO("\033[3;1HSample # %d\r\nX: %06d\r\nY: %06d\r\nZ: %06d", ++sample_number, acc_values.x, acc_values.y, acc_values.z);
                nrf_delay_ms(250);
            }
        }
    }
    
    /** @} */
    
    
     

    The MPU was powered and i have built 1 project before to test the response of TWI it's work normally, but the init of MPU is fail, idk why?

     

    Best regards,

    Kyle

Children
Related