Part Number:LP-CC2652RB
我按照SimpleLink CC13x2 / CC26x2 SDK BLE5-Stack User's Guide 2.02.01.00中周期广播那节的指导步骤进行外设设备的代码编写,
但主机centor设备无法接收到通过GapAdv_SetPeriodicAdvData函数设置的周期广播数据,但可以接收到GapAdv_loadByHandle设置的数据。附上外设设备配置周期广播部分的代码段如下,各函数返回的status我已经检查过,都返回了SUCCESS
// Periodic Advertising Intervals #define PERIDIC_ADV_INTERVAL_MIN160 #define PERIDIC_ADV_INTERVAL_MAX160 /// Non-Connectable & Non-Scannable advertising set #define GAPADV_PARAMS_AE_NC_NS {\.eventProps = 0,\.primIntMin = 160,\.primIntMax = 160,\.primChanMap = GAP_ADV_CHAN_ALL,\.peerAddrType = PEER_ADDRTYPE_PUBLIC_OR_PUBLIC_ID,\.peerAddr = { 0x74, 0xD2, 0x85, 0xD4, 0x63, 0xB4 },\.filterPolicy = GAP_ADV_WL_POLICY_ANY_REQ,\.txPower = GAP_ADV_TX_POWER_NO_PREFERENCE,\.primPhy = GAP_ADV_PRIM_PHY_1_MBPS,\.secPhy = GAP_ADV_SEC_PHY_1_MBPS,\.sid = 1\ } static uint8 advHandleNCNS;// Non-Connactable & Non-Scannable static uint8_t periodicData[] = {'P','e','r','i','o','d','i','c','A','d','v' }; #define GAPADV_DATA_PERIODIC_ADV {\.operation = GAPADV_PERIODIC_ADV_DATA_COMPLETE,\.dataLength = sizeof(periodicData),\.pData = periodicData\ } // Advertisement data static uint8_t advertData[] = {0x0C,// Length of this dataGAP_ADTYPE_LOCAL_NAME_SHORT, // Type of this data'P','e','r','i','o','d','i','c','A','d','v',0x02,// length of this dataGAP_ADTYPE_FLAGS,GAP_ADTYPE_FLAGS_GENERAL | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED, }; // Create non connectable & non scannable advertising set #3 GapAdv_params_t advParamNonConn = GAPADV_PARAMS_AE_NC_NS; // Create Advertisement set #3 and assign handle status = GapAdv_create(&SimplePeripheral_advCallback, &advParamNonConn, &advHandleNCNS); // Load advertising data for set #3 that is statically allocated by the app status = GapAdv_loadByHandle(advHandleNCNS, GAP_ADV_DATA_TYPE_ADV,sizeof(advertData), advertData); // Set event mask for set #3 status = GapAdv_setEventMask(advHandleNCNS,GAP_ADV_EVT_MASK_START_AFTER_ENABLE |GAP_ADV_EVT_MASK_END_AFTER_DISABLE |GAP_ADV_EVT_MASK_SET_TERMINATED); // Enable non connectable & non scannable advertising for set #3 status = GapAdv_enable(advHandleNCNS, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0); // Set Periodic Advertising parameters GapAdv_periodicAdvParams_t perParams = {PERIDIC_ADV_INTERVAL_MIN,PERIDIC_ADV_INTERVAL_MAX, 0x40}; status = GapAdv_SetPeriodicAdvParams(advHandleNCNS, &perParams); GapAdv_periodicAdvData_t periodicDataParams = GAPADV_DATA_PERIODIC_ADV; status = GapAdv_SetPeriodicAdvData(advHandleNCNS, &periodicDataParams); // Enable the periodic advertising status = GapAdv_SetPeriodicAdvEnable(1, advHandleNCNS);
经过在论坛搜索,我找到了之前的一个帖子[参考译文] LAUNCHXL-CC26X2R1:BTool 中发送周期性广播包的正确方法是什么? – Bluetooth®︎(参考译文帖)(Read Only) – Bluetooth®︎(参考译文帖) – E2E 设计支持 (ti.com),问题描述与我目前的现象基本一样,目前我仍没有找到问题原因和解决方法。
Nick Sun:
您好,
我们需要一点时间查看这个问题,有结论后及时联系您。
,
wj s:
好的,感谢!
,
Nick Sun:
您好,
这个问题我们帮您升级到E2E英文论坛由专业产线工程师帮您解答,有回复及时联系您。
这边希望您提供一下相关正在使用的SDK版本
,
wj s:
您好,目前正在使用的SDK版本为simplelink_cc13x2_26x2_sdk_5_10_00_48
,
Nick Sun:
您好,
您必须在 simple_central 进行一些额外的代码修改才能捕获周期性广告。这些修改写在了 Synchronize with a Periodic Advertising Train 部分中。您是否实施了这些步骤?
,
wj s:
抱歉,上周没有及时回复您。
附上我的simple_central代码
初始化相关代码如下:
void SimpleCentral_scanCb(uint32_t evt, void* pMsg, uintptr_t arg) {uint8_t event;if (evt & GAP_EVT_ADV_REPORT){event = SC_EVT_ADV_REPORT;}else if (evt & GAP_EVT_SCAN_ENABLED){event = SC_EVT_SCAN_ENABLED;}else if (evt & GAP_EVT_SCAN_DISABLED){event = SC_EVT_SCAN_DISABLED;}else if (evt & GAP_EVT_INSUFFICIENT_MEMORY){event = SC_EVT_INSUFFICIENT_MEM;}else{return;}if(SimpleCentral_enqueueMsg(event, SUCCESS, pMsg) != SUCCESS){ICall_free(pMsg);} }GapScan_registerCb(SimpleCentral_scanCb, NULL);// Set Scanner Event Mask GapScan_setEventMask(GAP_EVT_SCAN_ENABLED | GAP_EVT_SCAN_DISABLED |GAP_EVT_ADV_REPORT);// Set Scan PHY parameters GapScan_setPhyParams(DEFAULT_SCAN_PHY, SCAN_TYPE_PASSIVE,DEFAULT_SCAN_INTERVAL, DEFAULT_SCAN_WINDOW);// Set Advertising report fields to keep temp16 = (SCAN_ADVRPT_FLD_ADDRESS | SCAN_ADVRPT_FLD_ADDRTYPE); GapScan_setParam(SCAN_PARAM_RPT_FIELDS, &temp16); // Set Scanning Primary PHY temp8 = SCAN_PRIM_PHY_1M; GapScan_setParam(SCAN_PARAM_PRIM_PHYS, &temp8); // Set LL Duplicate Filter temp8 = SCAN_FLT_DUP_ENABLE; GapScan_setParam(SCAN_PARAM_FLT_DUP, &temp8);temp16 = SCAN_FLT_PDU_NONCONNECTABLE_ONLY; GapScan_setParam(SCAN_PARAM_FLT_PDU_TYPE, &temp16);// Set initiating PHY parameters // INIT_PHYPARAM_MAX_CONN_INT = 80 GapInit_setPhyParam(INIT_PHY_1M, INIT_PHYPARAM_CONN_INT_MIN,INIT_PHYPARAM_MIN_CONN_INT); GapInit_setPhyParam(INIT_PHY_1M, INIT_PHYPARAM_CONN_INT_MAX,INIT_PHYPARAM_MAX_CONN_INT);在SimpleCentral_processAppMsg函数中关于SC_EVT_ADV_REPORT广播扫描报告事件的处理中,我加了打印,第一个现象是没看到pAdvRpt->periodicAdvInt != 0的周期广播数据,第二个现象是发现了我的simple_peripheral设置的GapAdv_loadByHandle广播数据,代码如下:
static void SimpleCentral_processAppMsg(scEvt_t *pMsg) {bool safeToDealloc = TRUE;if (pMsg->hdr.event <= APP_EVT_EVENT_MAX){BLE_LOG_INT_STR(0, BLE_LOG_MODULE_APP, "APP : App msg status=%d, event=%s\n", 0, appEventStrings[pMsg->hdr.event]);}else{BLE_LOG_INT_INT(0, BLE_LOG_MODULE_APP, "APP : App msg status=%d, event=0x%x\n", 0, pMsg->hdr.event);}switch (pMsg->hdr.event){case SC_EVT_KEY_CHANGE:SimpleCentral_handleKeys(pMsg->hdr.state);break;case SC_EVT_ADV_REPORT:{GapScan_Evt_AdvRpt_t* pAdvRpt = (GapScan_Evt_AdvRpt_t*) (pMsg->pData);if(0 != pAdvRpt->periodicAdvInt){// this is a periodic advertisementDisplay_printf(dispHandle, SC_ROW_9, 0, "this is a periodic advertisement");SimpleCentral_doStopDiscovering(0);}else{// this is NOT a periodic advertisement}// reporting the advData according to the peripheral addressif(pAdvRpt->addr[0] == 0x8c && pAdvRpt->addr[5] == 0x74) { // this is my peripheral addressDisplay_printf(dispHandle, SC_ROW_NON_CONN, 0, "Discovered: %s", Util_convertBdAddr2Str(pAdvRpt->addr));int j = 0;Display_printf(dispHandle, SC_ROW_9 + 1, 0, "advertisement data len: %d", pAdvRpt->dataLen);for(j = 0; j < pAdvRpt->dataLen; j++) {Display_printf(dispHandle, SC_ROW_9 + 2 + j, 0, "%x", *(pAdvRpt->pData + j));}}// Free report payload dataif (pAdvRpt->pData != NULL){ICall_free(pAdvRpt->pData);}break;}// ...default:// Do nothing.break; }根据 Synchronize with a Periodic Advertising Train中的步骤来看,目前我在第六步遇到了问题,无法识别到periodic advertisers
,
Nick Sun:
您好,
我建议您首先验证 advertiser 是否实际发送定期广告。这可以通过使用逻辑分析仪和使用RF调试引脚来完成,您可以像这样启用。
https://dev.ti.com/tirex/content/simplelink_cc13xx_cc26xx_sdk_6_41_00_17/docs/ble5stack/ble_user_guide/html/ble-stack-5.x-guide/debugging-index.html#debugging-rf-output
我还建议您使用GAPADV_PERIODIC_ADV_ENABLE_TX_POWER而不是使用0x40 hex value。
一旦您确认 advertiser 实际上正在发送定期广告,就可以看到如何让 central 可以同步到他们。