只关心应用,不关系内部实现机制:
是时候秀一波操作了:
随便找一个sdk里面的ble例子,我使用的是sdk9里的ble_app_uart_s110_pca10028例程,工程路径为:XX\nRF51_SDK_9.0.0_2e23562\examples\ble_peripheral\ble_app_uart\pca10028\s110\arm4
代码很简单,只是用app timer来翻转一个led灯,我的板子是18脚连着一个led灯。
app_timer_id_t my_timer;
static void my_timer_handler(void * p_context)
{
nrf_gpio_pin_toggle(18);
}
/**@brief Application main function.
*/
int main(void)
{
uint32_t err_code;
bool erase_bonds;
uint8_t start_string[] = START_STRING;
// Initialize.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
uart_init();
buttons_leds_init(&erase_bonds);
ble_stack_init();
nrf_gpio_pin_dir_set(18, NRF_GPIO_PIN_DIR_OUTPUT);
app_timer_create(&my_timer, APP_TIMER_MODE_REPEATED, my_timer_handler);
app_timer_start(my_timer, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
while(1);
gap_params_init();
services_init();
advertising_init();
conn_params_init();
printf("%s",start_string);
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
// Enter main loop.
for (;;)
{
power_manage();
}
}
编译完下载进去就可以看到led闪烁了