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

Error in NUS Peripheral and central

Hello,

i’m using NRF52832 with SoftDevice S132 and Sdk 15.3 to develop a NUS peripheral and central. The system is tested as follows:

I have two NUS peripherals , a NUS Central-Peripheral device that echoes the data received from the peripherals and a central, in my case a SmartDevice(IOS). For the software I was based on the Nus examples and the Relay example. The 2 NUS Peripheral work perfectly. The Problem lies in the NUS Peripheral-Central-device. When I connect first the 2 Nus peripherals and afterwards connect the IOS-device, everything works perfectly. The Problem occurs if a sensor or both connects after the IOS-device. In this case the ble_nus_data_send() returns NRF_ERROR_INVALID_STATE. During Debugging I found out that on_connect() method in ble_nus.h was called, when the Nus peripherals were connected to the NUS peripheral-central-device. (Note Nus peripherals are ble_nus_c instances from the perspective of NUS peripheral-central-device and It should not call/trigger methods from ble_nus.h)

Thanks for your help in advance.

Parents
  • Hi Aditdv, 

    Please clarify, you were creating your own relay device that combine the central and peripheral ble_app_uart together ? 

    Please show your code where you have doubt.

    Please note that there is no call to on_connect() inside original ble_nus_c.c file , nor that file link to ble_nus.h, it only link to ble_nus_c.h 

    Please check again with the original ble_nus_c.c file. 

    on_connect() is called inside ble_nus_on_ble_evt, which is belong to ble_nus.c 

  • Hello Hung Bui,

    Thanks for your reply. Yes, I'm creating my own relay example by combining central and peripheral ble_app_uart examples. I know that there should not be a call to on_connect() from ble_nus_c, but I'm positive that when a peripheral is connecting, the on_connect() is called.  I dont understand why.

    The one thing that im not sure about is the definition of the instances. As i'm using c++ for coding, i had to expand some of the Makros, as they were not compatible with c++. See following code snippet.

    RF_BLE_GATT_DEF(m_gatt);                                           /**< GATT module instance. */
    NRF_BLE_QWRS_DEF(m_qwr, NRF_SDH_BLE_TOTAL_LINK_COUNT);              /**< Context for the Queued Write module.*/
    BLE_NUS_C_ARRAY_DEF(m_ble_nus_c, NRF_SDH_BLE_CENTRAL_LINK_COUNT);
    BLE_ADVERTISING_DEF(m_advertising);                                 /**< Advertising module instance. */
    NRF_BLE_SCAN_DEF(m_scan);
    /**< Scanning module instance. */
    
    static uint32_t m_nus_link_ctx_storage_ctx_data_pool[((1))*(((sizeof(ble_nus_client_context_t)) + 3) >> 2)];
    static blcm_link_ctx_storage_t m_nus_link_ctx_storage =                                                          \
    {
    	.p_ctx_data_pool = m_nus_link_ctx_storage_ctx_data_pool,
    	.max_links_cnt   = ((NRF_SDH_BLE_TOTAL_LINK_COUNT)),
    	.link_ctx_size   = sizeof(m_nus_link_ctx_storage_ctx_data_pool)
    };
    static ble_nus_t m_nus =
    {
    	.uuid_type = 0,
    	.service_handle = 0,
    	.tx_handles = {0},
    	.rx_handles = {0},
    	.p_link_ctx_storage = &m_nus_link_ctx_storage,
    };
    
    NRF_SECTION_ITEM_REGISTER(sdh_ble_observers5, static nrf_sdh_ble_evt_observer_t m_nus_obs) =
    {
        .handler   = ble_nus_on_ble_evt,
        .p_context = &m_nus,
    };
    
    /**< Database discovery module instances. */
    /* As there are 2 peripherals to be discovered, two instances of ble_db_discovery_t are created. MACRO not compatible with c++ */
    static ble_db_discovery_t m_db_disc[2];
    
    NRF_SECTION_ITEM_REGISTER(sdh_ble_observers3, static nrf_sdh_ble_evt_observer_t m_db_obs1) =
    {
        .handler   = ble_db_discovery_on_ble_evt,
        .p_context = &m_db_disc[1],
    };
    
    NRF_SECTION_ITEM_REGISTER(sdh_ble_observers4, static nrf_sdh_ble_evt_observer_t m_db_obs2) =
    {
        .handler   = ble_db_discovery_on_ble_evt,
        .p_context = &m_db_disc[0],
    };
    

  • There could be that when you get connected, event BLE_GAP_EVT_CONNECTED will arrive. And ble_nus_on_ble_evt() in ble_nus.c will be called (because it's observing those events) and on_connect() will be executed. Please use a check for p_ble_evt->evt.gap_evt.params.connected.role==BLE_GAP_ROLE_PERIPH before you proceed in that function. Similar to what we have in on_connect() inside ble_conn_params.c

  • Sorry for the late response. I'm already separating between the peripheral and central roles. The problem was not there. I already found a workaround and got it working. Thank you for your help.

    Best regards

Reply Children
No Data
Related