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

Combining BLE UART functionality into a Central+peripheral Relay example

Hi There,

I'm stuck with Getting BLE uart working in another example.

I wasn't sure if converting the BLE Uart example into a central/peripheral application would be more of a headache so I chose to start with The relay example and add UART functionality.

Some givens:

Keil uvision5, SDK 12.3, Nrf51DK, using Termite UART and NRF Toolbox UART viewer.

So maybe someone can tell me what I've done wrong but I started with adding UART init. to the main and working backwards on what was needed.

I added, uart event handle, then nus data handler,  included app_uart.h and ble_nus.h, added some global variables, m_nus and m_conn_handle., added the service code from the ble example. went through SDK_Config and enabled the nus service,enabled the UART driver, added the uart and retarget library.   basically anything that gave an error I dug through and cloned from the ble example.

I'm at a point now where I can communicate through UART to the device, but I cannot communicate out to the BLE app. I can connect with NRF Toolbox but no data is sent back and fourth. It's been a few days and I just dont want to keep bruteforcing things. What should i change in the relay codebase to get this to work?

Any help is appriciated. Thanks.

Parents
  • I never get answers in this form. is it too difficult a question or something? am I a lost cause?

    Anyways, I figured it out. to anyone curious, the difference between the two examples seems to be the ble_evt_dispatch function.

    it splits the previous ble_evt_dispatch into two new modes depending on if its a peripheral connection or central connection.

    In this case, my ble example code falls under the peripheral device category so any previous ble code would have to be funneled in the right mode.

Reply
  • I never get answers in this form. is it too difficult a question or something? am I a lost cause?

    Anyways, I figured it out. to anyone curious, the difference between the two examples seems to be the ble_evt_dispatch function.

    it splits the previous ble_evt_dispatch into two new modes depending on if its a peripheral connection or central connection.

    In this case, my ble example code falls under the peripheral device category so any previous ble code would have to be funneled in the right mode.

Children
  • Hi George,

    I am also trying to implement the UART service which will act as both central and peripheral at a time.

    So, I started including peripheral UART first into the central and peripheral relay example.

    I am also facing the same issue like you, I dumped BLE_UART central example into one board and the modified relay example in another board, both are connected but not able to communicate with each other.

    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_nus_on_ble_evt (&m_nus, p_ble_evt);
    			  bsp_btn_ble_on_ble_evt(p_ble_evt);
           // ble_rscs_on_ble_evt(&m_rscs, p_ble_evt);
        }
        else if ((role == BLE_GAP_ROLE_CENTRAL) || (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT))
        {
            /** on_ble_central_evt will update the connection handles, so we want to execute it
             * after dispatching to the central applications upon disconnection. */
            if (p_ble_evt->header.evt_id != BLE_GAP_EVT_DISCONNECTED)
            {
                on_ble_central_evt(p_ble_evt);
            }
    
            if (conn_handle < CENTRAL_LINK_COUNT + PERIPHERAL_LINK_COUNT)
            {
                ble_db_discovery_on_ble_evt(&m_ble_db_discovery[conn_handle], p_ble_evt);
            }
            ble_hrs_c_on_ble_evt(&m_ble_hrs_c, p_ble_evt);
           // ble_rscs_c_on_ble_evt(&m_ble_rsc_c, p_ble_evt);
    
            // If the peer disconnected, we update the connection handles last.
            if (p_ble_evt->header.evt_id == BLE_GAP_EVT_DISCONNECTED)
            {
                on_ble_central_evt(p_ble_evt);
            }
        }
    }

    The above is my ble_evt_dispatch function, could you suggest me what are the necessary changes and i need to make?

     

Related