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

Pairing/bonding with ble_app_template example not working for me

Hi,

I just recently got into designing Bluetooth devices and I am experimenting with NRF51822 and BLE400 board. I managed to compile and upload the examples from SDK 11.0.0 to the device with SEGGER Embedded Studio and I can advertise and connect to the device with nRF Connect app on my Android phone.

When I try to bond with nRF Connect it just hangs up after a couple of seconds. A similar thing happens if I try to pair with the phone directly.

Is there something I have to implement in the code of the example app?

  • Hi Matej,

    When it "hang" what happened after that ? Would the device advertise ?

    Please follow this guide and find out where in the code it stuck.

    The ble_app_template does support bonding. Did you add any modification to the code ?

  • Hi,

    I dug a little bit deeper and I get the PM_EVT_ERROR_UNEXPECTED error pm_evt_handler (I also switched to example from 12.2.0 now but the problem is still there)

    This is what happens:

    • I upload the code to device
    • Device starts advertising (led is blinking)
    • I scan with nRF Connect
    • I connect with nRF Connect (led is off)
    • I start bonding with nRF Connect (led is off)
    • Bonding fails (led is still off)
    • Device automatically disconnects (led is off)
    • Device automatically disconnects (led is off)
    • If I run scan again device isn't found anymore

    I managed to make it work but with this setup: #define SEC_PARAM_BOND 0
    #define SEC_PARAM_MITM 0
    #define SEC_PARAM_LESC 0
    #define SEC_PARAM_KEYPRESS 0
    #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE
    #define SEC_PARAM_OOB 0
    #define SEC_PARAM_MIN_KEY_SIZE 7
    #define SEC_PARAM_MAX_KEY_SIZE 16

    and

    sec_param.kdist_own.enc = 0; sec_param.kdist_own.id = 0; sec_param.kdist_peer.enc = 0; sec_param.kdist_peer.id = 0;

    If I want to do any other combination with #define SEC_PARAM_BOND 1 it fails

  • Please try to test again with unmodified example, you can test with the precompiled hex file. It works fine for me here. You can also try to test with another example, for example hrs or proximity.

    Please find the error code when the PM_EVT_ERROR_UNEXPECTED happen.

  • Hmm ... the precompiled hex works. Could there be something in the project settings that might interfeere? I used the SEGGER Studio template: github.com/.../nrf51822_s130_ble_app_uart from here but it is somewhat outdated so I changed the .emProject file a bit to make it work. I just added some preprocessor paths.

    How can I display the error code of PM_EVT_ERROR_UNEXPECTED. Right now the only way I know to display debug data is through SEGGER_RTT_WriteString function while I debug in SEGGER Studio. I tried to display the code like that but it didnt show.

  • The error value is in p_evt->params.error_unexpected.error, you can use SEGGER_RTT_printf to print out.

    There are only 3 place where PM_EVT_ERROR_UNEXPECTED is assigned inside peer_manager, you can track them down.

    I assume you have followed the tutorial here (a bit out of date) and here ?

    Also make sure you erase the chip completely when you test. There could be that earlier data stored can cause an issue when bonding is stored.

    You can try to capture a sniffer trace to see what happens over the air.

Related