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.

               

Parents
  • Hi,

    The project you uploaded is not buildable as it does not include the MPU code (app_mpu.c/.h), but I assume it is from nrf5-mpu-examples? There is also no usage of the mpu6050 other than the mpu_init() function, so I cannot say much based on that.

    However, I see that the program counter (PC) value when you get the SoftDevice assert is 0x00014cbc. I assume you use S132 7.0.1 (?), and in that case this is caused by the SoftDevice not being able to do a task in due time. A typical reason for this is that you spend too much time in a too high interrupt priority, blocking the SoftDevice for too long.

    Update: reading your question again I wonder if you only get the SoftDevice assert when debugging? If so, then please remember that you cannot continue after a break point or step in the code when using a SoftDevice, as this will cause the SoftDevice to assert because of the reason explained above. So to get the same debugging experience as stepping you need to set a breakpoint and run to that, then move the breakpoint, reset and run again. etc...

  • Hello, Einar!
    Thank you for helping me.

    But I'm still in the same problem.
    Added library file for mpu6050 and added 'mpu_init' to main() code.

    I use SDK v17.0 and Segger, and I worked on s132 of ble_app_uart.

    Can I know more about this problem?

    Thank you.

  • Hi,

    I am no longer able to read the original question. Please edit it again and translate it to English.

    Currently I unfortunately lack context in order to suggest anything. Please share the exact code you are testing so that I know I am looking at the correct code, ans specify which .zip that is. Also, please specify in detail what fails how, and what you would expect. 

  • Hi,

    I am still not sure about the question:

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

    This makes me think that the issue is that you get an error while debugging? If so, please see my first reply, explaining that you cannot step in the code or continuing from a breakpoint when using BLE.

    schosdas said:
    Can I know more about this problem?

    Is there also another problem? If so, please clarify what the problem is, how you have debubbed, what you have found (such as which error code you get form which function call on which line in which file, or other error condition)? What is happening, and what would you expect to happen?

  • Hello, Einar!
    I'm sorry for the late reply.

    Successfully output sensor values to serial terminal.

    And it was printed on the app.
    However, the text is broken and printed as shown in the picture below.
    Is 'array[]' wrong?

        

    static void send_data()
    {
        uint32_t err_code;
    
        accel_values_t accel_values; //mpu6050
        app_mpu_read_accel(&accel_values);          
        err_code = app_mpu_read_accel(&accel_values);
        APP_ERROR_CHECK(err_code);
    
        float accel_x = accel_values.x * 4.0 / 32768.0; //Conversion to decimal places for easy viewing
    
        printf("Aceel_X : %.2f \n", accel_x); //Success!
    
        //char array[10] = "HELLOW"; //Success
        //char array[100]; //Broken character output_1
        //uint8_t array[100]; //Broken character output_2
        uint16_t array[100]; //Broken character output_3
        uint16_t length = sizeof(array);
    
        sprintf(array, "%.2f", accel_x);
    
    
        err_code = ble_nus_data_send(&m_nus, &array, &length, m_conn_handle);
    
        if ((err_code != NRF_ERROR_INVALID_STATE) &&// 
                                (err_code != NRF_ERROR_RESOURCES) &&
                                (err_code != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code);
                            }
    }
    
    
    
       for (;;)
        {
            idle_state_handle(); //sleep mode
            send_data(); //send data to app
            nrf_delay_ms(500);
        }

    Thank you in advance!
Reply
  • Hello, Einar!
    I'm sorry for the late reply.

    Successfully output sensor values to serial terminal.

    And it was printed on the app.
    However, the text is broken and printed as shown in the picture below.
    Is 'array[]' wrong?

        

    static void send_data()
    {
        uint32_t err_code;
    
        accel_values_t accel_values; //mpu6050
        app_mpu_read_accel(&accel_values);          
        err_code = app_mpu_read_accel(&accel_values);
        APP_ERROR_CHECK(err_code);
    
        float accel_x = accel_values.x * 4.0 / 32768.0; //Conversion to decimal places for easy viewing
    
        printf("Aceel_X : %.2f \n", accel_x); //Success!
    
        //char array[10] = "HELLOW"; //Success
        //char array[100]; //Broken character output_1
        //uint8_t array[100]; //Broken character output_2
        uint16_t array[100]; //Broken character output_3
        uint16_t length = sizeof(array);
    
        sprintf(array, "%.2f", accel_x);
    
    
        err_code = ble_nus_data_send(&m_nus, &array, &length, m_conn_handle);
    
        if ((err_code != NRF_ERROR_INVALID_STATE) &&// 
                                (err_code != NRF_ERROR_RESOURCES) &&
                                (err_code != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code);
                            }
    }
    
    
    
       for (;;)
        {
            idle_state_handle(); //sleep mode
            send_data(); //send data to app
            nrf_delay_ms(500);
        }

    Thank you in advance!
Children
  • 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