Examples

Nordic 52840-Timer定时器学习问题(一)

今天在ble_app_blinky例程中移植定时器驱动,在编译过程中报出了两个错误,在此记录一下。

 

1. 在nRF_Dreivers中添加nrfx_timer.c文件

选中“nRF_Dreivers ” -> 右键选择“Add Existing Files to Group....” -> 选择nrf_timer.c文件

注:添加完成nrf_timer.c后,发现文件图标上面没有和其他文件图标上面的雪花形状的标记,原因是:

该文件没有被单独设置过option。

方法是:右击该文件打开它的option,随便改个属性然后点确定,它就会被标上雪花。

 

    

 

 

 

2. 参考examples\peripheral\timer timer定时器中的逻辑,调用相关接口。

 

#include "nrf_drv_timer.h"

const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0); ---编译报错

 

int main()

{

uint32_t time_ms = 500;
uint32_t time_ticks;
uint32_t err_code = NRF_SUCCESS;
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
APP_ERROR_CHECK(err_code);

time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);

nrf_drv_timer_extended_compare(
&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

nrf_drv_timer_enable(&TIMER_LED);

}

 

nrfx_timer.c中:

#if !(NRFX_CHECK(NRFX_TIMER0_ENABLED) || NRFX_CHECK(NRFX_TIMER1_ENABLED) || \
NRFX_CHECK(NRFX_TIMER2_ENABLED) || NRFX_CHECK(NRFX_TIMER3_ENABLED) || \
NRFX_CHECK(NRFX_TIMER4_ENABLED))

#error "No enabled TIMER instances. Check <nrfx_config.h>."          ----------编译报错
#endif

 

3. 编译

编译程序,发现两处地方报错,最后发现问题原因:

sdk_config.h中,需要将

#ifndef TIMER0_ENABLED
#define TIMER0_ENABLED 1
#endif

 

#ifndef TIMER_ENABLED
#define TIMER_ENABLED 1 
#endif

 

posted on 2020-04-13 11:25  足各火丁  阅读(1865)  评论(0编辑  收藏  举报

导航

Examples