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

nfc52832 calling ble_evt_handler with BLE_GAP_EVT_DISCONNECTED during pairing

Hi

I am trying to migrate our BLE hardware platform from Laird to Nordic Semi nRF52832. I have an App which was previously working with the Laird platform, but am having serious issues just getting it to pair reliably with the nRF52832 - specifically, the underlying BLE Stack keeps calling ble_evt_handler with BLE_GAP_EVT_DISCONNECTED while trying to pair/connect!

My Android app is pretty simple:

1) It searches for a BLE device advertising with a certain name

2) It makes a connection using the MAC address learnt from the above

3) It connects to the known service UUID

4) It connects to the known characteristic UUID

5) It sets up a callback called when the characteristic sends data

(The characteristic is simply a button press on the dev board)

At some stage in the above, usually just after a successful connection, the nRF52832 BLE stack calls 'Disconnect', I then see this in my app as a 'connection lost', I try and reconnect (using the same MAC/UUID) and the cycle repeats.

Any thoughts as to why its disconnecting. I have the following parameters in place, not really sure which one to change. I am using 'Just works' pairing

#define MIN_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.1 seconds). */
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS)
#define SLAVE_LATENCY 0 /**< Slave latency. */
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */
#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000) /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000) /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT 6 /**< Number of attempts before giving up the connection parameter negotiation. */
#define SECURITY_REQUEST_DELAY APP_TIMER_TICKS(400) /**< Delay after connection until Security Request is sent, if necessary (ticks). */

Nigel

  • Does the BLE_GAP_EVT_DISCONNECTED event tell you the disconnect reason?

    Can you try to add:

    case BLE_GAP_EVT_DISCONNECTED:
        NRF_LOG_INFO("disconnected, reason 0x%02x", p_ble_evt->evt.gap_evt.params.disconnected.reason);
        ... // The rest of the code in BLE_GAP_EVT_DISCONNECTED, if any.
        break;

     

    And see if you can see the disconnect reason.

    I don't know if you have logging enabled, but you can also set a breakpoint here. 

    You can also check if your error handler catches anything. This is easiest to explain if you have logging enabled. You should see a "fatal error" in the log. If you define "DEBUG" in your preprocessor defines, then the log should print some more info on where and what kind of error that occured. If not, try to see if the error handler in app_error.c fires. Note that you probably have to turn off optimization (set it to -O0) in order to see the value of the variables while debugging. This is usually done in the IDE's project settings.

     

    Best regards,

    Edvin

  • Hi

    This turned out to be down to experiments by the previous owner of this code who was trying to get LE Length Extension working. NRF_SDH_BLE_GATT_MAX_MTU_SIZE having been set to 247. Returning it to 23 allowed me to connect.

    I was also deleting the pairing at startup on the Murata, and unless I did the same on the Phone, this caused issues with the error: 

    PM_EVT_CONN_SEC_START
    <info> app:
    PM_EVT_CONN_SEC_FAILED
    <info> app: Failed to secure connection. Disconnecting.

    Your tip above helped point the finger at the problem with the length request reported at 251 bytes.

    My app is an amalgamation of a couple of other apps to do the BLE + NFC stuff - I don't do 'standard' NFC pairing as the remit is to allow NFC pairing via iOS which does not support this - although more standard support is likely to arrive with iOS12.

    Are there any examples explaining how to do LE Length Extension properly?

    Nigel

  • Hello Nigel,

    We don't have any examples only describing Data Length Extension, if that is what you are looking for. You can take a look at the example in:

    SDK\examples\ble_central_and_peripheral\experimental\ble_app_att_mtu_throughput.

    This example is intended for testing the throughput with different connection parameters. If you have 2 DKs, you can run this example on both, and follow the instructions in the log (uart).

    This example uses the data_len_set() in main.c, which is used to set the data length.

     

    Best regards,

    Edvin

Related