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

Not able to send data from nrf52840 to BLE for more than 1 minute.

Hi Everyone

I am able to configure BLE on the template project and it is sending data from nrf52840 to BLE nrfconnect app using the function nrf_ble_data_send() .

However i am getting into one problem, probably a minor issue.

nrf52840 cannot send data after 1 minute or so and in the DEBUG section or nrf5connect app , i see 0 bytes received.

But if i disable and enable the notification, i can see the data but only for another 1 minute or so.

What could be the reason of such error and how can it be resolved.

Thanks

Rajat!

void ble_init()
{
     bool erase_bonds;
    timers_init();

    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    advertising_start();
}

void ble_send(char *data_pointer)
{
 uint16_t temp_len = 0;
 while(*(data_pointer+temp_len)!='\0')
     {
       temp_len++;
     }

uint16_t length = (uint16_t)temp_len;

   ble_nus_data_send(&m_nus, data_pointer, &length, m_conn_handle);
   

}

int main()
{
ble_init();
while(1)
{
ble_send("ABC");
nrf_delay_ms(1000);

}
}

Parents
  • Just a little update

    My code is sending the data even when i put a while(1); statement after sending the data once.

    IN DEBUG section of Android app , i see 0bytes received , continously after around 50 miliseconds

  • Okay!

    Good news , the issue is resolved. I think i was too anxious that i posted it here , but it has been bugging me since a week or so.

    What i did was. Instead of writing data onto UART(because i am using another module on UART) , Whatever data i was receiving through bluetooth from nrfconnect to my nrf52840. I was sending that data back to the nrfconnect app(just to make sure data was reached to microcontroller). 

    In the nus event handler , i called the send_data function outside of the "if (event flag)" statement which made it to send the data again without any delay.

    It was a silly mistake ,but glad that its solved now.

    Here is the piece of code i was talking about.

    The error was on Line40. I moved the send function inside the "if(event flag)" 

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    char data_nus[10]="";
    
    /*
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
    
            printf("Received data from BLE NUS. Writing data on UART.");
            NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
                do
                {
                    err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
                    if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                    {
                        NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                        APP_ERROR_CHECK(err_code);
                    }
                } while (err_code == NRF_ERROR_BUSY);
            }
            if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            {
                while (app_uart_put('\n') == NRF_ERROR_BUSY);
            }
        }
    */
    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    {
    for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
    {
    data_nus[i]=p_evt->params.rx_data.p_data[i];
    
    }
    ble_nus_data_send(&m_nus, data_nus, &(p_evt->params.rx_data.length), m_conn_handle);
    }
    /*The BELOW STATEMENT WAS CAUSING THE BUG,BLOODY BUGGER*/
    /////ble_nus_data_send(&m_nus, data_nus, &(p_evt->params.rx_data.length), m_conn_handle);

Reply
  • Okay!

    Good news , the issue is resolved. I think i was too anxious that i posted it here , but it has been bugging me since a week or so.

    What i did was. Instead of writing data onto UART(because i am using another module on UART) , Whatever data i was receiving through bluetooth from nrfconnect to my nrf52840. I was sending that data back to the nrfconnect app(just to make sure data was reached to microcontroller). 

    In the nus event handler , i called the send_data function outside of the "if (event flag)" statement which made it to send the data again without any delay.

    It was a silly mistake ,but glad that its solved now.

    Here is the piece of code i was talking about.

    The error was on Line40. I moved the send function inside the "if(event flag)" 

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    char data_nus[10]="";
    
    /*
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
    
            printf("Received data from BLE NUS. Writing data on UART.");
            NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
                do
                {
                    err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
                    if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                    {
                        NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                        APP_ERROR_CHECK(err_code);
                    }
                } while (err_code == NRF_ERROR_BUSY);
            }
            if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            {
                while (app_uart_put('\n') == NRF_ERROR_BUSY);
            }
        }
    */
    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    {
    for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
    {
    data_nus[i]=p_evt->params.rx_data.p_data[i];
    
    }
    ble_nus_data_send(&m_nus, data_nus, &(p_evt->params.rx_data.length), m_conn_handle);
    }
    /*The BELOW STATEMENT WAS CAUSING THE BUG,BLOODY BUGGER*/
    /////ble_nus_data_send(&m_nus, data_nus, &(p_evt->params.rx_data.length), m_conn_handle);

Children
No Data
Related