This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2340R5: central to peripheral automatically connect

Part Number: CC2340R5
Other Parts Discussed in Thread: UNIFLASH

I have two evolution board (cc2340r5) .so I want to connect automatically central to peripheral(board(central) to board(peripheral)).

when I change address(public address) on peripheral side that time central side it is not getting discovered. 

  • Hello Umesh,

    I am assuming you want to connect two boards based on the Public Address of the peripheral. Please let me know if this is indeed the requirement.

    If that is the case, please take as a reference the basic_ble example (SimpleLink basic_ble example). You can find the project inside the SDK (7_20) and follow the next steps:

    For the Peripheral:

    • Inside basic_ble.syscfg - RF Stacks - BLE - Device Role: set as Peripheral.
    • Inside basic_ble.syscfg - RF Stacks - BLE - General Configuration (Configure General BLE Settings), change Address Mode to: Public Address.
    • Obtain the Public Address of a device following the next steps: 
      • Access Uniflash, search for the device and select Start.                                      
      • Search the address value in a special register stored in the 0x4E000058 address, should be 6-byte long.
      • Build and flash the project (which will use app_peripheral.c as it was configured in the .syscfg file).

    For the Central:

    • Inside basic_ble.syscfg - RF Stacks - BLE - Device Role: set as Central.    
    • Inside app_central.c add the BLEAPPUTIL_ADV_REPORT event flag to the centralScanHandler: 
      // Events handlers struct, contains the handlers and event masks
      // of the application central role module
      BLEAppUtil_EventHandler_t centralScanHandler =
      {
          .handlerType    = BLEAPPUTIL_GAP_SCAN_TYPE,
          .pEventHandler  = Central_ScanEventHandler,
          .eventMask      = BLEAPPUTIL_SCAN_ENABLED |
                            BLEAPPUTIL_SCAN_DISABLED |
                            BLEAPPUTIL_ADV_REPORT
      };
    • Inside app_central.c, add a new case to the Central_ScanEventHandler(). Inside this case, evaluate if the address value is the same as the Public Address of the peripheral obtained in the previous section to filter out other devices. 
              case BLEAPPUTIL_ADV_REPORT:
              {
                  bleStk_GapScan_Evt_AdvRpt_t *pScanRpt = &scanMsg->pBuf->pAdvReport;
                  if (pScanRpt->pData != NULL)
                  {
                    //GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF);
                    if(pScanRpt->addr[0] == 0x52 &&
                       pScanRpt->addr[1] == 0x29 &&
                       pScanRpt->addr[2] == 0xAF &&
                       pScanRpt->addr[3] == 0xF1 &&
                       pScanRpt->addr[4] == 0x34 &&
                       pScanRpt->addr[5] == 0xA4){
      
                       // Set the connection parameters
                       BLEAppUtil_ConnectParams_t connParams =
                       {
                       .peerAddrType = pScanRpt->addrType,
                       .phys = INIT_PHY_1M,
                       .timeout = 3000
                        };
                        //Copy the selected address
                        memcpy(connParams.pPeerAddress, pScanRpt->addr, B_ADDR_LEN);
                        status = BLEAppUtil_connect(&connParams);
                        //GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
                    }
                  }
                  break;
              }
    • Inside app_central.c, add central scan parameters: 
      const BLEAppUtil_ScanStart_t centralScanStartParams =
      {
          /*! Zero for continuously scanning */
          .scanPeriod     = DEFAULT_SCAN_PERIOD, /* Units of 1.28sec */
      
          /*! Scan Duration shall be greater than to scan interval,*/
          /*! Zero continuously scanning. */
          .scanDuration   = DEFAULT_SCAN_DURATION, /* Units of 10ms */
      
          /*! If non-zero, the list of advertising reports will be */
          /*! generated and come with @ref GAP_EVT_SCAN_DISABLED.  */
          .maxNumReport   = APP_MAX_NUM_OF_ADV_REPORTS
      };
      
    • Inside app_central.c, modify Central_start() function to trigger the scanning by adding the following: 
          status = BLEAppUtil_scanStart(&centralScanStartParams);
          if(status != SUCCESS)
            {
                // Return status value
                return(status);
           }
    • Build and flash the project (which will use app_central.c as it was configured in the .syscfg file).

    Hope it helps.

    David.