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.

[FAQ] CC2642R: Synchronizing with a periodic advertising train (CC2642R / CC2652R7)

Part Number: CC2642R
Other Parts Discussed in Thread: CC2652R, CC2652R7, SYSCONFIG

Hi,

Here are some steps to enable synchronization with a periodic advertising train on CC2642R, CC2652R or CC2652R7.

This guide assumes you are using the simple_central example for the device selected. This guide has been tested on SDK 7.10.00.98.

1- Enable support for "Periodic Advertising Sync"

2- Save and close SysConfig

3- In SimpleCentral_processGapMsg(), under GAP_DEVICE_INIT_DONE_EVENT, ensure the GAP layer does not filter out the advertising packets you are interesting into. Commenting out the line "temp16 = SCAN_FLT_PDU_CONNECTABLE_ONLY | SCAN_FLT_PDU_COMPLETE_ONLY;" and replace by "temp16 = SCAN_FLT_PDU_NONCONNECTABLE_ONLY;".

4- (Optional) Automatically trigger scan operation by adding the following code at the end of the case GAP_DEVICE_INIT_DONE_EVENT in SimpleCentral_processGapMsg():

      // Automatically trigger scan
      GapScan_enable(0, 0, 0);

5- Add the code to create a sync with a received advertisement. The following code should be added in SimpleCentral_processAppMsg() within the case "SC_EVT_ADV_REPORT":

      GapScan_Evt_AdvRpt_t* pAdvRpt = (GapScan_Evt_AdvRpt_t*) (pMsg->pData);

//// BEGIN
      if(0 != pAdvRpt->periodicAdvInt)
      {
          // this is a periodic advertisement
          GapScan_PeriodicAdvCreateSyncParams_t pSyncParams;

          pSyncParams.options = SCAN_PERIODIC_DO_NOT_USE_PERIODIC_ADV_LIST |
                                SCAN_PERIODIC_REPORTING_INITIALLY_ENABLED;
          pSyncParams.advAddrType = (uint8)pAdvRpt->addrType; // only ADDRTYPE_PUBLIC and ADDRTYPE_RANDOM are allowed
          osal_memcpy(pSyncParams.advAddress, pAdvRpt->addr, B_ADDR_LEN);
          pSyncParams.skip = 0; // should be between 0 and SCAN_PERIODIC_SKIP_MAX
          pSyncParams.syncTimeout = 1000; // synchronization timeout for the periodic advertising train is 1000*10ms = 10s
                                          // should be between SCAN_PERIODIC_TIMEOUT_MIN and SCAN_PERIODIC_TIMEOUT_MAX
          pSyncParams.syncCteType = SCAN_PERIODIC_CTE_TYPE_ALL;

          uint8_t status = GapScan_PeriodicAdvCreateSync(pAdvRpt->advSid, &pSyncParams);
          if(SUCCESS != status){
            // handle error
          }

          GapScan_disable("");

          break;
      }
//// END

      //Auto connect is enabled

6- Declare a volatile global variable to count the advertisements received.

volatile uint32_t numberOfReports = 0;

7- In SimpleCentral_processGapMsg(), add the handling for the cases GAP_SCAN_CREATE_SYNC_EVENT, GAP_SCAN_PERIODIC_ADV_SYNC_EST_EVENT and GAP_SCAN_PERIODIC_ADV_REPORT_EVENT:

    case GAP_SCAN_CREATE_SYNC_EVENT:
    {
        GapScan_PeriodicAdvEvt_t *pPkt = (GapScan_PeriodicAdvEvt_t *)pMsg;
        uint8_t status;

        if(pPkt->status == SUCCESS)
        {
          status = GapScan_enable(0, DEFAULT_SCAN_DURATION, 0);
          if(SUCCESS != status){
            // handle error
          }
        }
        break;
    }

    case GAP_SCAN_PERIODIC_ADV_SYNC_EST_EVENT:
    {
      GapScan_Evt_PeriodicAdvSyncEst_t *pPkt = (GapScan_Evt_PeriodicAdvSyncEst_t *)pMsg;
      uint8_t status;

      if(pPkt->status == SUCCESS)
      {
        status = GapScan_SetPeriodicAdvReceiveEnable(pPkt->syncHandle, 0x01);
        if(SUCCESS != status){
          // handle error
        }
      }

      break;
    }

    case GAP_SCAN_PERIODIC_ADV_REPORT_EVENT:
    {
      GapScan_Evt_PeriodicAdvRpt_t *pPkt = (GapScan_Evt_PeriodicAdvRpt_t *)pMsg;

      numberOfReports++;

      // Free report payload data
      if (pPkt->pData != NULL)
      {
        ICall_free(pPkt->pData);
      }

      break;
    }

8- Build and Flash the device

9- Turn on the periodic advertiserdevice

10- Run the program in debug mode. Ensure the variable numberOfReports is added to the "expressions" view.

11- The device synchronizes and reports the advertising events:

Note: If you have enabled automatic scan start (step #4), there is no action to be made. If you haven't enabled automatic scan start then you should use the two-button menu to trigger the scan.

Note 2: Even if you have enabled automatic scan start (step #4), you may have to repeat the operation using the two-button menu.

Please also check this thread showing how to set-up CC2642R or CC2652R7 devices as periodic advertiser: https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1294888/faq-cc2642r-periodic-advertising-with-cc2642r-cc2652r7

I hope this will help,

Best regards,