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

BLE_NUS_C_EVT_NUS_TX_EVT event received twice when the central connect peripheral second times

Hi,

  I'm using two  boards with nrf52832 and sdk 15.3.0.  One alter the  ble_app_mult_uart__c example as  ble center ,the othe alter the  ble_app_uart example as  ble peripheral .Two boards connect well .

  But the problem is that when the peripheral disconnect and the center connected the same peripheral second time ,I found that BLE_NUS_C_EVT_NUS_TX_EVT event received twice .That caused the center prinf the rx. data twice on PC . I haved follow this issue'suggestion ,add 

   ble_nus_c_evt.conn_handle = p_ble_evt->evt.gap_evt.conn_handle;

  before

  p_ble_nus_c->evt_handler(p_ble_nus_c, &ble_nus_c_evt);

 But it didn't work ,the problem still happen .Debug found that p_ble_nus_c->conn_handle(0xffff)  caused it , so i add the code   in the ble_nus_c_on_ble_evt() function 

   case BLE_GATTC_EVT_HVX:
      #if 1 //20210130 add this,due to printf twice
          if(p_ble_nus_c->conn_handle != BLE_CONN_HANDLE_INVALID){
             on_hvx(p_ble_nus_c, p_ble_evt);
         }
     #else
        on_hvx(p_ble_nus_c, p_ble_evt);
    #endif
    break;

The issue won't happen again. Add this code would affect the other fuction ?  I know that it can't slove the source of the problem .

Any good suggestion on this will be of great help.

Thank you very much .

Related