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 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. 

  •  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. 

Reply Children
Related