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

How to configure nRF82540 for using multiple BLE packages in one connection interval?

Hi,

I try to achieve high throughput via BLE connection between two nRF82540dk boards. I would like to maximize duty cycle of transmission in the connection interval.
Unfortunately I observe only one or two BLE packets in each interval.
How can I configure SoftDevice to transmit more packets in one interval?

I use slighly modified ble_app_uart_c_pca10056_s140 and ble_app_uart_pca10056_s140 as starting point examples for the serial connection.
A stream of 244 bytes packets is sent from peripheral to the central device. 

Other options:
1) BLE PHY 2Mbps,
2) Connection interval = 7.5ms
3) NRF_SDH_BLE_GAP_EVENT_LENGTH = 6

Kind regards,

Piotr Romaniuk

  • Hi Karl,

    Piotr, I think a lot of this confusion could have been avoided if you had read the steps I wrote out more carefully. I specifically mentioned the 'common' configuration twice, and it is also visible in the screenshot I sent you.

    I am sorry, I overlooked that. Thank you for the explanation.

    By this, do you mean that the blue channel indicates calls to 'ble_nus_data_send', for queueing of data to be transferred?

    Yes. It is toggled every time when ble_nus_data_send() returns something else than NRF_ERROR_RESOURSES, see below:

        for(i = 0; i < 30; i++){
            data_array[1] = '@'+i;
            do
            {
                uint16_t length = (uint16_t)index+1;
                err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
                
                
            } while (err_code == NRF_ERROR_RESOURCES);
            nrf_gpio_pin_toggle( pin_dbg2 );
        }

    The length of the signal levels between edges corresponds to periods when above code is not active or is spinning in while - means waiting for the BLE stack untill it accepts a packet for transfer. Looking to oscilogram, one can see that it is synchronized with transmission, hence my conclussion about some queue capacity inside the stack. Also returning code NRF_ERROR_RESOURCES suggests that some resources are not available.

    What MTU size are you using for your transfers, when changing to 10 or 50 ms connection intervals?

    I did not change MTU for 10 or 50ms connection interval, it is: 

       NRF_SDH_BLE_GATT_MAX_MTU_SIZE = 247

    Is the call to ble_nus_data_send (which in turn calls sd_ble_gatts_hvx) returning any errors, such as NRF_ERROR_RESOURCES, when you try to queue your data for transfer?

    Yes, I followed calling path. From my code I conclude that NRF_ERROR_RESOURCES is returned.

    How have you ensured that there is enough data queued for transer to fill the entire connection interval of 50 ms?

    I cannot queue more, because of returned above error. I am trying continuously add more - see while loop.

    Please elaborate what you are referring to when you say '(dynamic memory)'.
    Are you using dynamic memory allocation in your application, and asking if this may interfere with the SoftDevice's data queueing process?

    I just was trying to explain why there is problem with resources in BLE stack. I am not using dynamic memory in my software. I tried to increase heap size and increase RAM_START, but it did not help.

    Mayby there is some limited size of queue on central device site?

    Kind regards,
    Piotr Romaniuk

    PS
    What is  general architecture of BLE stack? Does it use some threads, or is only interrupt driven?
    I am asking just to understand how main processor is loaded with BLE stack operation.
    I am aware of general mechanism: SVC calls and designated interrupt for event signaling from the stack.

  • Hello Piotr,

    Piotr Romaniuk said:
    I am sorry, I overlooked that. Thank you for the explanation.

    No need to apologies, it is no problem at all - I am happy to help! :)

    Piotr Romaniuk said:
    Yes. It is toggled every time when ble_nus_data_send() returns something else than NRF_ERROR_RESOURSES, see below:
    Piotr Romaniuk said:
    The length of the signal levels between edges corresponds to periods when above code is not active or is spinning in while - means waiting for the BLE stack untill it accepts a packet for transfer. Looking to oscilogram, one can see that it is synchronized with transmission, hence my conclussion about some queue capacity inside the stack. Also returning code NRF_ERROR_RESOURCES suggests that some resources are not available.

    Ah, yes, I remember this now. Thank you for clarifying, this is very helpful information.
    Looking at the oscilloscope picture you sent earlier, it then seems to me that the radio is in fact being used for the entire connection interval length - given that the picture was taken while using a 7.5 ms connection interval.
    Regarding that only 4 packets seem to be sent per 50 ms interval, this is then the problem we are currently looking into?
    It is hard to say exactly what is going on from the oscilloscope screenshot as opposed to a sniffer trace, but it is up to the central to dictate how many packets actually will be sent each event, since the central has to prompt each and every one of the packets.

    The returned NRF_ERROR_RESOURCES from sd_ble_gatts_hvx just means that the queue is filled up with data queued for transfer, so this is alright in your case.

    Could you take another oscilloscope screenshot of the test you are conducting, taken from the central side, using 50 ms connection interval? 
    It would be interesting to see whether the central stops prompting for more packets.
    How many transfers of how many bytes is successful each interval?
    These are all things that would be easy to see in a sniffer trace, but we will try to make due with the oscilloscope pictures to understand what is happening.

    In case the the oscilloscope screenshots prove futile for debugging this issue, you could download the nRF Connect application for Smartphones on your phone, and use that as a central connected to your peripheral device. This way, you should be able to use the freed up device as the sniffer, and produce a sniffer trace of their communication.

    Piotr Romaniuk said:

    I just was trying to explain why there is problem with resources in BLE stack. I am not using dynamic memory in my software. I tried to increase heap size and increase RAM_START, but it did not help.

    Mayby there is some limited size of queue on central device site?

    I see - I just had to make sure what you were referring to. Increasing RAM_START and heap_size does not change this, no.
    What is your hvn_tx_queue_size on your peripheral side of the link?

    Best regards,
    Karl

  • Hi Karl,

    Sorry for delay in my response but I had to switch to another project.

    Looking at the oscilloscope picture you sent earlier, it then seems to me that the radio is in fact being used for the entire connection interval length - given that the picture was taken while using a 7.5 ms connection interval.

    Yes, it is much better, but you can observe a gap every 4 packets. 
    I suspected that more cannot fit into such a small connection interval, so I tried to increase that parameter.
    Unfortunatelly, still and only 4 packets were transmitted every one cycle.

    It looks like there is another limitation.

    Could you take another oscilloscope screenshot of the test you are conducting, taken from the central side, using 50 ms connection interval? 

    There will be 4 packets at the begining of the cycle, then long gap to next cycle. Each packet is 244 bytes long on data payload.

    you could download the nRF Connect application for Smartphones on your phone, and use that as a central connected to your peripheral device. This way, you should be able to use the freed up device as the sniffer, and produce a sniffer trace of their communication.

    Thank you for this suggestion it is good idea.

    What is your hvn_tx_queue_size on your peripheral side of the link?

    Should I read this parameter or it should be set?
    I browsed the code, I cannot find reference to that in the code, I probably don't set it. I only call nrf_sdh_ble_default_cfg_set() that is in nrf_sdh_ble.c (in ble_uart example) but it doesn't set it.

    Kind regards,
    Piotr Romaniuk

  • Hello Piotr,

    Piotr Romaniuk said:
    Sorry for delay in my response but I had to switch to another project.

    No problem at all, I completely understand. Do not worry about any delays - we'll continue with the debugging whenever you are ready.

    Piotr Romaniuk said:

    I suspected that more cannot fit into such a small connection interval, so I tried to increase that parameter.
    Unfortunatelly, still and only 4 packets were transmitted every one cycle.

    It looks like there is another limitation.

    Piotr Romaniuk said:
    There will be 4 packets at the begining of the cycle, then long gap to next cycle. Each packet is 244 bytes long on data payload.

    Yes, this is where a sniffer trace would be tremendously helpful. With a sniffer trace of the communication we could immediately rule out some issues and potential sources of errors - such as the central not prompting for more packets, etc.  

    Piotr Romaniuk said:
    Thank you for this suggestion it is good idea.

    I am glad it could be helpful. I look forward to taking a look at the sniffer trace you produce of the on-air communication. It will be very helpful to have a look at.

    Piotr Romaniuk said:
    Should I read this parameter or it should be set?

    You can set this parameter yourself to change the notification TX buffer, so that you are able to queue more data for transfer (more successful calls to sd_ble_gatts_hvx before NRF_ERROR_RESOURCES is returned) before each connection event.

    If you do not set it yourself, it will use the default value of 1. The variable determines 'the minimum guaranteed number of notifications that can be queued for transmission'.
    Try to increase this to 10, for example.

    Best regards,
    Karl

Related