实现:广播态,LED灯亮,链接态LED灭
硬件:沁恒微CH583评估版
开发环境:MounRiver Studio Version: v1.84
烧写软件:WCHISPTool
安卓BLE调试软件:BLEAssist
...........................................................................................................................................................
以沁恒微提供的IDE,CH583EVT例程:
打开CH583EVT\EVT\EXAM\BLE\Peripheral下Peripheral.wvproj工程
在peripheral_main.c 添加:
int main(void) {
#if(defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
PWR_DCDCCfg(ENABLE);
#endif
SetSysClock(CLK_SOURCE_PLL_60MHz);
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
// GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
#endif
#if
GPIOB_ModeCfg(GPIO_Pin_7, GPIO_ModeOut_PP_5mA);
GPIOB_ResetBits(GPIO_Pin_7);
#endif
.................................................
在peripheral.c 添加:
*********************************************************************
* @fn peripheralStateNotificationCB
*
* @brief Notification from the profile of a state change.
*
* @param newState - new state
*
* @return none
*/
static void peripheralStateNotificationCB(gapRole_States_t newState,
gapRoleEvent_t *pEvent) {
switch (newState & GAPROLE_STATE_ADV_MASK) {
case GAPROLE_STARTED:
PRINT("Initialized..\n");
break;
case GAPROLE_ADVERTISING:
if (pEvent->gap.opcode == GAP_LINK_TERMINATED_EVENT) {
Peripheral_LinkTerminated(pEvent);
PRINT("Disconnected.. Reason:%x\n", pEvent->linkTerminate.reason);
PRINT("Advertising..\n");
} else if (pEvent->gap.opcode == GAP_MAKE_DISCOVERABLE_DONE_EVENT) {
PRINT("Advertising..\n");
GPIOB_ResetBits(GPIO_Pin_7);
}
break;
case GAPROLE_CONNECTED:
if (pEvent->gap.opcode == GAP_LINK_ESTABLISHED_EVENT) {
Peripheral_LinkEstablished(pEvent);
PRINT("Connected..\n");
GPIOB_SetBits(GPIO_Pin_7);
}
break;
.....................................................
编译程序.
沁恒微CH583评估版用杜邦线,LED1或LED2链接至PB7.
用type-C链接开发板至电脑,按下开发板DOWNLOAD,拨动开关 S1,开发板识别为USB下载接口.
点下载程序.
按 开发板RESET :复位按键.
打开安卓手机端APP:BLE调试助手,
BLEAssist.ZIP - 南京沁恒微电子股份有限公司 (wch.cn)
链接名称为"Simple Peripheral"BLE设备,点击右上角的连接和断开连接,可看到PB7链接的LED亮灭变化.