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

send packets continuously in ble_app_uart example

I have to send packages continuously; How can I get feedback on the success of transmission before sending the next package? Which event should I use? and in what callback function?

I'm using SDK 15 and softdevice 6.0. The event BLE_EVT_TX_COMPLETE is missing in ble.h

Thanks

Parents
  • Hi,

     

    You can use the BLE_GATTS_EVT_HVN_TX_COMPLETE event to know that a Handle Value Notification transmission has completed. (This is allready used in the NUS implementation, ble_nus.c). Note that you can queue more than one, but you will get NRF_ERROR_RESOURCES returned when there are too many in the queue. In that case, you have to wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE event before you call ble_nus_data_send() (or sd_ble_gatts_hvx()) again.

  • Hello, I wait the event BLE_GATTS_EVT_HVN_TX_COMPLETE before the next transmission with ble_nus_data_send(). Please see the while loop in the main:

        // Enter main loop.
        for (;;)
        {
            //idle_state_handle();
    
            if ((flag_connected==1)&&(flag_transmitted==1))
            //if (flag_connected==1)
    	{
              flag_transmitted = 0;
              
              //nrf_delay_ms(100);
              nrf_gpio_pin_toggle(OUT_COMP);
              SendData();
    
              num_packets++;
                                               
    	}
    
        }

    the flag_transmitted is asserted in following function handler:

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
        int break_point;
        char debug_str[10] = {0};
    
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
    
            NRF_LOG_DEBUG("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);
    
            break_point = 25;
    
            // **************** ha ricevuto i dati su BLE RX, commentato il blocco inferiore che li rigirava sulla UART fisica
            /*
            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);
            }
            */
        }
        else if (p_evt->type == BLE_NUS_EVT_TX_RDY)
        {
            flag_transmitted = 1;
    
            NRF_LOG_INFO("TX OK");
            //sprintf(debug_str, "numbers of packets = %d", num_packets);
            //NRF_LOG_INFO("%s",(uint32_t)debug_str);
        }
    
    }

    then, at the connection, the continuous transmission starts. About 6000 packages can be transmitted  before the software goes to the function "__WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)" with error 19 "NRF_ERROR_RESOURCES".

    Every transmission I toggle a pin, please see the attached image of the monitoring of pin with the scope. Every change of level is a transmission

    A scope division i 5 ms and this is a very strange behaviour because I set the connction interval at 15 ms.

    What do you think?

  • Good morning,

    I declared the flag as volatile, but the behaviour is the same. I have more information for you:

    If I send only 1000 packets witn the same code the app on iOS does not freeze, but If I disconnect the Nordic and I connect again I have the following error in the function "app_error_weak.c" of chip:

    app: ERROR 13313 [Unknown error code]

    Please see the following screenshot; the line number is always "APP_ERROR_CHECK(err_code);" in SendData(void).

    Best regards

    Mario

  • Ok.

    The error 13313 = 0x3401 means that the CCCD of the characteristic is not set. That means that the phone has not enabled the notification yet, when you try to send the notification.

     

    You can ignore this err_code. That is, don't send it to an APP_ERROR_CHECK(), but be aware that the message is not sent. Try to send it again. Once you call it after the notification is enabled, it should return NRF_SUCCESS.

     

    BR,

    Edvin

  • Hello, thank you for the great support.

    A last question:

    I believed that only in BLE 5.0 I can send more packets in a connection interval. It's true?

    This is because I connected the nordic to phones with BLE <5.0 and then it seems that more packets are being sent every connection interval.

  • That is not entirely true.

    Different devices supports different features in BLE. Some are BLE5 features, while some are not.

     

    The only BLE5 specific feature that makes a difference in throughput is 2MBPS. 

    Other than that, different phones support different MTU sizes, and some support DLE while others don't. This will affect the number of packets that can be sent every connection interval.

     

    BR,

    Edvin

  • Thank you.

    For me the ticket is closed.

    Best regards

Reply Children
No Data
Related