CH573 CH582 CH592 CH579常用库函数记录

发布时间 2023-11-20 13:40:08作者: WCH蓝牙应用分享

一:系统篇:

软件复位

SYS_ResetExecute(); 

延时函数

mDelaymS(1);     //延时1ms
mDelayuS(1);     //延时1us

设置晶体匹配电容

 

void HSECFG_Capacitance(HSECapTypeDef c);     //外部高频32MHZ
void LSECFG_Capacitance(LSECapTypeDef c); //外部低频32.768KHZ

 

开启DCDC降低功耗

void PWR_DCDCCfg(FunctionalState s);

二:蓝牙篇

获取芯片唯一MAC 

uint8_t MacAddr[6];
GetMACAddress(MacAddr);

查询蓝牙连接状态

extern uint8_t linkDB_State( uint16_t connectionHandle, uint8_t state );

蓝牙交互MTU

extern bStatus_t GATT_ExchangeMTU( uint16_t connHandle, attExchangeMTUReq_t *pReq, uint8_t taskId );

蓝牙主动断开连接(主机和从机都适用)

extern bStatus_t GAPRole_TerminateLink( uint16_t connHandle );

蓝牙从机开关广播

uint8_t advertising_enable = TRUE;
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &advertising_enable);     //开启广播
uint8_t advertising_enable = FALSE;
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &advertising_enable);     //关闭广播

蓝牙从机更新广播内容

extern bStatus_t GAP_UpdateAdvertisingData( uint8_t taskID, uint8_t adType, uint8_t dataLen, uint8_t *pAdvertData );

蓝牙从机更新连接参数

extern bStatus_t GAPRole_PeripheralConnParamUpdateReq( uint16_t connHandle, uint16_t connIntervalMin,
    uint16_t connIntervalMax, uint16_t latency, uint16_t connTimeout, uint8_t taskId );

蓝牙主机开启扫描

extern bStatus_t GAPRole_CentralStartDiscovery( uint8_t mode, uint8_t activeScan, uint8_t whiteList );

蓝牙主机取消扫描

extern bStatus_t GAPRole_CentralCancelDiscovery( void );

蓝牙主机发起连接

extern bStatus_t GAPRole_CentralEstablishLink( uint8_t highDutyCycle, uint8_t whiteList, uint8_t addrTypePeer, uint8_t *peerAddr );

..............