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

Help needed with pairing a central UART over BLE module to a peripheral UART over BLE advertiser using whitelisting

Hello,

I am attempting to program nRF52 DK modules to communicate using the UART over BLE central and peripheral roles as in the examples provided in SDK 15.2. The data transmitted is a string of 4 characters which is generated on the peripheral end. I would like to implement this in a configuration of 5 pairs of modules that are using whitelisting. 

I have followed the case example found here https://devzone.nordicsemi.com/f/nordic-q-a/21941/how-to-implement-whitelist-in-sdk12-2-0 to make the changes on the peripheral end. In advertising_init(), I included this line (init.config.ble_adv_whitelist_enabled = true;) to enable whitelisting, as well as included the changes suggested by the case example. The one difference I made to the example, was to provide the advertising module instance in ble_advertising_whitelist_reply(), like this (err_code = ble_advertising_whitelist_reply(&m_advertising, &whitelist_addr, 1, NULL, 0);). I am able to sent characters from peripheral to central using Putty, and once the whitelist functionality is enabled on the peripheral end, that ability goes away, which leads me to believe that the peripheral is set up correctly. 

I need some help setting up the central end for whitelisting, and to set up the advertising packets to sent the 4 characters from peripheral to central as mentioned above please. I am hoping that there are some tutorials that you can point me to to shed some clarity on this topic for me. 

I am using Segger (release 4.10a), SDK 15.2.0, PCA 10040, Soft device S132 on a Windows 10 machine (Version 10.0.17134, Processor Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz, 2694 Mhz, 4 Core(s), 8 Logical Processor(s), with 16Gb Ram).

Thank you in advance for your time!

Alin

Parents
  • After some trial and error I managed to communicate between the central and peripheral, with whitelisting added to the peripheral side. Here I will go through the steps taken.

    First, you will need the MAC address of the device in which the central is running on. I got it by flashing and running the BLE UART Peripheral example on the device (it can also be found by reading the FICR register in this manner), then I opened the nRF Connect app on the mobile phone and wrote down the 6 byte MAC address. In my case it was 0xE2:8B:65:53:71:9B. Then I erased the chip, and flashed the BLE UART Central Example onto the chip.

    Changes to made to the BLE UART Peripheral Example

    Initially I added this line at the top of main

    static ble_gap_addr_t whitelist_addrs = {0, BLE_GAP_ADDR_TYPE_RANDOM_STATIC, {0x9B, 0x71, 0x53, 0x65, 0x8B, 0xE2}};

    In advertising_init() I added this line

    init.config.ble_adv_whitelist_enabled          = true;

    Inside the function advertising_start() these lines were added

    ret_code_t err_code;
    ble_gap_addr_t const     *p_whitelist_addr[] = {&whitelist_addrs};
    err_code = sd_ble_gap_whitelist_set(p_whitelist_addr, 1);

    Eventually, I modified the handler for advertising events (on_adv_evt()), by including the case BLE_ADV_EVT_WHITELIST_REQUEST

    case BLE_ADV_EVT_WHITELIST_REQUEST:
            {
    
                 // Apply the whitelist.
                 err_code = ble_advertising_whitelist_reply(&m_advertising,
                                                           &whitelist_addrs,
                                                           1,
                                                           NULL,
                                                           0);
            } break; //BLE_ADV_EVT_WHITELIST_REQUEST

    Remember to call sd_ble_gap_whitelist_set() before running ble_advertising_start(), if not the function sd_ble_gap_adv_set_configure(..) will fail with the error NRF_ERROR_INVALID_PARAM.

    It is also important to add the function ble_advertising_whitelist_reply(..) as shown above. The comment above the function declaration says the following:

    "The whitelist must be set by the application upon receiving a BLE_ADV_EVT_WHITELIST_REQUEST event."

    Hopefully I haven't forgotten anything, just in case, I have attached the code.

    ble_app_uart_whitelist.zip

    Best regards,

    Simon

  • Hi Simon, 

    Thank you for your reply! I implemented the whitelisting functionality in the same way you suggested and noticed that the peripheral paired with the central whose MAC address was recorded in the XX fields of whitelist_addrs = {0, BLE_GAP_ADDR_TYPE_RANDOM_STATIC, {0x XX, 0x XX, 0x XX, 0x XX, 0x XX, 0x XX}}, but I also noticed that the program stops sending the string of characters over BLE. In other words, once the connection is established, the peripheral stops executing any of the code in main.

    Could you please help me figure out why that might be?

    Thank you!

    Alin

  • Sorry for the long delay.

    Strange, It is working fine for me. If you haven't made any modifications to the ble_app_uart peripheral example, the act of sending and receiving messages are event driven and handled by interrupts and event handlers. Thus, it sounds like you have modified the example by sending messages directly from main.

    If you upload your main function, I might be able to see where it fails.

Reply
  • Sorry for the long delay.

    Strange, It is working fine for me. If you haven't made any modifications to the ble_app_uart peripheral example, the act of sending and receiving messages are event driven and handled by interrupts and event handlers. Thus, it sounds like you have modified the example by sending messages directly from main.

    If you upload your main function, I might be able to see where it fails.

Children
No Data
Related