Unusually high BLE connection latency

Hi, we're creating a BLE mouse. We've setup the HID service- clicking button 1 on the nrf52832DK sends left mouse button click- nothing else is being sent.

The problem: even though the connection interval is 6 * 1.25 ms (I've verified that the host device accepts this interval preference)- we're measuring a very high latency (average 80ms). Also, the pref. timeout is set to 100ms - we noticed the connection drop a few times- this means that latency is spiking to more than 100ms sometimes!

Peripheral pref. parameters:

CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=y
CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=6
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=6
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=10


Note that we're also making use of the UART Async API, Baud rate is set to 9600 and it transmits data every 200ms. Could UART be responsible for possibly degrading the connection?
Also, I've made UART uses 'timer 2', to make sure the BLE controller isn't affected by UART hogging up the default timer instance.

Here's the full config:

#TODO: organize configs

CONFIG_NCS_SAMPLES_DEFAULTS=n
CONFIG_BT=y
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=3
CONFIG_BT_ATT_TX_COUNT=5
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="CARBN"
CONFIG_BT_DEVICE_APPEARANCE=962

CONFIG_BT_BAS=y
CONFIG_BT_HIDS=y
CONFIG_BT_HIDS_MAX_CLIENT_COUNT=1
CONFIG_BT_HIDS_DEFAULT_PERM_RW_ENCRYPT=y
CONFIG_BT_GATT_UUID16_POOL_SIZE=40
CONFIG_BT_GATT_CHRC_POOL_SIZE=20

CONFIG_BT_CONN_CTX=y

CONFIG_BT_DIS=y
CONFIG_BT_DIS_PNP=y
CONFIG_BT_DIS_MANUF="NordicSemiconductor"
CONFIG_BT_DIS_PNP_VID_SRC=2
CONFIG_BT_DIS_PNP_VID=0x1915
CONFIG_BT_DIS_PNP_PID=0xEEEE
CONFIG_BT_DIS_PNP_VER=0x0100

CONFIG_MAIN_STACK_SIZE=1536
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_DK_LIBRARY=y



CONFIG_BT_SETTINGS=y
CONFIG_SETTINGS=y


CONFIG_CARBN_FIRMWARE_DEFAULT=y


CONFIG_APP_EVENT_MANAGER=y


CONFIG_CAF=y
CONFIG_CAF_BLE_STATE=y
CONFIG_REBOOT=y
CONFIG_HEAP_MEM_POOL_SIZE=2048


CONFIG_CAF_SETTINGS_LOADER=y
CONFIG_CAF_SETTINGS_LOADER_DEF_PATH="settings_loader.h"

CONFIG_CAF_BLE_COMMON_EVENTS=y
CONFIG_CAF_BLE_ADV=y
CONFIG_CAF_BLE_ADV_DIRECT_ADV=n
CONFIG_CAF_BLE_ADV_FAST_ADV=y
CONFIG_CAF_BLE_ADV_FAST_ADV_TIMEOUT=15
CONFIG_CAF_BLE_ADV_FILTER_ACCEPT_LIST=n
CONFIG_CAF_BLE_STATE_SECURITY_REQ=y
CONFIG_CAF_BLE_ADV_ROTATE_RPA=y
CONFIG_BT_PRIVACY=y
CONFIG_BT_ADV_PROV=y
CONFIG_BT_ADV_PROV_DEVICE_NAME=y
CONFIG_BT_ADV_PROV_DEVICE_NAME_SD=n
CONFIG_BT_ADV_PROV_GAP_APPEARANCE_SD=n
CONFIG_BT_ADV_PROV_GAP_APPEARANCE=y
CONFIG_BT_ADV_PROV_FLAGS=y
CONFIG_BT_SMP=y
CONFIG_BT_ID_MAX=5

CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=n
CONFIG_BT_BONDABLE=y

CONFIG_GPIO=y
CONFIG_CAF_BUTTONS=y
CONFIG_CAF_BUTTON_EVENTS=y
CONFIG_CAF_BUTTONS_SCAN_INTERVAL=2
CONFIG_CAF_BUTTONS_DEBOUNCE_INTERVAL=2
CONFIG_CAF_BUTTONS_DEF_PATH="buttons_def.h"
CONFIG_CAF_CLICK_DETECTOR=y
CONFIG_CAF_CLICK_DETECTOR_DEF_PATH="click_detector_def.h"
CONFIG_CAF_CLICK_DETECTOR_LONG_CLICK_MSEC=2500
CONFIG_CAF_CLICK_DETECTOR_SHORT_CLICK_MSEC=300
CONFIG_CAF_BUTTONS_LOG_LEVEL_DBG=y
CONFIG_CAF_BUTTONS_POLARITY_INVERSED=y
CONFIG_CAF_POWER_MANAGER=n
CONFIG_SHELL=n



# Enable CAF_LEDS
CONFIG_LED=y
CONFIG_PWM=y
CONFIG_LED_PWM=y
CONFIG_CAF_LEDS=y
CONFIG_CAF_LEDS_PWM=y

#dynamic device name and swift pair
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_ADV_PROV_SWIFT_PAIR=y


#enabling UART async
CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y

#disable console and logging
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_LOG=n

CONFIG_UART_0_ASYNC=y
CONFIG_UART_0_INTERRUPT_DRIVEN=n
CONFIG_UART_0_NRF_HW_ASYNC=y
CONFIG_UART_0_NRF_HW_ASYNC_TIMER=2
CONFIG_NRFX_TIMER2=y


#Connection parameters (pref.)
CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=y
CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=6
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=6
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=10


I'd love to get some help to debug this issue, thanks!
Parents Reply
  • Hello!

    Yes, the performance critical modules such as mouse sensor input, HID service etc. are all based on nRF Desktop.

    I measured internal latencies- the delay between a button getting clicked and right before bt_hids_inp_rep_send() is called is negligible.



    I know that internally bt_hids_inp_rep_send() calls bt_gatt_notify_cb()

     a GATT notification is sent at the next connection event- so this must mean that the connection is somehow just not able to maintain 7.5 ms and the fact that connection drops when the timeout is set to 100ms means that latency is definitely spiking to 100ms + 

Children
  • One possible theory could be that some part of my code is starving the Soft Device Controller.

    But that is not the case either- reason being that in later tests- I decided to make the device run as a BLE HID Peripheral and a BT Central at the same time.
    The central code just responds to another DK's latency service messages- the tested latency was a blazing fast 1.5 ms  average (LLPM enabled)

    While the BT Peripheral continued to give the same average high latency functioning the same way as mentioned in my previous message.  (Note: the peripheral connects to a Windows 11 host)


    This definitely means that my code is not starving out the SDC- since central works perfectly fine.

    Any ideas why peripheral has such a huge latency? 


  • This has been resolved.

    My method of measuring latency was a high speed camera. I was comparing the time between DK LED lighting up and a screen flash on Windows 11 through an app I programmed.

    Turns out that this massive latency is a result of how Windows handles HID over BLE. Nothing to do with the actual BLE connection interval.

    Similar behaviour was observed with a high end gaming mouse that supports BLE.

    To everyone who comes across this post. Please measure connection related parameters with a Bluetooth sniffer- the nrf52840 dongle can be easily programmed to work like a sniffer. Other methods will never be as accurate.

Related