I'm trying to establish a bond in my project and then perform service discovery, however the discovery is returning the BUSY error.
I tried to wait for the events according to the documentation but they will never trigger so long as I have the while(bondPending){} statement there because the events are part of the same interrupt.
What's the proper way to perform two actions (dm_security_setup_req() & ble_db_discovery_start() in this case) sequentially, while waiting for an event between the two?
/* Perform bonding upon connection */
bondPending = 1;
err_code = dm_security_setup_req(&m_dm_device_handle);
APP_ERROR_CHECK(err_code);
while(bondPending){}
// Discover peer's services.
err_code = ble_db_discovery_start(&m_ble_db_discovery, p_event->event_param.p_gap_param->conn_handle);
APP_ERROR_CHECK(err_code);
case DM_EVT_SECURITY_SETUP_COMPLETE:
bondPending = 0;
APPL_LOG("[APPL]: >> DM_EVT_SECURITY_SETUP_COMPLETE\r\n");
// Heart rate service discovered. Enable notification of Heart Rate Measurement.
err_code = ble_hrs_c_hrm_notif_enable(&m_ble_hrs_c);
APP_ERROR_CHECK(err_code);
APPL_LOG("[APPL]: << DM_EVT_SECURITY_SETUP_COMPLETE\r\n");
break;
case DM_EVT_LINK_SECURED:
bondPending = 0;
APPL_LOG("[APPL]: >> DM_LINK_SECURED_IND\r\n");
APPL_LOG("[APPL]: << DM_LINK_SECURED_IND\r\n");
break;