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

no communication between custom PCB and mpu6050

Hello,

I used a breakout board of the MPU6050 (playground.arduino.cc/.../mpu-6050.jpg) and the nrf52832 development board. There is communication between the two and I have no problems retrieving data from the MPU6050. However, when I put the mpu6050 and nrf52832 on a custom PCB there is no communication between the two (i.e. no clock signals). The MPU6050 are close to the nrf52832 so there is minimal noise interference. I can provide more information. I'm just not sure what I should add.

Has anyone come across this problem or has ideas to solve this?

Parents
  • Hi Adrian,

    I suggest that you take a look at the nRF5x examples in this GitHub repo .

    Best regards

    Bjørn

  • Hi Bjorn,

    I have used that repo, but I have problems building the program (example nrf_mpu_simple).

    This is the code and errors:

     /* 
      * 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"
    
    typedef struct
    {
        uint8_t             smplrt_div;         // Divider from the gyroscope output rate used to generate the Sample Rate for the MPU-9150. Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
        sync_dlpf_config_t  sync_dlpf_gonfig;   // Digital low pass fileter and external Frame Synchronization (FSYNC) configuration structure
        gyro_config_t       gyro_config;        // Gyro configuration structure
        accel_config_t      accel_config;       // Accelerometer configuration structure
    }app_mpu_config_t;
    
    /**@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);
            }
        }
    }
    
    /** @} */
    
    

    Building ‘template_pca10040’ from solution ‘template_pca10040’ in configuration ‘Debug’
      Compiling ‘main.c’
        conflicting types for 'app_mpu_config_t'
        main.c
        previous declaration of 'app_mpu_config_t' was here
        passing argument 1 of 'app_mpu_config' from incompatible pointer type [-Wincompatible-pointer-types]
        main.c
        expected 'app_mpu_config_t * {aka struct <anonymous> *}' but argument is of type 'app_mpu_config_t * {aka struct <anonymous> *}'
    Build failed

    Can you help me with this. I do not know where is the error.

Reply
  • Hi Bjorn,

    I have used that repo, but I have problems building the program (example nrf_mpu_simple).

    This is the code and errors:

     /* 
      * 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"
    
    typedef struct
    {
        uint8_t             smplrt_div;         // Divider from the gyroscope output rate used to generate the Sample Rate for the MPU-9150. Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
        sync_dlpf_config_t  sync_dlpf_gonfig;   // Digital low pass fileter and external Frame Synchronization (FSYNC) configuration structure
        gyro_config_t       gyro_config;        // Gyro configuration structure
        accel_config_t      accel_config;       // Accelerometer configuration structure
    }app_mpu_config_t;
    
    /**@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);
            }
        }
    }
    
    /** @} */
    
    

    Building ‘template_pca10040’ from solution ‘template_pca10040’ in configuration ‘Debug’
      Compiling ‘main.c’
        conflicting types for 'app_mpu_config_t'
        main.c
        previous declaration of 'app_mpu_config_t' was here
        passing argument 1 of 'app_mpu_config' from incompatible pointer type [-Wincompatible-pointer-types]
        main.c
        expected 'app_mpu_config_t * {aka struct <anonymous> *}' but argument is of type 'app_mpu_config_t * {aka struct <anonymous> *}'
    Build failed

    Can you help me with this. I do not know where is the error.

Children
Related