您当前的位置: 首页 > 

仙剑情缘

暂无认证

  • 0浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

NRF52832 RTC for TICK

仙剑情缘 发布时间:2018-11-01 17:58:52 ,浏览量:0

1.在sdk_config.h中加入宏

// NRF_CLOCK_ENABLED - nrf_drv_clock - CLOCK peripheral driver - legacy layer //========================================================== #ifndef NRF_CLOCK_ENABLED #define NRF_CLOCK_ENABLED 1 #endif // CLOCK_CONFIG_LF_SRC  - LF Clock Source   // RC  // XTAL  // Synth  // External Low Swing  // External Full Swing 

#ifndef CLOCK_CONFIG_LF_SRC #define CLOCK_CONFIG_LF_SRC 1 #endif

// CLOCK_CONFIG_IRQ_PRIORITY  - Interrupt priority  

// Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice // 0 (highest)  // 1  // 2  // 3  // 4  // 5  // 6  // 7 

#ifndef CLOCK_CONFIG_IRQ_PRIORITY #define CLOCK_CONFIG_IRQ_PRIORITY 6 #endif

// RTC_ENABLED - nrf_drv_rtc - RTC peripheral driver - legacy layer //========================================================== #ifndef RTC_ENABLED #define RTC_ENABLED 1 #endif // RTC_DEFAULT_CONFIG_FREQUENCY - Frequency   

#ifndef RTC_DEFAULT_CONFIG_FREQUENCY #define RTC_DEFAULT_CONFIG_FREQUENCY 32768 #endif

// RTC_DEFAULT_CONFIG_RELIABLE  - Ensures safe compare event triggering  

#ifndef RTC_DEFAULT_CONFIG_RELIABLE #define RTC_DEFAULT_CONFIG_RELIABLE 0 #endif

// RTC_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority  

// Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice // 0 (highest)  // 1  // 2  // 3  // 4  // 5  // 6  // 7 

#ifndef RTC_DEFAULT_CONFIG_IRQ_PRIORITY #define RTC_DEFAULT_CONFIG_IRQ_PRIORITY 6 #endif

// RTC0_ENABLED  - Enable RTC0 instance  

#ifndef RTC0_ENABLED #define RTC0_ENABLED 1 #endif

// RTC1_ENABLED  - Enable RTC1 instance  

#ifndef RTC1_ENABLED #define RTC1_ENABLED 0 #endif

// RTC2_ENABLED  - Enable RTC2 instance  

#ifndef RTC2_ENABLED #define RTC2_ENABLED 0 #endif

// NRFX_RTC_ENABLED - nrfx_rtc - RTC peripheral driver //========================================================== #ifndef NRFX_RTC_ENABLED #define NRFX_RTC_ENABLED 1 #endif // NRFX_RTC0_ENABLED  - Enable RTC0 instance  

#ifndef NRFX_RTC0_ENABLED #define NRFX_RTC0_ENABLED 0 #endif

// NRFX_RTC1_ENABLED  - Enable RTC1 instance  

#ifndef NRFX_RTC1_ENABLED #define NRFX_RTC1_ENABLED 0 #endif

// NRFX_RTC2_ENABLED  - Enable RTC2 instance  

#ifndef NRFX_RTC2_ENABLED #define NRFX_RTC2_ENABLED 0 #endif

// NRFX_RTC_MAXIMUM_LATENCY_US - Maximum possible time[us] in highest priority interrupt  #ifndef NRFX_RTC_MAXIMUM_LATENCY_US #define NRFX_RTC_MAXIMUM_LATENCY_US 2000 #endif

// NRFX_RTC_DEFAULT_CONFIG_FREQUENCY - Frequency   

#ifndef NRFX_RTC_DEFAULT_CONFIG_FREQUENCY #define NRFX_RTC_DEFAULT_CONFIG_FREQUENCY 32768 #endif

// NRFX_RTC_DEFAULT_CONFIG_RELIABLE  - Ensures safe compare event triggering  

#ifndef NRFX_RTC_DEFAULT_CONFIG_RELIABLE #define NRFX_RTC_DEFAULT_CONFIG_RELIABLE 0 #endif

// NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority   // 0 (highest)  // 1  // 2  // 3  // 4  // 5  // 6  // 7 

#ifndef NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY #define NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY 6 #endif

// NRFX_RTC_CONFIG_LOG_ENABLED - Enables logging in the module. //========================================================== #ifndef NRFX_RTC_CONFIG_LOG_ENABLED #define NRFX_RTC_CONFIG_LOG_ENABLED 0 #endif // NRFX_RTC_CONFIG_LOG_LEVEL  - Default Severity level   // Off  // Error  // Warning  // Info  // Debug 

#ifndef NRFX_RTC_CONFIG_LOG_LEVEL #define NRFX_RTC_CONFIG_LOG_LEVEL 3 #endif

// NRFX_RTC_CONFIG_INFO_COLOR  - ANSI escape code prefix.   // Default  // Black  // Red  // Green  // Yellow  // Blue  // Magenta  // Cyan  // White 

#ifndef NRFX_RTC_CONFIG_INFO_COLOR #define NRFX_RTC_CONFIG_INFO_COLOR 0 #endif

// NRFX_RTC_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.   // Default  // Black  // Red  // Green  // Yellow  // Blue  // Magenta  // Cyan  // White 

#ifndef NRFX_RTC_CONFIG_DEBUG_COLOR #define NRFX_RTC_CONFIG_DEBUG_COLOR 0 #endif

2.导入文件nrfx_rtc.c,nrfx_clock.c,nrf_drv_clock.c到工程

3.引入头文件

#include "nrf_drv_rtc.h" #include "nrf_drv_clock.h"

4.定义变量 const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(0); /**< Declaring an instance of nrf_drv_rtc for RTC0. */ 5.RTC事件处理函数

/** @brief: Function for handling the RTC0 interrupts.  * Triggered on TICK and COMPARE0 match.  */ static void rtc_handler(nrf_drv_rtc_int_type_t int_type) {        if (int_type == 0)     {             }     else if (int_type == NRF_DRV_RTC_INT_TICK)     {        nrf_gpio_pin_toggle(31);     } }

6.初时化函数

/** @brief Function starting the internal LFCLK XTAL oscillator.  */ static void lfclk_config(void) {     ret_code_t err_code = nrf_drv_clock_init();     APP_ERROR_CHECK(err_code);

    nrf_drv_clock_lfclk_request(NULL); }

/** @brief Function initialization and configuration of RTC driver instance.  */ static void rtc_config(void) {     uint32_t err_code;

    //Initialize RTC instance     nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;     config.prescaler = 4095;     err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler);     APP_ERROR_CHECK(err_code);

//    Enable tick event & interrupt     nrf_drv_rtc_tick_enable(&rtc,true);

    //Power on RTC instance     nrf_drv_rtc_enable(&rtc);      }

7.在主函数中处理

 nrf_gpio_cfg_output(31);

    lfclk_config();

    rtc_config();

 

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

微信扫码登录

0.3099s