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

BLE Peripheral NUS connected to multiple Central devices on nrf52840 S140 and SDK V16.0.0

Hello,

Is it possible to configure the board as a peripheral device that provides the Nordic UART Service and allows multiple central devices to connect and exchange data.

Sort of like the "usbd_ble_uart_freertos" example but allows more than one Central device to connect at the same time.

Thanks

Omid

  • Hello,

    I would suggest you take a look at the example that you find in:

    SDK\examples\ble_peripheral\experimental\ble_app_multiperipheral (Not really any need for an FreeRTOS).

    This example shows how to allow multiple peripheral connections (connecting to multiple central devices). As you can see it is quite similar to the ble_app_multilink_central, which allows for multiple central connections (multiple peripherals connecting to it). There are some defines that need to be set, such as the NRF_SDH_BLE_PERIPHERAL_LINK_COUNT and NRF_SDH_BLE_TOTAL_LINK_COUNT in sdk_config.h and then start advertising on the BLE_GAP_EVT_CONNECTED event, as long as the number of current connections is smaller than NRF_SDH_BLE_PERIPHERAL_LINK_COUNT.

    Remember that when you are dealing with multiple connections, you must keep track of your connection handles, in order to know who you received a message from, and who you are transmitting to.

    Best regards,

    Edvin

  • Thanks very much

    I checked that out and it sure works as expected.  For our project we have modified the "usbd_ble_uart_freertos" and when I attempted to change the NRF_SDH_BLE_PERIPHERAL_LINK_COUNT  to allow for multi connections the build is successful but I get the following error @ runtime

    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at /home/nikola/gitlabRepo/nikola-nordic-ble/nikola_nRF5_SDK_16.0.0/nikola-ws/nikola/nikola-ble/main.c:583
    PC at: 0x0003965B
    <error> app: End of error report

    It occurs at this instruction

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    Thanks for your help

  • If you have enabled logging, the log probably says something about some recommended RAM settings right before it returns this error. You should change the RAM settings accordingly. Let me know what IDE you are using, if you are not sure how to do this in your project. The lines you should look for should look something like this:

    RAM start location can be adjusted to 0x...
    
    RAM size for application can be adjusted to 0x...

    The simple reason for this is that if you want to support more connections, the softdevice requires more RAM in order to hold the information for the multiple devices' services and characteristics.

    Best regards,

    Edvin

  • Hi Edvin,

    I am using the Segger Embedded Studio and  I have the debug logging to the Debug Terminal.  Is that what you mean?

    The only thing I see on the Terminal is the error I included on the previous message.  Which is :

    <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at /home/nikola/gitlabRepo/nikola-nordic-ble/nikola_nRF5_SDK_16.0.0/nikola-ws/nikola/nikola-ble/main.c:583
    PC at: 0x0003965B
    <error> app: End of error report

    Your help is much appreciated.

  • Ok. Can you please try to step through nrf_sdh_ble_enable() and see what happens there? Are you sure you don't get any other logging?

    ret_code_t nrf_sdh_ble_enable(uint32_t * const p_app_ram_start)
    {
        // Start of RAM, obtained from linker symbol.
        uint32_t const app_ram_start_link = *p_app_ram_start;
    
        ret_code_t ret_code = sd_ble_enable(p_app_ram_start);
        if (*p_app_ram_start > app_ram_start_link)
        {
            NRF_LOG_WARNING("Insufficient RAM allocated for the SoftDevice.");
    
            NRF_LOG_WARNING("Change the RAM start location from 0x%x to 0x%x.",
                            app_ram_start_link, *p_app_ram_start);
            NRF_LOG_WARNING("Maximum RAM size for application is 0x%x.",
                            ram_end_address_get() - (*p_app_ram_start));
        }
        else
        {
            NRF_LOG_DEBUG("RAM starts at 0x%x", app_ram_start_link);
            if (*p_app_ram_start != app_ram_start_link)
            {
                NRF_LOG_DEBUG("RAM start location can be adjusted to 0x%x.", *p_app_ram_start);
    
                NRF_LOG_DEBUG("RAM size for application can be adjusted to 0x%x.",
                              ram_end_address_get() - (*p_app_ram_start));
            }
        }
    
        if (ret_code == NRF_SUCCESS)
        {
            m_stack_is_enabled = true;
        }
        else
        {
            NRF_LOG_ERROR("sd_ble_enable() returned %s.", nrf_strerror_get(ret_code));
        }
    
        return ret_code;
    }

    What is your NRF_LOG_DEFAULT_LEVEL defined to in sdk_config.h?

    If you step through this part of the code (you may need to turn off optimization for that to happen properly), does it enter any of the if-else checks?

    BR,

    Edvin

Related