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

Merging nRF52 blinky into uart for peripheral as well as central role.

I'm merging nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_blinky\pca10040\s132\ses to nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_uart\pca10040\s132\ses, but getting error. Also, I want to merge nRF5_SDK_17.0.2_d674dde\examples\ble_central\ble_app_blinky_c\pca10056\s140\ses to nRF5_SDK_17.0.2_d674dde\examples\ble_central\ble_app_uart_c\pca10056\s140\ses. Can anybody help me? or If their already merged then it will be benefit.

Please find below error screenshot,

  • Hi,

    I took a look at the ble_app_uart. In services_init(), you need to init the LBS service, and add the led_write_handler().

    /**@brief Function for handling write events to the LED characteristic.
     *
     * @param[in] p_lbs     Instance of LED Button Service to which the write applies.
     * @param[in] led_state Written/desired state of the LED.
     */
    static void led_write_handler(uint16_t conn_handle, ble_lbs_t * p_lbs, uint8_t led_state)
    {
        if (led_state)
        {
            bsp_board_led_on(LEDBUTTON_LED);
            NRF_LOG_INFO("Received LED ON!");
        }
        else
        {
            bsp_board_led_off(LEDBUTTON_LED);
            NRF_LOG_INFO("Received LED OFF!");
        }
    }
    
    
    /**@snippet [Handling the data received over BLE] */
    
    
    /**@brief Function for initializing services that will be used by the application.
     */
    static void services_init(void)
    {
        uint32_t           err_code;
        ble_nus_init_t     nus_init;
        ble_lbs_init_t     init     = {0};
        nrf_ble_qwr_init_t qwr_init = {0};
    
        // Initialize Queued Write Module.
        qwr_init.error_handler = nrf_qwr_error_handler;
    
        err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init);
        APP_ERROR_CHECK(err_code);
    
        // 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);
    
        // Initialize LBS.
        init.led_write_handler = led_write_handler;
    
        err_code = ble_lbs_init(&m_lbs, &init);
        APP_ERROR_CHECK(err_code);
    }

    Since you are adding a second custom service, you need to increase the value of NRF_SDH_BLE_VS_UUID_COUNT in sdk_config.h to 2

    If you are having trouble viewing the RTT log inside SES, then set NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED in sdk_config.h to 0

    After adding the 2nd service, you need to allocate more RAM to the SoftDevice. You typically will get something like this printed in the log when this is needed:

    <warning> nrf_sdh_ble: Insufficient RAM allocated for the SoftDevice.
    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002AD8 to 0x20002AE8.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0xD518.
    <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.

    You then need to adjust this values, like this:

    If you connect with a phone, using e.g. nRF Connect for Mobile app, you should see that the LBS Service has been added.

    Let me know if you need more help with this.

  • Hi,

    I have checked your suggestion.

    Added led_write_handler() & init LBS service. Also, change in sdk_config.h as  NRF_SDH_BLE_VS_UUID_COUNT in sdk_config.h to 2

    Now, I'm unable to see it on nRF toolbox also.

    Before adding these changes atleast I'm able to see it in nRF toolbox.

    Checked in debug mode, both continuously goes into NRF_BREAKPOINT_COND;

    Please find below link of updated sdk:

    https://smetgroup-my.sharepoint.com/:u:/g/personal/megha_choudhari_mysmindia_com/Ef_06NnNAFhKjzGPNLRt8s0Bn7x9q9FgYLiibla92wL_IA?e=7VSmin

    Kindly suggested what is wrong in this.

    Regards,

    Megha Choudhari

  • Hi,

    After setting 

    NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED to 0 

    I get this in the log window:

    I right click on "ble_app_uart_pca10040_s132" -> Options, and find the RAM size the linker uses:

    I changed the RAM values so it matches what the log said, and after that it worked fine.

  • Hi,

    Checked by doing this changes in peripheral code. Now able discover on nRF tool box. But not connects with Central ble_app_uart_c(nRF52840)

    What will be the changes required in central side. Can you just check in same sdk & let me know.

    Regards,

  • MeghaC said:

    What will be the changes required in central side. Can you just check in same sdk & let me know.

     For the central, the first steps to get it to connect is:
    in sdk_config.h set these:

    NRF_BLE_SCAN_NAME_CNT to 1
    NRF_SDH_BLE_VS_UUID_COUNT to 2

    You then will get this in the log:
    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002A38 to 0x20002A48.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0x3D5B8.

    So you need to set these values for the linker:

    RAM_START=0x20002A48
    RAM_SIZE=0x3D5B8

Related