nRF52832 Timer

nrf52832 SDK中的timer使用还是很简单的,这里也没有深入.
timer在app_timer.h中
SDK中的说明:

Usage

Configuration of the app_timer module is static. It is located in the sdk_config.h file. Use function app_timer_init to initialize the library.

To define a timer, use the APP_TIMER_DEF macro. This macro allocates memory for the timer instance and declares an identifier that can later on be used to refer to the specific instance. Before starting a timer, the timer must be created:
APP_TIMER_DEF(my_timer_id);

err_code = app_timer_create(&my_timer_id, mode, timeout_handler)

After the timer is created, it can be controlled using app_timer_start and app_timer_stop.

When app_timer_start() or app_timer_stop() are called, the timer operation is only queued, not executed. A software interrupt is triggered and the actual timer start/stop operation is executed by the SWI0 interrupt handler. If the application code that calls the timer function is running at the same or higher interrupt priority level, the timer operation will not be performed until the application handler has returned. This is the case, for example, when stopping a timer from a time-out handler when not using the scheduler.

所以使用倒是很简单了:
初始化定时器:ret_code_t err_code = app_timer_init();
定义:APP_TIMER_DEF(timer_name);
创建:err_code=app_timer_create(&timer_name,APP_TIMER_MODE_SINGLE_SHOT,user_timer_out);
启动:err_code=app_timer_start(timer_name,APP_TIMER_TICKS(300),NULL);
停止:err_code=app_timer_stop(timer_name);

你可能感兴趣的:(nRF52832 Timer)