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

ble_app_uart multilink_central with a peripheral

Hi team

I have a problem that bothers me for days.

I try to run demo ble_app_uart_c with

  NRF_SDH_BLE_CENTRAL_LINK_COUNT=8 and NRF_SDH_BLE_PERIPHERAL_LINK_COUNT=1.

first,I use APP nRF toolbox scan and connect first board witch running this demo.It works fine.I can send data with ble_nus_string_send() and recive data from APP.

And then,after I use the second board (runs demo ble_app_uart) connect the first board,the first board use ble_nus_string_send() send data to APP will get event BLE_ERROR_GATTS_SYS_ATTR_MISSING.The other functions work fine.Two boards can send data to each other.The first board can send data to APP.

And I found that if I use nRF toolbox to disconnect the board and reconnect it .It all goes normal.But when a new peripheral connect to the central board I will get this event again.

And What I'm referring to is ble_app_multilink_central and ble_app_hrs_rscs_relay without peer manager. Please give me some advice.

There is some change that i do: main:

int main(void)
{
uint32_t err_code;
bool     erase_bonds;
log_init();
timer_init();
power_init();
uart_init();
buttons_leds_init(&erase_bonds);
db_discovery_init();
ble_stack_init();
gatt_init();
nus_c_init();



if(0==isScanning)
  scan_start();
/***********ADD****************/
gap_params_init();
services_init();
advertising_init();
conn_params_init();
err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);

/***************************/

for (;;)
{
    if (NRF_LOG_PROCESS() == false)
    {
        nrf_pwr_mgmt_run();
    }
}
}

uart:

void uart_event_handle(app_uart_evt_t * p_event)
{
.............
switch (p_event->evt_type)
{
    .............
        
        if ((data_array[index - 1] == '\n') || (index >= (m_ble_nus_max_data_len)))
        {
            ...............

            do
            {//TODO
                //ret_val = ble_nus_c_string_send(&m_ble_nus_c, data_array, index);
                if(SendToTag==0xA0){
                      ret_val = ble_nus_string_send(&m_nus, data_array, &index);
                      
                }else if(SendToTag==0xA1){
                      ret_val = ble_nus_c_string_send(&m_ble_nus_c[data_array[1]], data_array,
   index);
                }
                
                if ( (ret_val != NRF_ERROR_INVALID_STATE) && 
                (ret_val != NRF_ERROR_BUSY) 
                )
                {
                    APP_ERROR_CHECK(ret_val);
                }
                
            } while (ret_val == NRF_ERROR_BUSY);

            index = 0;
        }
        break;

    ...........


}
}
Parents
  • I am using SDK v14.2
    // m_nus register a event handler ble_nus_on_ble_evt() by using marco  BLE_NUS_DEF 
    BLE_NUS_DEF(m_nus); 
    // All event will be handled by ble_nus_on_ble_evt(), NOT only NUS related events
    // If BLE_GAP_EVT_CONNECTED event comes,
    // ble_nus_on_ble_evt() calls on_connect() then set p_nus->conn_handle to p_ble_evt->evt.gap_evt.conn_handle;
    // (ble_nus.c LN63)
     
    // That means "Any new connection will set m_nus.conn_handle to be the new connect handle"
    // to resolve this issue, i use following code
    // but this work only if you have only 1 peripheral
    static ble_nus_t m_nus;
    static void wrapper_ble_nus_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint16_t conn_handle;
        uint16_t role;
        ble_nus_t * p_nus = (ble_nus_t *)p_context;

        if ((p_nus == NULL) || (p_ble_evt == NULL)) {
            return;
        }

        conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        role = ble_conn_state_role(conn_handle);

        if (role == BLE_GAP_ROLE_PERIPH) {
            ble_nus_on_ble_evt(p_ble_evt, p_context);
        }
    }
    NRF_SDH_BLE_OBSERVER(m_nus_obs, BLE_NUS_BLE_OBSERVER_PRIO, wrapper_ble_nus_on_ble_evt, &m_nus);
Reply Children
No Data
Related