Guidance on Implementing Concurrent Central and Peripheral Roles for nRF52832 Using nRF5 SDK 17.0.2

Hi,

We are currently planning to start a project using the nRF52832 as our controller, SEGGER Embedded Studio version 5.42a as the IDE, and nRF5 SDK version 17.0.2 as our SDK. Our requirement is to have an nRF52832 device that behaves as both a central and peripheral.

Initially, the nRF52832 will act as a peripheral, allowing it to connect with the nRF Connect app. After this connection is established, the nRF52832 needs to function as both a central and a peripheral simultaneously. Other nRF52832 peripheral devices will be present, and these peripherals will connect to the central nRF52832. The central device should send information about the connected peripheral devices, such as MAC IDs and advertising names, to the app.

When the app sends BLE UART data specifying a particular destination device, this data should be forwarded to the corresponding nRF52832 peripheral device through the nrf52832 central device (GATEWAY) .

Project Details:

  • SDK: nRF5 SDK 17.0.2
  • IDE: SEGGER Embedded Studio 5.42a
  • Controller: nRF52832

Thank you for your support.

Best regards,
SILTVM

Parents
  •  , in the given example code how can i add nordic uart service , and scan and connect nordic uart service based devices . is there any tutorial for that ? 

  •  ,

    We have decided to add the Nordic UART service to the ble_app_hrs_rscs_relay example project. Before doing that, I am testing the code based on the link you provided.

    I flashed the ble_app_hrs_rscs_relay example project onto one development board and the ble_app_rscs example project from the BLE peripheral directory onto another development board. After flashing, the ble_app_hrs_rscs_relay-flashed board successfully connected with the ble_app_rscs-flashed board, and it sent speed data to the ble_app_hrs_rscs_relay board, which I could see in the logs. However, when I try to connect to the ble_app_hrs_rscs_relay-flashed board using the nRF Connect APK, I am unable to connect. The logs show a warning.

    What could be the possible reason for this issue?

    development board  :-  nrf52832 pca10040 

    <info> app: Peripheral connected
    
    <info> app: Speed      = 896
    
    <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x2, procedure: Encryption, error: 4102
    
    <warning> peer_manager_handler: Disconnecting conn_handle 2.
    
    <info> app: Fast advertising.
    
    <info> app: Peripheral disconnected. conn_handle: 0x2, reason: 0x16

  • Hi,

    It's most likely  because that one of the sides (phone or ble_app_hrs_rscs_relay board) has the bond information from previous pairing between them when the other doesn't. Please try to erase the full chip on the nRF52 board (nrfjprog --eraseall) and try to find if the device is in the bonded list on Bluetooth on the phone, click Forget this device. 
    You can take a look at this ticket: devzone.nordicsemi.com/.../peer_manager_handler-connection-security-failed-role-peripheral-conn_handle-0x0-procedure-encryption-error-4102

  •   ,

    We informed you that we are planning to add the Nordic UART Service (NUS) to the ble_app_hrs_rscs example project .

    So far, we have made the following changes:

    1. Included Necessary Header:

      • Added #include "ble_nus.h"  header files.
    2. Added NUS Component:

      • Included ble_nus.c and its header file.
      • Included ble_link_ctx_manager.c
    • Modified SDK Configuration:

      • Set BLE_NUS_ENABLED to 1 and NRF_SDH_BLE_VS_UUID_COUNT to 1 in sdk_config.h.
    • Declared NUS Instance:

      • Declared an NUS instance at the top of main.c:
         
        BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);

             Initialized NUS:

    • Initialized NUS in the service_init() function:
       
      ble_nus_init_t nus_init;
      // Initialize NUS.
      memset(&nus_init, 0, sizeof(nus_init));
      nus_init.data_handler = nus_data_handler;
      err_code = ble_nus_init(&m_nus, &nus_init);
      APP_ERROR_CHECK(err_code);

           Modified NUS Data Handler:

    • Modified the nus_data_handler function to:
       
      static void nus_data_handler(ble_nus_evt_t * p_evt)
      {
          memset(Bledatabuff, 0, sizeof(Bledatabuff));
          // Write the code for NUS data handling.
          if (p_evt->type == BLE_NUS_EVT_RX_DATA)
          {
              NRF_LOG_DEBUG("Received data from BLE NUS.");
              // Copy received data to Bledatabuff array
              for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
              {
                  Bledatabuff[i] = p_evt->params.rx_data.p_data[i];
              }
          }
          NRF_LOG_INFO("Received BLE data: %s\n", Bledatabuff);
      }

    Before proceeding with further NUS integration, we would like to verify if the current initialization is correct. We are currently encountering a "no memory error" in the nrf_sdh_ble() function.

    <info> app_timer: RTC: initialized.
    <info> app: nrf_sdh_enable_request : 0
    <info> app: nrf_sdh_ble_default_cfg_set : 0
    <warning> nrf_sdh_ble: Insufficient RAM allocated for the SoftDevice.
    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002DA0 to 0x20002DB0.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0xD250.
    <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.
    <error> app: Fatal error
    <warning> app: System reset
    
    

    Do I need to modify the RAM start and end addresses? If so, what should the new addresses be?

    Your advice is really helpful

  •  , changing the ram address from  0x20002DA0 to  0x20002DB0 in section placement macros solved the issue  

  • Hi, 
    I'm glad that you find the fix. It's the correct fix. 

Reply Children
  •  hi ,   

    Hope you are doing well.

    We previously informed you that we started integrating the Nordic UART Service into the ble_app_hrs_rscs example project. We added the Nordic UART Service central and peripheral code regions from the ble_app_uart_c and ble_app_uart BLE central and peripheral example projects. We have not yet tested the modified code.

    After the integration, we flashed the modified ble_app_hrs_rscs example project onto the PCA10040 nRF52832 development board. After flashing, we observed a "no memory" error. I will share the log output.

    My question is: is a RAM address change necessary when adding the Nordic UART central part? I had already changed the RAM address when adding the Nordic UART peripheral part.

    12:27:11.592 -> <warning> nrf_sdh_ble: Insufficient RAM allocated for the SoftDevice.
    
    12:27:11.592 -> <warning> nrf_sdh_ble: Change the RAM start location from 0x20002DB0 to 0x20004718.
    
    12:27:11.592 -> <warning> nrf_sdh_ble: Maximum RAM size for application is 0xB8E8.
    
    12:27:11.639 -> <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.
    
    12:27:11.639 -> <error> app: Fatal error
    
    12:27:11.639 -> <warning> app: System reset
    
    12:27:11.873 -> <info> app_timer: RTC: initialized.

  • Hi Siltvm, 
    Yes if you add more service/characteristic to the table, it will require larger stack inside the softdevice. Please adjust the stack accordingly. 

  • We added the NUS_C and NUS parts from the ble_app_uart_c and ble_app_uart examples to the ble_app_hrs_rscs example project and made some necessary corrections in the event handlers of the central and peripheral side handlings. Now, we are able to send data to the APK through the gateway and vice versa. We have implemented bidirectional data transfer through the gateway. We are greatly appreciative of your valuable suggestions

  • Hi Siltvm, 
    Thanks for letting me know. I'm happy to help. From what I read everything is working as expected, right ? 
    If it's the case you can either close the ticket or just leave it at the current state. 

Related