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

ble_nus_data_send returns 0x5 error code

Hello,

I wanted to send data over peripheral device to the central device by using ble UART example. I used ble_nus_data_send() function in main(void) function. I have checked if the data was sent or not . ble_nus_data_send() returned 0x5 instead of NRF_SUCCESS. I also tried to use it in main() function, but nothing changed.

My ultimate goal is to send data when peripheral and central device pair each other.

Best Regards

  • Hi,

    the error says "not found ". may be connection lost

    #define NRF_ERROR_NOT_FOUND                   (NRF_ERROR_BASE_NUM + 5)  ///< Not found

    you can post the code here. let it check

  • Okay, let me know if I you want to check another function. Do I have to edit uart_event_handle() function ?

    int main(void)
    {
        bool erase_bonds;
    
        // 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();
    
        // Start execution.
        printf("\r\nUART started.\r\n");
        NRF_LOG_INFO("Debug logging for UART over RTT started.");
        advertising_start();
    
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN] = "Hello World";
            uint16_t length = 11;
    
            ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
            uint32_t err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
    
            NRF_LOG_INFO ("ble_nus_data_send returned 0x%x", err_code)
    
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }
    

  • I am not found any error in the code. rather i found the cause of 0x5 because . at the time of sending the device didn't connected with central or mobile.

    i just you to send the data once you connected with the central.

    the peripheral need to know the device connected to other and then you send the data it will be success

  • Yeah, you are right. ble_nus_data_send()  function is executed before the peripheral and central device connect each other. That's why I get this info on RTT viewer :

    00> <info> app: Debug logging for UART over RTT started.
    00> <info> app: ble_nus_data_send returned 0x5
    00> <info> app: Connected
    00> <info> app: Data len is set to 0x14(20)

    The function needs to be executed after the devices connect each other. Should I call the function in somewhere else ?

  • yes, you can call the function one after the BLE_ CONNECTED

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
                NRF_LOG_INFO("Connected");
                err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
                APP_ERROR_CHECK(err_code);
                m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
                err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
                APP_ERROR_CHECK(err_code);
                ..
                data_send();// you call the function ...
                
                break;
    ....
    ....
    ...
    }
    }

Related