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,

Parents
  • Hi,

    I don't think we have any ready examples that merges ble_app_blinky and ble_app_uart.

    If you can upload your project here, then I will take a look at what's missing.

  • Hi,

    Please find below link to download the project:

    https://smetgroup-my.sharepoint.com/:u:/g/personal/megha_choudhari_mysmindia_com/ESMV-B9MJLdEvC0eyhJ2ghgBXCsVIT4OQg3A2CFfrWDq9w?e=lYWprR

    Added comments with //03/05/21 for easy understanding of changes, I have merged - 

    1. ble_peripheral - ble_app_blinky into ble_app_uart

    2. ble_central -  ble_app_blinky_c into ble_app_uart_c 

    Now both project builds successfully but enable to connect ble_app_uart to ble_app_uart_c. Also, the advertising, connection LED status not visible.

    Checked in debug mode both goes to NRF_BREAKPOINT_COND; in app_error_weak.c file

    Looking forward for your reply.

    Regards,

    Megha Choudhari

  • 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

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

Children
  • Hi,

    Done changes suggested on central side also, now peripheral getting connected with central device. Please find below screenshot for your reference.

    But when I'm pressing button from peripheral the LED from central should turn ON. This is not happening.

    I have added all necessary logic from ble_app_blinky to ble_app_uart & from ble_app_blinky_c to ble_app_uart_c.

    If I missed out anything, kindly suggest me. My sdk is already with you. I have maked peripheral as nRF52832 DK & central as nRF52840 DK.

    Waiting for your reply.

    Thanks for your valuable guidance.

    Regards,

    Megha Choudhari

  • Hi, 

    Also I have observed while debugging that the when switch pressed from peripheral it again goes to NRF_BREAKPOINT_COND;

    Why it so?

    Regards,

    Megha Choudhari

  • MeghaC said:

    But when I'm pressing button from peripheral the LED from central should turn ON. This is not happening.

     I took a look at the code, in db_disc_handler() you need to add ble_lbs_on_db_disc_evt(&m_ble_lbs_c, p_evt); , so that the function looks like this:

    /**@brief Function for handling database discovery events.
     *
     * @details This function is a callback function to handle events from the database discovery module.
     *          Depending on the UUIDs that are discovered, this function forwards the events
     *          to their respective services.
     *
     * @param[in] p_event  Pointer to the database discovery event.
     */
    static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
    {
        ble_nus_c_on_db_disc_evt(&m_ble_nus_c, p_evt);
        ble_lbs_on_db_disc_evt(&m_ble_lbs_c, p_evt);
    }

     

    MeghaC said:

    Also I have observed while debugging that the when switch pressed from peripheral it again goes to NRF_BREAKPOINT_COND;

     This did not happen when I tested here. Maybe this will be resolved when you fix the db_disc_handler() function.

  • Hi,

    Have a nice day!!!!!

    Sorry to revert you late.

    I have done changes in db_disc_handler(); as suggested. But still while pressing button from peripheral no LED indication observed on central board. Please find below link for video:

    https://smetgroup-my.sharepoint.com/:v:/g/personal/megha_choudhari_mysmindia_com/EevKoIF0g0FHsMoe2dRAIvkBKJLytnGN5S9IfelY2uSQmw?e=IdAL1P

    Also, I have checked with in main.c added just to check on button press goes to button_event_handler(); or not. But its goes to NRF_BREAKPOINT_CONDITION;

    /**@brief Application main function.
     */
    int main(void)
    {
        bool erase_bonds;
    
        // Initialize.
        log_init();
        uart_init();
        leds_init();  //03/05/21     
        timers_init();
        buttons_init(); //03/05/21
    //    buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        // Start execution.
        printf("\r\nUART started.\r\n");
        NRF_LOG_INFO("Debug logging for UART over RTT started.");
        advertising_start();
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
           //ble_nus_data_send(&m_nus,"SMET\r\n",5,m_conn_handle);
           if(LEDBUTTON_BUTTON == true)
           {
            bsp_board_led_on(LEDBUTTON_LED);
           }
        }
        
       
    }
    
     

    If it's working at your side, Can you resend me that sdk?

    Regards,

    Megha Choudhari

  • Hi,

    Have a nice day!!!

    Waiting for reply. When I can expect?

    Regards,

    Megha Choudhari

Related