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);

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容