參考BLE5.3 使用1M 2M 500K或者 125Kbps通訊 - debugdabiaoge - 博客園 (cnblogs.com)修改為2M后nrf connet就顯示N/A了,注釋掉那幾行就正常
代碼如下
void?Peripheral_Init()?{ ????Peripheral_TaskID?=?TMOS_ProcessEventRegister(Peripheral_ProcessEvent); ????//?Setup?the?GAP?Peripheral?Role?Profile ????{ ????????uint8_t?initial_advertising_enable?=?FALSE; ????????uint16_t?desired_min_interval?=?6; ????????uint16_t?desired_max_interval?=?1000; ????????//?Set?the?GAP?Role?Parameters ????????GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED,?sizeof(uint8_t),?&initial_advertising_enable); ????????GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA,?sizeof(scanRspData),?scanRspData); ????????GAPRole_SetParameter(GAPROLE_ADVERT_DATA,?sizeof(advertData),?advertData); ????????GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL,?sizeof(uint16_t),?&desired_min_interval); ????????GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL,?sizeof(uint16_t),?&desired_max_interval); ????} //????//?set?to?2M //????uint8_t?adv_type?=?GAP_ADTYPE_EXT_CONN_UNDIRECT; //????GAPRole_SetParameter(GAPROLE_ADV_EVENT_TYPE,?sizeof(uint8_t),?&adv_type); //????GAP_SetParamValue(TGAP_ADV_PRIMARY_PHY,?GAP_PHY_VAL_LE_2M); //????GAP_SetParamValue(TGAP_ADV_SECONDARY_PHY,?GAP_PHY_VAL_LE_2M); ????//?Set?the?GAP?Characteristics ????GGS_SetParameter(GGS_DEVICE_NAME_ATT,?(uint8_t)?tmos_strlen((char?*)?attDeviceName),?(void?*)?attDeviceName); ????//?Set?advertising?interval ????{ ????????uint16_t?advInt?=?DEFAULT_ADVERTISING_INTERVAL; ????????GAP_SetParamValue(TGAP_DISC_ADV_INT_MIN,?advInt); ????????GAP_SetParamValue(TGAP_DISC_ADV_INT_MAX,?advInt); ????} ????//?Setup?the?GAP?Bond?Manager ????{ ????????uint32_t?passkey?=?0;?//?passkey?"000000" ????????uint8_t?pairMode?=?GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; ????????uint8_t?mitm?=?TRUE; ????????uint8_t?bonding?=?TRUE; ????????uint8_t?ioCap?=?GAPBOND_IO_CAP_DISPLAY_ONLY; ????????GAPBondMgr_SetParameter(GAPBOND_PERI_DEFAULT_PASSCODE,?sizeof(uint32_t),?&passkey); ????????GAPBondMgr_SetParameter(GAPBOND_PERI_PAIRING_MODE,?sizeof(uint8_t),?&pairMode); ????????GAPBondMgr_SetParameter(GAPBOND_PERI_MITM_PROTECTION,?sizeof(uint8_t),?&mitm); ????????GAPBondMgr_SetParameter(GAPBOND_PERI_IO_CAPABILITIES,?sizeof(uint8_t),?&ioCap); ????????GAPBondMgr_SetParameter(GAPBOND_PERI_BONDING_ENABLED,?sizeof(uint8_t),?&bonding); ????} ????//?Initialize?GATT?attributes ????GGS_AddService(GATT_ALL_SERVICES);?????????//?GAP ????GATTServApp_AddService(GATT_ALL_SERVICES);?//?GATT?attributes ????ble_uart_add_service(); ????BLE_EntryDFU_AddService(); ????//?Register?with?Link?DB?to?receive?link?status?change?callback ????linkDB_Register(ble_HandleConnStatusCB); ????//?Init?Connection?Item ????peripheralInitConnItem(&peripheralConnList); ????//?Register?receive?scan?request?callback ????GAPRole_BroadcasterSetCB(&Broadcaster_BroadcasterCBs); ????//?Setup?a?delayed?profile?startup ????tmos_set_event(Peripheral_TaskID,?SBP_START_DEVICE_EVT); ????BLE_Processor_Init(); }
廣播數(shù)據(jù)如下
//?GAP?-?SCAN?RSP?data?(max?size?=?31?bytes) static?const?uint8_t?scanRspData[]?=?{ ????????//?complete?name ????????8,?//?length?of?this?data ????????GAP_ADTYPE_LOCAL_NAME_COMPLETE, ????????'1',?'2',?'3',?'4',?'5',?'6',?'7', ????????//?connection?interval?range ????????0x05,?//?length?of?this?data ????????GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE, ????????LO_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL),?//?100ms ????????HI_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL), ????????LO_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL),?//?1s ????????HI_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL), ????????//?Tx?power?level ????????0x02,?//?length?of?this?data ????????GAP_ADTYPE_POWER_LEVEL, ????????0?//?0dBm }; //?GAP?-?Advertisement?data?(max?size?=?31?bytes,?though?this?is //?best?kept?short?to?conserve?power?while?advertisting) static?const?uint8_t?advertData[]?=?{ ????????//?Flags;?this?sets?the?device?to?use?limited?discoverable ????????//?mode?(advertises?for?30?seconds?at?a?time)?instead?of?general ????????//?discoverable?mode?(advertises?indefinitely) ????????0x02,?//?length?of?this?data ????????GAP_ADTYPE_FLAGS, ????????DEFAULT_DISCOVERABLE_MODE?|?GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED, ????????//?service?UUID,?to?notify?central?devices?what?services?are?included ????????//?in?this?peripheral ????????0x05,??????????????????//?length?of?this?data ????????GAP_ADTYPE_16BIT_MORE,?//?some?of?the?UUID's,?but?not?all ????????0x59, ????????0xFE, ????????0x40, ????????0xFF };
熱門產(chǎn)品 :
CH32X035: 32位USB+USB PD單片機(jī)