您当前的位置: 首页 > 

仙剑情缘

暂无认证

  • 3浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

NRF52832定时器

仙剑情缘 发布时间:2018-10-20 20:14:36 ,浏览量:3

以SDK14.0.0为例 ,TIMER0的定时器使用

1.加入文件nrf_drv_timer.c

2.sdk_config.h中的宏打开

#ifndef TIMER_ENABLED #define TIMER_ENABLED 1 #endif

#ifndef TIMER0_ENABLED #define TIMER0_ENABLED 1 #endif

3.定义一个TIMER实例 

const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);

4.定义一个timer事件处理函数 /**  * @brief Handler for timer events.  */ void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context) {                     nrf_gpio_pin_toggle(31);           }

5.初时化timer

int main(void) {     uint32_t time_ms = 244; //Time(in miliseconds) between consecutive compare events.     volatile uint32_t time_ticks;     uint32_t err_code = NRF_SUCCESS;

    //Configure all leds on board.     nrf_gpio_cfg_output(31);   //p0_31 配置成输出模式       //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.     nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;     timer_cfg.frequency = 4;  // 修改分频,频率变成1MHZ     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); //调用此方法,转换成TICK数,如果不调用,则可以实现

                                                                                                            //微秒级定时器

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

    nrf_drv_timer_enable(&TIMER_LED);

       while (1)     {         __WFI();     } }

 

代码下载地址:https://download.csdn.net/download/mygod2008ok/10734229

 

 

 

 

 

 

 

关注
打赏
1658017818
查看更多评论
立即登录/注册

微信扫码登录

0.0388s