nrf51822 app timer简单使用

本文介绍了一个简单的nRF51 SDK中的BLE UART示例程序,通过使用APPTIMER模块定时翻转LED的状态来演示基本的BLE UART功能。示例中详细展示了如何配置定时器并设置GPIO引脚来控制LED灯的亮灭。

只关心应用,不关系内部实现机制:



是时候秀一波操作了:

随便找一个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闪烁了



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值