ble nus central disconnect immediately

Hello, i have unexpected disconnection on a nRF54L15 SoC. The goal is to synchronise 2 nRF devices : device 1 is a nRF54L15 SoC and ble nus central software, device 2 is a nRF52832 SoC and ble NUS server software. Device 1 will scan for ble NUS services.

Device 1 :

SDK : nRF Connect SDK Bare Metal v2.0.1

Tool Chain : nRF Connect SDK Toolchain v3.3.0

Softdevice : bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice

Device 2:

SDK : nRF5 SDK V16.0.0

Softdevice : s132_nRF52_softdevice V7.0.1

Device 2 discovery works randomly.

Good case :

[00:02:18.131,818] <inf> sample: Client initialized
[00:02:18.131,875] <inf> sample: Client scan started
[00:02:18.219,577] <inf> sample: Connecting to target 3bf29a2a35d4
[00:02:18.219,599] <inf> sample: Connected, client_conn_handle = 2
[00:02:18.221,392] <inf> ble_conn_params: Peer 0x2 requested ATT MTU of 247 bytes
[00:02:18.221,420] <inf> ble_conn_params: ATT MTU set to 23 bytes for peer 0x2
[00:02:18.221,425] <inf> sample: GATT ATT MTU on connection 0x2 changed to 23
[00:02:18.251,232] <inf> ble_conn_params: Peer 0x2 requested data length of TX 251, RX 251 bytes
[00:02:18.281,228] <inf> ble_conn_params: Data length updated to TX 27, RX 27 for connection 0x2
[00:02:18.281,235] <inf> sample: Data length for connection 0x2 updated to 27
[00:02:18.551,187] <inf> sample: Discovery complete
[00:02:18.551,223] <inf> sample: Connected to device with Nordic UART Service
[00:02:18.731,176] <inf> sample: NUS TX data event, len: 3
[00:02:18.736,593] <inf> sample: Sended data to UART: <06>
[00:02:18.736,649] <inf> sample: Sended data to UART: <93>
[00:02:18.736,703] <inf> sample: Sended data to UART: <00>
[00:02:18.753,737] <inf> sample: Sended to NUS Client : <06><01><00>
[00:02:18.753,772] <inf> sample: Received data from UART: <06><01><00>
[00:02:18.862,405] <inf> sample: Received data from UART: <FF><F4><00>

Device 2 is discovered.

Bad case:

[00:00:48.303,294] <inf> sample: Client initialized
[00:00:48.303,352] <inf> sample: Client scan started
[00:00:52.891,556] <inf> sample: Sended data to UART: <FF>
[00:00:52.891,613] <inf> sample: Sended data to UART: <F7>
[00:00:52.891,668] <inf> sample: Sended data to UART: <0F>
[00:00:52.891,745] <inf> sample: Sended data to UART: <53>
[00:00:52.891,800] <inf> sample: Sended data to UART: <4F>
[00:00:52.891,855] <inf> sample: Sended data to UART: <27>
[00:00:52.891,911] <inf> sample: Sended data to UART: <54>
[00:00:52.891,966] <inf> sample: Sended data to UART: <4F>
[00:00:52.892,022] <inf> sample: Sended data to UART: <55>
[00:00:52.892,077] <inf> sample: Sended data to UART: <43>
[00:00:52.892,827] <inf> sample: Sended data to UART: <48>
[00:00:52.892,895] <inf> sample: Sended data to UART: <5F>
[00:00:52.892,950] <inf> sample: Sended data to UART: <30>
[00:00:52.893,006] <inf> sample: Sended data to UART: <30>
[00:00:52.893,059] <inf> sample: Sended data to UART: <30>
[00:00:52.893,115] <inf> sample: Sended data to UART: <34>
[00:00:52.893,170] <inf> sample: Sended data to UART: <31>
[00:00:52.893,233] <inf> sample: Sended data to UART: <38>
[00:00:52.942,274] <inf> sample: Connecting to target 3bf29a2a35d4
[00:00:52.942,296] <inf> sample: Connected, client_conn_handle = 0
[00:00:53.093,990] <inf> sample: Disconnected
[00:00:53.094,004] <inf> sample: Disconnected. conn_handle: 0x0, reason: 0x3e

Device 2 is seen by device 1, but after connection device 1 will disconnect immediately with error 0x3e (Connection failed to be established error).

Project configuration :

# Logging
CONFIG_LOG=y
CONFIG_LOG_BACKEND_BM_UARTE=y

# SoftDevice
CONFIG_SOFTDEVICE=y
CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT=2
CONFIG_NRF_SDH_BLE_CENTRAL_LINK_COUNT=1

# NUS requires storage of a vendor UUID
CONFIG_NRF_SDH_BLE_VS_UUID_COUNT=2

# Enable RNG
CONFIG_NRF_SECURITY=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_PSA_WANT_GENERATE_RANDOM=y

# Advertising library
CONFIG_BLE_ADV=y
CONFIG_BLE_ADV_RESTART_ON_DISCONNECT=n

# BLE connection parameter
CONFIG_BLE_CONN_PARAMS=y
CONFIG_BLE_CONN_STATE=y

# Nordic UART service
CONFIG_BLE_NUS=y

# NUS depends on the Queued Writes module
CONFIG_BLE_QWR=y

# Enable POWEROFF
CONFIG_PM_DEVICE=y
CONFIG_POWEROFF=y

# Enable HW INFO
CONFIG_HWINFO=y

# Timer library
CONFIG_BM_TIMER=y

# Button library
CONFIG_BM_BUTTONS=y
CONFIG_BM_GPIOTE=y

# Clock control
CONFIG_CLOCK_CONTROL=y

# BLE NUS client
CONFIG_BLE_NUS_CLIENT=y

# BLE database discovery
CONFIG_BLE_DB_DISCOVERY=y
CONFIG_BLE_GATT_QUEUE=y

# BLE scan
CONFIG_BLE_SCAN=y
CONFIG_BLE_SCAN_UUID_COUNT=2
CONFIG_BLE_SCAN_ADDRESS_COUNT=1
CONFIG_BLE_SCAN_NAME_COUNT=2
Scan filters :
struct ble_scan_filter_data uuid_filter =
{
        .uuid_filter = {.uuid = {.uuid = BLE_UUID_NUS_SERVICE, .type = BLE_UUID_TYPE_BLE}}
};

Scan parameters :

struct ble_scan_config ble_scan_cfg =
{
        .scan_params = {
            .active = 0x01,
            .interval = BLE_GAP_SCAN_INTERVAL_US_MIN * 20,
            .window = BLE_GAP_SCAN_WINDOW_US_MIN * 20,
            .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
            .timeout = BLE_GAP_SCAN_TIMEOUT_UNLIMITED,
            .scan_phys = BLE_GAP_PHY_AUTO,
        },
        .conn_params = BLE_SCAN_CONN_PARAMS_DEFAULT,
        .connect_if_match = true,
        .conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG,
        .evt_handler = on_ble_scan_evt,
};

So, what can be the problem ?

Thanks.
Best Regards.
Andre MULLER
  • Hello Andre,

    This connection error is expected to occur occasionally, especially when other active scanners are within range (e.g., if you are scanning for LE devices in the nRF connect app on your phone), as their scan requests may overlap with your connection request PDU. The connection error is raised when the peripheral is not responding to the request.  The solution should be to simply retry the connection.

    Excessive clock drift on the 32K source may also lead to this error, but then I would also expect the connection to be unstable in the cases where the connection is established successfully.

    Best regards,

    Vidar

    Edit to clarify: There are of course other reasons why a connection request might not be received by the peer. The connection request is only sent once per attempt. Noise from other Wifi,BT,etc devices operating on the same frequency is another example. It is just that in my experience, nearby active scanners are typically the most common cause if you experience this connection error.

Related