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

nRF52832 and mpu6050

I am trying to program mpu_simple https://github.com/Martinsbl/nrf5-mpu-examples with Segger, and I get to connect sensor MPU6050 to my board but I do not receive datas of sensor.

I have configured Segger with the device and twi. The code is this:

 /* 
  * 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
    
    app_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);
        }
    }
}

/** @} */

Can you tell me why I do not receive any datas of sensor MPU?

Parents
  • hi,

      in which sdk did you ported this example. what error did you get

  • Hi,

    I am working with SDK 14.2 and I do not get an error but I do not receive the values of MPU6050

  • hi,

    in that github file take this example nrf5-ble-mpu-simple. this one will work

  • Hi,

    I am with the first example now, but I do not get any datas yet. I do not know where it prints the values. So I am gonna program the next example nrf5-ble-mpu-simple.

  • hi, 

    try that example it will work. i have done this for nrf52840 before 2 months itself. they had released for nrf52832 and nrf52840 now. so no need to make any changes it will work fine

  • It will be printed over the UART. Are you using a nRF52832-DK? If yes, then you should be able to see the printed data using a terminal program, such as Termite. You can download Termite from this link.

  • HI,

    I am using same github library. instead of keil i want to work in segger. but there is no SES file for the MPU library is there any SES file available..?

    and also i am trying to alternate  " ble_app_uart_pca10040_s132 "   segger solution to work in this MPU library which is SDK 15.2.

    for that i also got the error  #error "No MPU defined. Please define MPU in Target Options C/C++ Defines"

    and more error like

    Rebuilding ‘ble_app_uart_pca10040_s132 - MPU’ from solution ‘ble_app_uart_pca10040_s132 - MPU’ in configuration ‘Release’
      Assembling ‘thumb_crt0.s’
      Compiling ‘nrf_log_backend_rtt.c’
      Compiling ‘nrf_log_backend_serial.c’
      Compiling ‘nrf_log_default_backends.c’
      Compiling ‘nrf_log_frontend.c’
      Compiling ‘nrf_log_str_formatter.c’
      Compiling ‘app_button.c’
      Compiling ‘app_error.c’
      Compiling ‘app_error_handler_gcc.c’
      Compiling ‘app_error_weak.c’
      Compiling ‘app_fifo.c’
      Compiling ‘app_scheduler.c’
      Compiling ‘app_timer.c’
      Compiling ‘app_uart_fifo.c’
      Compiling ‘app_util_platform.c’
      Compiling ‘hardfault_implementation.c’
      Compiling ‘nrf_assert.c’
      Compiling ‘nrf_atfifo.c’
      Compiling ‘nrf_atflags.c’
      Compiling ‘nrf_atomic.c’
      Compiling ‘nrf_balloc.c’
      Compiling ‘nrf_fprintf.c’
      Compiling ‘nrf_fprintf_format.c’
      Compiling ‘nrf_memobj.c’
      Compiling ‘nrf_pwr_mgmt.c’
      Compiling ‘nrf_ringbuf.c’
      Compiling ‘nrf_section_iter.c’
      Compiling ‘nrf_strerror.c’
      Compiling ‘retarget.c’
      Assembling ‘ses_startup_nrf52.s’
      Assembling ‘ses_startup_nrf_common.s’
      Compiling ‘system_nrf52.c’
      Compiling ‘boards.c’
      Compiling ‘nrf_drv_clock.c’
      Compiling ‘nrf_drv_uart.c’
      Compiling ‘nrfx_clock.c’
      Compiling ‘nrfx_gpiote.c’
      Compiling ‘nrfx_power_clock.c’
      Compiling ‘nrfx_prs.c’
      Compiling ‘nrfx_uart.c’
      Compiling ‘nrfx_uarte.c’
      Compiling ‘bsp.c’
      Compiling ‘bsp_btn_ble.c’
      Compiling ‘nrf_drv_mpu_spi.c’
      Compiling ‘nrf_drv_mpu_twi.c’
      Compiling ‘main.c’
        app_mpu.h: No such file or directory
      Compiling ‘app_mpu.c’
        app_mpu.c
        #error "No MPU defined. Please define MPU in Target Options C/C++ Defines"
        app_mpu.c
        #error "No/unknown MPU defined"
        app_mpu.c
        #elif with no expression
        'MPU_REG_SMPLRT_DIV' undeclared (first use in this function)
        each undeclared identifier is reported only once for each function it appears in
        'MPU_REG_INT_PIN_CFG' undeclared (first use in this function)
        'MPU_REG_INT_ENABLE' undeclared (first use in this function)
        'MPU_REG_SIGNAL_PATH_RESET' undeclared (first use in this function)
        'MPU_REG_PWR_MGMT_1' undeclared (first use in this function)
        'MPU_REG_ACCEL_XOUT_H' undeclared (first use in this function)
        'MPU_REG_GYRO_XOUT_H' undeclared (first use in this function)
        'MPU_REG_TEMP_OUT_H' undeclared (first use in this function)
        'MPU_REG_INT_STATUS' undeclared (first use in this function)
      Compiling ‘ble_mpu.c’
        ble_mpu.h
        ble_mpu.c
        #error "No MPU defined. Please define MPU in Target Options C/C++ Defines"
        ble_mpu.h
        ble_mpu.c
        #error "No/unknown MPU defined"
      Compiling ‘SEGGER_RTT.c’
    Build failed

Reply
  • HI,

    I am using same github library. instead of keil i want to work in segger. but there is no SES file for the MPU library is there any SES file available..?

    and also i am trying to alternate  " ble_app_uart_pca10040_s132 "   segger solution to work in this MPU library which is SDK 15.2.

    for that i also got the error  #error "No MPU defined. Please define MPU in Target Options C/C++ Defines"

    and more error like

    Rebuilding ‘ble_app_uart_pca10040_s132 - MPU’ from solution ‘ble_app_uart_pca10040_s132 - MPU’ in configuration ‘Release’
      Assembling ‘thumb_crt0.s’
      Compiling ‘nrf_log_backend_rtt.c’
      Compiling ‘nrf_log_backend_serial.c’
      Compiling ‘nrf_log_default_backends.c’
      Compiling ‘nrf_log_frontend.c’
      Compiling ‘nrf_log_str_formatter.c’
      Compiling ‘app_button.c’
      Compiling ‘app_error.c’
      Compiling ‘app_error_handler_gcc.c’
      Compiling ‘app_error_weak.c’
      Compiling ‘app_fifo.c’
      Compiling ‘app_scheduler.c’
      Compiling ‘app_timer.c’
      Compiling ‘app_uart_fifo.c’
      Compiling ‘app_util_platform.c’
      Compiling ‘hardfault_implementation.c’
      Compiling ‘nrf_assert.c’
      Compiling ‘nrf_atfifo.c’
      Compiling ‘nrf_atflags.c’
      Compiling ‘nrf_atomic.c’
      Compiling ‘nrf_balloc.c’
      Compiling ‘nrf_fprintf.c’
      Compiling ‘nrf_fprintf_format.c’
      Compiling ‘nrf_memobj.c’
      Compiling ‘nrf_pwr_mgmt.c’
      Compiling ‘nrf_ringbuf.c’
      Compiling ‘nrf_section_iter.c’
      Compiling ‘nrf_strerror.c’
      Compiling ‘retarget.c’
      Assembling ‘ses_startup_nrf52.s’
      Assembling ‘ses_startup_nrf_common.s’
      Compiling ‘system_nrf52.c’
      Compiling ‘boards.c’
      Compiling ‘nrf_drv_clock.c’
      Compiling ‘nrf_drv_uart.c’
      Compiling ‘nrfx_clock.c’
      Compiling ‘nrfx_gpiote.c’
      Compiling ‘nrfx_power_clock.c’
      Compiling ‘nrfx_prs.c’
      Compiling ‘nrfx_uart.c’
      Compiling ‘nrfx_uarte.c’
      Compiling ‘bsp.c’
      Compiling ‘bsp_btn_ble.c’
      Compiling ‘nrf_drv_mpu_spi.c’
      Compiling ‘nrf_drv_mpu_twi.c’
      Compiling ‘main.c’
        app_mpu.h: No such file or directory
      Compiling ‘app_mpu.c’
        app_mpu.c
        #error "No MPU defined. Please define MPU in Target Options C/C++ Defines"
        app_mpu.c
        #error "No/unknown MPU defined"
        app_mpu.c
        #elif with no expression
        'MPU_REG_SMPLRT_DIV' undeclared (first use in this function)
        each undeclared identifier is reported only once for each function it appears in
        'MPU_REG_INT_PIN_CFG' undeclared (first use in this function)
        'MPU_REG_INT_ENABLE' undeclared (first use in this function)
        'MPU_REG_SIGNAL_PATH_RESET' undeclared (first use in this function)
        'MPU_REG_PWR_MGMT_1' undeclared (first use in this function)
        'MPU_REG_ACCEL_XOUT_H' undeclared (first use in this function)
        'MPU_REG_GYRO_XOUT_H' undeclared (first use in this function)
        'MPU_REG_TEMP_OUT_H' undeclared (first use in this function)
        'MPU_REG_INT_STATUS' undeclared (first use in this function)
      Compiling ‘ble_mpu.c’
        ble_mpu.h
        ble_mpu.c
        #error "No MPU defined. Please define MPU in Target Options C/C++ Defines"
        ble_mpu.h
        ble_mpu.c
        #error "No/unknown MPU defined"
      Compiling ‘SEGGER_RTT.c’
    Build failed

Children
Related