依旧是官方给的例程恩……
int main(void)
{
uint32_t err_code;
timers_init();
gpiote_init();
buttons_init();
ble_stack_init();
device_manager_init();
// Initialize Bluetooth Stack parameters.
gap_params_init();//初始化gap层连接
advertising_init();
services_init();
conn_params_init();
// Start advertising.
advertising_start();//启动定时器,battery每2S发送一次数据,heart rate每1S发送一次数据
// Enter main loop.
for (;;)
{
// Switch to a low power state until an event is available for the application
err_code = sd_app_evt_wait();
APP_ERROR_CHECK(err_code);
}
}
先初始化,初始化了定时器,GPIO TASK&EVENT,按钮(pin16和pin17)BLE stack,device manager,gap层连接,广播,services,和conn params(相关参数)
为啥battery每2s发送一次数据,heart rate每1s发送一次数据-。-在后面有解释
来看看初始化BLE stack的函数
static void ble_stack_init(void)
{
uint32_t err_code;
// Initialize the SoftDevice handler module.
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);
// Enable BLE stack
ble_enable_params_t ble_enable_params;
memset(&ble_enable_params, 0, sizeof(ble_enable_params));
ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
err_code = sd_ble_enable(&ble_enable_params);
APP_ERROR_CHECK(err_code);
// Register with the SoftDevice handler module for BLE events.
err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);//若event发生,进入ble_evt_dispatch
APP_ERROR_CHECK(err_code);
// Register with the SoftDevice handler module for BLE system events.
err_code = softdevice_sys_evt_handl