You should get CYBLE_EVT_GAPC_SCAN_START_STOP with the event data of '0x01' indicating success, before initiating a connection. This could be the reason for HCI error.
Thanks for the reply.
With more investigation in this topic, here is more findings.
#1. When CYBLE_EVT_GAPC_SCAN_START_STOP received the event data is "0x01", then I try to init the connection
In most situation it will report this HCI error.
#2. This is because the ble state still in CyBle_GetState() == CYBLE_STATE_SCANNING
If the duplicate filtering is not selected, these scan result event still coming.
#3. So for temp solution, put the connect in the main loop, until the state not in CYBLE_STATE_SCANNING.
So what is the standard procedure for connect a new device?
#1. startscan CyBle_GapcStartScan
#2. processing the scan result CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT
#3. once find the target device, stop scan CyBle_GapcStopScan
#4. connect when receive the CYBLE_EVT_GAPC_SCAN_START_STOP and event data=0x01?