MultiLink with Peripherals & Centrals in the nRF5 SDK v13

##Introducing concurrent MultiLinks

I’d like to inform that it is possible to configure concurrent-multiple connections with several Centrals and Peripherals.
This behavior can be possible to use examples in the nRF5 SDK v13.
In the nRF5 SDK v13, “multiperipheral” example has been come newly.

So, “multilink_central” and “multiperipheral” can be used together.

##MultiLink examples in the nRF5 SDK v13

There are two multilink examples for Central and Peripheral which are located in the nRF5 SDK v13.

  • “nRF5_SDK_13.0.0_04a0bfd\examples\ble_central\ble_app_multilink_central”

image description

  • “nRF5_SDK_13.0.0_04a0bfd\examples\ble_peripheral\experimental_ble_app_multiperipheral”

image description

These solutions allow multi-connections from Peripherals as the Central Role and from Centrals as the Peripheral Role.
These examples are based on Blinky behavior and are using LED_BUTTON Service.

##Basic Concept

It doesn’t matter which example is used as the background.
In this blog, the “multilink_central” example has been the background and the “multiperipheral” example has been merged.

To verify easy, the connected Peripherals and Centrals are restricted only two each.


Add Peripheral Role to Multilink Central example code.

[1]. Modify count value for PERIPHERAL_LINK_COUNT

In Main.c, link count value for Peripheral is 0. So, change this value to some value user want.

  • Before
  • After

[2]. Copy and add defined values from code of multiperipheral example for the Peripheral Role.

#define DEVICE_NAME                     "Nordic_Blinky_Peripheral" 
#define APP_ADV_INTERVAL                64                                      
#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(100, UNIT_1_25_MS)        
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(200, UNIT_1_25_MS)        
#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)         
#define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(20000)                  
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5000)                   
#define MAX_CONN_PARAMS_UPDATE_COUNT    3                                       

[3]. Copy these functions from multiperipheral example and add to main.c


[4]. Add ble_lbs.c to nRF_BLE_Sevice of Project. And, declare a golbal variable for LED Button Service Instance.

static ble_lbs_t m_lbs;

Then, define BLE_LBS_ENABLED in sdk_config.h.


Last, include head file in main.c.

#include "ble_lbs.h"

[5]. Add initializing functions related with Peripheral Role to Main Function.

int main(void)
    gap_params_init(); //Add for Peripheral Role
    services_init(); //Add for Peripheral Role
    advertising_init(); //Add for Peripheral Role
    conn_params_init(); //Add for Peripheral Role
    NRF_LOG_INFO("Multilink example started.\r\n");

    advertising_start(); //Add for Peripheral Role

    for (;;)

[6]. In advertising_start(), one value should be changed.

static void advertising_start(void) { : err_code = sd_ble_gap_adv_start(&adv_params, CONN_CFG_TAG BLE_CONN_CFG_TAG_DEFAULT); : }

If you use original value, you will get the Fatal situation.

[7]. To allow second Central connection, should advertise again after connection with first Central.

static void on_ble_evt(ble_evt_t const * p_ble_evt)
        if((ble_conn_state_n_peripherals() evt.gap_evt.conn_handle) == BLE_GAP_ROLE_PERIPH))

[8]. Adjust RAM parameters. After Flash, start address and size of RMA should be adjusted.

SDH:WARNING:RAM start should be adjusted to 0x20004e78.
SDH:WARNING:RAM size should be adjusted to 0xb188.

Start address and size of RAM can be changed due to amount of your modified codes.

##Demo For demonstration, more modified codes are needed.
To exchange data between a board with the Peripheral role and Central devices with Blinky behavior, LED Button Service has been added.
And, not used codes and functions have been deleted to avoid any confusion.

New behaviors have been assigned to LEDs and Buttons.

[1]. Preparation

  • 2 Peripheral devices programmed Blinky example (nRF51 or nRF52 DK)
  • 2 Central devices can conduct Blinky example
  • 1 nRF52 DK programmed MultiLink Demo (nRF52832 DK)

[2]. Behaviors for LEDs and Buttons
As you know, there are 4 LEDs and Buttons in a nRF52 DK.
With MultiLink Demo, behaviors for LEDs and Buttons on the MultiLink Board are like below.

  • LED1 : turn on/off when first Peripheral device is connected or is disconnected
  • LED2 : turn on/off when second Peripheral device is connected or is disconnected
  • LED3 : turn on/off when first Central device is connected or is disconnected
  • LED4 : turn on/off when second Central device is connected or is disconnected
  • Button1 : to send an event to first Peripheral device
  • Button2 : to send an event to second Peripheral device
  • Button3 : to send an event to first Central device
  • Button4 : to send an event to second Central device
  • Blink LED1 : when push and then release the Button1 on first Peripheral device
  • Blink LED2 : when push and then release the Button1 on second Peripheral device
  • Turn off LED3 : when push On-Button on first Central device
  • Turn on LED3 again : when push Off-Button on first Central device
  • Turn off LED4 : when push On-Button on second Central device
  • Turn on LED4 : when push Off-Button on second Central device

[3]. Demo

image description

You can refer sample code here.

Multilink_Peripheral_Central : ble_app_multiConnection-Central_Peripheral.7z

In sample code, only allow the connection with two Peripherals and Centrals.
You can expand more Peripherals and Centrals if you want.