4 Replies Latest reply on Jan 25, 2017 1:50 AM by dalip.sharma_2011746

    PSOC 4 BLE : central not connecting to peripheral. central scans peripherals properly, but dont connect.

    dalip.sharma_2011746

      I have two cy8ckit-042-ble and I am trying to connect my 1st BLE kit configured as GAP role: central and GATT Client with a 2nd BLE kit configured as GAP role: peripheral and GATT server. It can generate event
      CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT: I can fetch address of peer device. STOP scanning using CyBle_GapcStopScan().
      As a result following event is generated CYBLE_EVT_GAPC_SCAN_START_STOP: When I call  res = CyBle_GapcConnectDevice(&peerAddr); value in res is CYBLE_ERROR_OK, but not generating CYBLE_EVT_GAP_DEVICE_CONNECTED. I get HCI error.
      CYBLE_HCI_COMMAND_DISALLOWED_ERROR.

         

      *****Is thereany specific way to call : CyBle_GapcConnectDevice((const CYBLE_GAP_BD_ADDR_T* )&add);

         

      i have called this API wen event  generated is CYBLE_EVT_GAPC_SCAN_START_STOP on calling CyBle_GapcStopScan().

         

      code for central is as follows:

         

      *************************

         

      #include "project.h"

         

      void ble(uint32 eventCode, void *eventParam);

         

      CYBLE_GATTC_WRITE_REQ_T writeReqParam;

         

      static volatile CYBLE_API_RESULT_T res;

         

      static CYBLE_GAP_BD_ADDR_T add;

         

      void v_workerBLE_slaveSelectionHandler(CYBLE_GAPC_ADV_REPORT_T* eventParam);

         

      void resolveErr(CYBLE_HCI_ERROR_T *eventParam);

         

      uint8 u8slaveFound;

         

      int main(void)

         

      {

         

      CyGlobalIntEnable; /* Enable global interrupts. */

         

      CyBle_Start(ble);

         

      while(1)

         

      {

         

      CyBle_ProcessEvents();

         

      }

         

      }

         

      void ble(uint32 eventCode, void *eventParam)

         

      {

         

      switch(eventCode)

         

      {

         

      case CYBLE_EVT_STACK:

         

                CyBle_GapcStartScan(CYBLE_SCANNING_FAST);

         

      break;

         

      case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

         

               // call api to vew n list scanned device, and save the address of device

         

              // this API working fine and shows scanned devices and generates

         

              // CYBLE_EVT_GAPC_SCAN_START_STOP event.

         

      v_workerBLE_slaveSelectionHandler((CYBLE_GAPC_ADV_REPORT_T *)eventParam);

         

      break;

         

      case CYBLE_EVT_GAPC_SCAN_START_STOP:

         

      {

         

      // **** error section. not generating next event. CYBLE_EVT_GAP_DEVICE_CONNECTED

         

      // API - CyBle_GapcConnectDevice((const CYBLE_GAP_BD_ADDR_T* )&add); generates  

         

      //  CYBLE_EVT_HCI_STATUS event , which is error. res variable shows all OK-no error.

         

      if(u8slaveFound)

         

      {

         

      //peerAddr.type = 0u;

         

      // connect to the device

         

      // ** error API- THIS API GENERATES HCI ERROR

         

      res = CyBle_GapcConnectDevice((const CYBLE_GAP_BD_ADDR_T* )&add);  

         

      }

         

      }

         

      break;

         

      case CYBLE_EVT_GAP_DEVICE_CONNECTED:

         

      CyBle_GattcStartDiscovery(cyBle_connHandle);

         

      break;

         

      case CYBLE_EVT_GATTC_DISCOVERY_COMPLETE:

         

      // do some work 

         

      break;

         

      case CYBLE_EVT_HCI_STATUS:

         

      resolveErr(eventParam);

         

      break;

         

      default:

         

      CyBle_GapcStartScan(CYBLE_SCANNING_FAST);

         

      break;

         

      }

         

      }

         

      void v_workerBLE_slaveSelectionHandler(CYBLE_GAPC_ADV_REPORT_T* eventParam)

         

      {

         

      uint8 newDevice = 0u, device = 0u;

         

      uint8 i;

         

      uint8 adStructPtr = 0u;

         

      uint8 adTypePtr = 0u;

         

      uint8 nextPtr = 0u;

         

      // copy peer device address- address of device which we want to connect to

         

      memcpy(add.bdAddr, eventParam->peerBdAddr, CYBLE_GAP_BD_ADDR_SIZE);

         

      add.type = eventParam->eventType;

         

      {

         

      // convert little endian to big endian as for now

         

      add.bdAddr[0] = eventParam->peerBdAddr[5];

         

      add.bdAddr[1] = eventParam->peerBdAddr[4];

         

      add.bdAddr[2] = eventParam->peerBdAddr[3];

         

      add.bdAddr[3] = eventParam->peerBdAddr[2];

         

      add.bdAddr[4] = eventParam->peerBdAddr[1];

         

      add.bdAddr[5] = eventParam->peerBdAddr[0];

         

      u8slaveFound = 1u;

         

      CyBle_GapcStopScan();

         

      }

         

      }

         

      void resolveErr(CYBLE_HCI_ERROR_T *eventParam)

         

      {

         

      // see error code- CYBLE_HCI_COMMAND_DISALLOWED_ERROR in my case

         

      volatile uint8 err = *eventParam;

         

      }