主题中讨论的其他器件: CC2652R、 CC2652R7、 SysConfig
您好!
以下是在 CC2642R、CC2652R 或 CC2652R7上启用定期广播的一些步骤。
本指南假定您针对所选器件使用 simple_peripheral 示例。 本指南已在 SDK 7.10.00.98上进行了测试。
1-在 SysConfig 中启用对周期性广播的支持
2-在 SysConfig 中创建新的广播集
3-为新创建的广播集设置广播数据
4 -保存并关闭 SysConfig
5-(可选)通过注释掉找到的"GapAdv_enable"命令来禁用设置的其他广播
6-添加所需的全局数据
// Create non connectable & non scannable advertising #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 = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, \ .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 // Periodic Advertising Data static uint8_t periodicData[] = { 'P', 'e', 'r', 'i', 'o', 'd', 'i', 'c', 'A', 'd', 'v' };
7-在 SimplePeripheral_processGapMessage ()中处理 GAP_DEVICE_INIT_DONE_EVENT 事件结束时添加以下代码
// Create Advertisement set #3 and assign handle GapAdv_params_t advParamNonConn = GAPADV_PARAMS_AE_NC_NS; 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(advData3), advData3); // 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 // This is a must in order to enable periodic advertisement status = GapAdv_enable(advHandleNCNS, GAP_ADV_ENABLE_OPTIONS_USE_MAX , 0); // Set Periodic Advertising parameters GapAdv_periodicAdvParams_t perParams = {240, 240, 0x40}; status = GapAdv_SetPeriodicAdvParams(advHandleNCNS, &perParams);
8-在 SimplePeripheral_processGapMessage 中添加对 GAP_ADV_SET_PERIODICLE_ADV_PARAMS_EVENT 和 GAP_ADV_SET_PERIOD_ADV_DATA_EVENT 事件的处理
case GAP_ADV_SET_PERIODIC_ADV_PARAMS_EVENT: { uint8_t status; GapAdv_periodicAdvData_t periodicDataParams = {0x03, sizeof(periodicData), periodicData}; status = GapAdv_SetPeriodicAdvData(advHandleNCNS, &periodicDataParams); } break; case GAP_ADV_SET_PERIODIC_ADV_DATA_EVENT: { uint8_t status; status = GapAdv_SetPeriodicAdvEnable(1, advHandleNCNS); } break;
9-(可选)按照调试指南中的描述使能 RF 可观察到的内容(在没有蓝牙监听器时十分有用)。
在 main.c 中添加以下内容、其中包括:"#include "
然后在 Board_initGeneral()之后添加以下代码
// Map LNA enable pin RFC_GPO0 to DIO6 IOCPortConfigureSet(IOID_6, IOC_PORT_RFC_GPO0, IOC_IOMODE_NORMAL); // Map Tx start pin RFC_GPO3 to DIO7 IOCPortConfigureSet(IOID_7, IOC_PORT_RFC_GPO3, IOC_IOMODE_NORMAL);
10 -构建代码并刷写设备
适用于支持定期广播的 CC26X2R1 LaunchPad 的 Hexfile: /cfs-file/__key/communityserver-components-multipleuploadfilemanager/d35fa551_2D00_8bfa_2D00_42ea_2D00_8c7f_2D00_ea501b1a1ce7-370266-complete/simple_5F00_peripheral_5F00_CC26X2R1_5F00_LAUNCHXL_5F00_tirtos7_5F00_ticlang.hex
用于支持定期广播的 CC2652R7 LaunchPad 的 Hexfile: /cfs-file/__key/communityserver-discussions-components-files/538/simple_5F00_peripheral_5F00_LP_5F00_CC2652R7_5F00_tirtos7_5F00_ticlang.hex
我希望这将有所帮助、
此致、