cc26X2将simple_peripheral_oad_onchip 修改为主从一体

1 基础平台

1.1 sdk:simplelink_cc13x2_26x2_sdk_3_30_00_03
1.2 ccs_9.22

2.步骤

2.1 在syscfg 里面将角色修改一下

cc26X2将simple_peripheral_oad_onchip 修改为主从一体_第1张图片

2.2 添加代码

1:在初始化中,添加gap两个角色

  //Initialize GAP layer for Peripheral role and register to receive GAP events
  GAP_DeviceInit(GAP_PROFILE_PERIPHERAL|GAP_PROFILE_CENTRAL, selfEntity, addrMode, mac_buf);

2:添加扫描代码

void multi_role_scanCB(uint32_t evt, void* pMsg, uintptr_t arg)
{
  uint8_t event;

  if (evt & GAP_EVT_ADV_REPORT)
  {
//    event = MR_EVT_ADV_REPORT;
  }
  else if (evt & GAP_EVT_SCAN_ENABLED)
  {

  }
  else if (evt & GAP_EVT_SCAN_DISABLED)
  {

  }
  else if (evt & GAP_EVT_INSUFFICIENT_MEMORY)
  {

  }
  else
  {
    return;
  }

  if(SimplePeripheral_enqueueMsg(event, pMsg) != SUCCESS)
  {
    ICall_free(pMsg);
  }

}


#define DEFAULT_SCAN_PHY                        SCAN_PRIM_PHY_1M

//Default Scan type (Active/Passive)
#define DEFAULT_SCAN_TYPE                       SCAN_TYPE_ACTIVE

// Default scan interval (in 625 us ticks)
#define DEFAULT_SCAN_INTERVAL                   800

// Default scan window   (in 625 us ticks)
#define DEFAULT_SCAN_WINDOW                     800

// Default scan duration in 10 ms
#define DEFAULT_SCAN_DURATION                   100

#define DEFAULT_INIT_PHY                      INIT_PHY_1M

// Default minimum connection interval (in 1.25ms)
#define INIT_PHYPARAM_MIN_CONN_INT            80

// Default maximum connection interval (in 1.25ms)
#define INIT_PHYPARAM_MAX_CONN_INT            80



// Advertising report fields to keep in the list
#define ADV_RPT_FIELDS                          (SCAN_ADVRPT_FLD_ADDRESS | SCAN_ADVRPT_FLD_ADDRTYPE)

static void multi_role_scanInit(void)
{
  uint8_t temp8;
  uint16_t temp16;


  GapScan_registerCb(multi_role_scanCB, NULL);


  GapScan_setEventMask(GAP_EVT_SCAN_ENABLED | GAP_EVT_SCAN_DISABLED |
                       GAP_EVT_ADV_REPORT);


  GapScan_setPhyParams(DEFAULT_SCAN_PHY, SCAN_TYPE_ACTIVE,
                       SCAN_PARAM_DFLT_INTERVAL, SCAN_PARAM_DFLT_WINDOW);

  // Set Advertising report fields to keep
  temp16 = ADV_RPT_FIELDS;
  GapScan_setParam(SCAN_PARAM_RPT_FIELDS, &temp16);
  // Set Scanning Primary PHY
  temp8 = DEFAULT_SCAN_PHY;
  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_CONNECTABLE_ONLY | SCAN_FLT_PDU_COMPLETE_ONLY;
  GapScan_setParam(SCAN_PARAM_FLT_PDU_TYPE, &temp16);

  // Set initiating PHY parameters
  GapInit_setPhyParam(DEFAULT_INIT_PHY, INIT_PHYPARAM_CONN_INT_MIN,
                      INIT_PHYPARAM_MIN_CONN_INT);
  GapInit_setPhyParam(DEFAULT_INIT_PHY, INIT_PHYPARAM_CONN_INT_MAX,
                      INIT_PHYPARAM_MAX_CONN_INT);


GapScan_enable(0,100,0);
}

3 放在事件

cc26X2将simple_peripheral_oad_onchip 修改为主从一体_第2张图片

开始广播后启动扫描
cc26X2将simple_peripheral_oad_onchip 修改为主从一体_第3张图片

你可能感兴趣的:(CC26X2)