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

How to change from BLE central to peripheral mode by buttons

Hi, I was wondering how to change from central mode of the NRF52 board to peripheral mode and from peripheral mode to central mode by pressing the input buttons on the board. For example, button 1 would enable the central mode which is when the NRF52 board is acting as the client and wants to send data and then button 2 would enable the peripheral mode when the NRF52 board is advertising to be connected to another BLE device, but then disable the central mode which is button 1.

Are there any examples related to this? Any help would be appreciated.

Parents
  • Hi,

    The S130 (nRF51) and S132 (nRF52) softdevices are capable of running concurrently in peripheral and central mode with up to 8 individual links (up to 20 in latest S132 v4.0.0 alpha release). You are therefore not required to switch from central to peripheral mode and back, but you can of course do this if you want to. It is also possible to configure button presses to start advertising/scanning for a predefined period of time if this is what you want.

    I recommand that you take a look at the BLE Relay example and the BLE LE Secure Connections multirole example, which both use concurrent paripheral and central mode.

    Best regards,

    Jørgen

  • Thank you I have successfully fixed the L6218E errors. Last question, as I was observing the ble_app_uart_c I noticed some of the methods in that example code which are not included in my code. Is it neccessary to another ble_evt_dispatch method for the calling of &m_ble_nus_c. Currently there is another dispatch for &m_hrs.

    For example:

    From the ble_app_uart example

    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    {
        on_ble_evt(p_ble_evt);
        bsp_btn_ble_on_ble_evt(p_ble_evt);
        ble_db_discovery_on_ble_evt(&m_ble_db_discovery, p_ble_evt);
        **ble_nus_c_on_ble_evt(&m_ble_nus_c,p_ble_evt);**
    }
    

    From the BLE hrs_multi example

    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    
    {
        uint16_t conn_handle;
        uint16_t role;
    
        ble_conn_state_on_ble_evt(p_ble_evt);
        pm_on_ble_evt(p_ble_evt);
    
        // The connection handle should really be retrievable for any event type.
        conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        role        = ble_conn_state_role(conn_handle);
    
        // Based on the role this device plays in the connection, dispatch to the right applications.
        if (role == BLE_GAP_ROLE_PERIPH)
        {
            // Manages peripheral LEDs.
            on_ble_peripheral_evt(p_ble_evt);
    
            ble_advertising_on_ble_evt(p_ble_evt);
            ble_conn_params_on_ble_evt(p_ble_evt);
    
            // Dispatch to peripheral applications.
            **ble_hrs_on_ble_evt (&m_hrs, p_ble_evt);**
    .......
    }
    
Reply
  • Thank you I have successfully fixed the L6218E errors. Last question, as I was observing the ble_app_uart_c I noticed some of the methods in that example code which are not included in my code. Is it neccessary to another ble_evt_dispatch method for the calling of &m_ble_nus_c. Currently there is another dispatch for &m_hrs.

    For example:

    From the ble_app_uart example

    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    {
        on_ble_evt(p_ble_evt);
        bsp_btn_ble_on_ble_evt(p_ble_evt);
        ble_db_discovery_on_ble_evt(&m_ble_db_discovery, p_ble_evt);
        **ble_nus_c_on_ble_evt(&m_ble_nus_c,p_ble_evt);**
    }
    

    From the BLE hrs_multi example

    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    
    {
        uint16_t conn_handle;
        uint16_t role;
    
        ble_conn_state_on_ble_evt(p_ble_evt);
        pm_on_ble_evt(p_ble_evt);
    
        // The connection handle should really be retrievable for any event type.
        conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        role        = ble_conn_state_role(conn_handle);
    
        // Based on the role this device plays in the connection, dispatch to the right applications.
        if (role == BLE_GAP_ROLE_PERIPH)
        {
            // Manages peripheral LEDs.
            on_ble_peripheral_evt(p_ble_evt);
    
            ble_advertising_on_ble_evt(p_ble_evt);
            ble_conn_params_on_ble_evt(p_ble_evt);
    
            // Dispatch to peripheral applications.
            **ble_hrs_on_ble_evt (&m_hrs, p_ble_evt);**
    .......
    }
    
Children
No Data
Related