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

(Edit) It is difficult to output the sensor value through the ble_app_uart.

Hello

I am using SDK v17 and nRF52DK board (PCA10040) and testing mpu6050 sensor.

I want to print out the sensor value through the app through ble_app_uart. 

Before sending the sensor values through the app, I would like to test the output at the terminal.
However, there is a problem merging to the ble_app_uart code.

Bluetooth connections work well, but debugging will cause 'NRF_BREKPOINT_COND;'error. Printed at 'err_code = app_mpu_read_accel (& accel_values)

//mpu6050
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
    p_mpu_config.gyro_config.fs_sel = AFS_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 
}


int main(void)
{
    bool erase_bonds;
    uint32_t err_code;


    // Initialize.
    uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
    
    mpu_init(); //add

    // Start execution.
    printf("\r\nUART started.\r\n");
    NRF_LOG_INFO("Debug logging for UART over RTT started.");
    advertising_start();

    accel_values_t accel_values; //mpu6050
    gyro_values_t gyro_values;

    // Enter main loop.
    for (;;)
    {
        idle_state_handle(); //sleep mode


        //MPU6050 CODE
        if (NRF_LOG_PROCESS() == false)
        {
            //app_mpu_read_accel(&accel_values);
            //app_mpu_read_gyro(&gyro_values);
            
            err_code = app_mpu_read_accel(&accel_values);
            APP_ERROR_CHECK(err_code);
            //err_code = app_mpu_read_gyro(&gyro_values);
            //APP_ERROR_CHECK(err_code);

            //Accel value
            NRF_LOG_INFO("Accel_X : "NRF_LOG_FLOAT_MARKER"", NRF_LOG_FLOAT(accel_x)); //float print
            NRF_LOG_INFO("Accel_Y : "NRF_LOG_FLOAT_MARKER"", NRF_LOG_FLOAT(accel_y));
            NRF_LOG_INFO("Accel_Z : "NRF_LOG_FLOAT_MARKER"", NRF_LOG_FLOAT(accel_z));


            nrf_delay_ms(500);

            //start_accel_update_flag = false;
        }
    }
}
3480.ble_app_uart.zip3312.mpu6050.zip


I attached the project because there may be a problem with other parts.

The mpu6050 was placed in the \nRF5_SDK_17.0.0_9d13099\examples path.

Can you tell me the problem?
Thank you in advance.

================================================ ================================================ ======
Adds output from the debug terminal.

               

  • Hi,

    I see you have success with using a 10 byte long array with a text:

        //char array[10] = "HELLOW"; //Success

    But from the comment I understand you get an error when the buffer size increases:

        //char array[100]; //Broken character output_1

    You also experiment with other data types, but that is a dead-end. The problem seems related to the increase in size, as the increase from 10 to 100 causes problems with ble_nus_data_send().

    schosdas said:
    However, the text is broken and printed as shown in the picture below.
    Is 'array[]' wrong?

     The text strings in the screenshot start with 0.07 and 0.06, which I assume is correct? The rest of the data is just nonsense, which is expected, as you transitt the whole length of the array, but what you really want to transmit is probably just the length of the string?

    If so, you should not calculate the length like this taking the length of the array (which you do now):

        uint16_t length = sizeof(array);

    but instead take the length of the string:

        uint16_t length = strlen(array);

    Note that strlen() does not include the null termination, so if you want that you should add 1 to the length.

  • Aha, I think it's a problem caused by the output of the blank space in the array. Let me check.
    Thank you!

Related