您当前的位置: 首页 > 

仙剑情缘

暂无认证

  • 0浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

NRF52832 WDT

仙剑情缘 发布时间:2018-11-01 16:48:40 ,浏览量:0

1.在sdk_config.h中加入宏

// WDT_ENABLED - nrf_drv_wdt - WDT peripheral driver - legacy layer //========================================================== #ifndef WDT_ENABLED #define WDT_ENABLED 1 #endif // WDT_CONFIG_BEHAVIOUR  - WDT behavior in CPU SLEEP or HALT mode   // Run in SLEEP, Pause in HALT  // Pause in SLEEP, Run in HALT  // Run in SLEEP and HALT  // Pause in SLEEP and HALT 

#ifndef WDT_CONFIG_BEHAVIOUR #define WDT_CONFIG_BEHAVIOUR 1 #endif

// WDT_CONFIG_RELOAD_VALUE - Reload value   

#ifndef WDT_CONFIG_RELOAD_VALUE #define WDT_CONFIG_RELOAD_VALUE 2000 #endif

// WDT_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 WDT_CONFIG_IRQ_PRIORITY #define WDT_CONFIG_IRQ_PRIORITY 6 #endif 2.导入文件nrfx_wdt.c到工程中

3.引入头文件

#include "nrf_drv_wdt.h"

4.定义变量 nrf_drv_wdt_channel_id m_channel_id;

5.WDT事件函数

void wdt_event_handler(void) {    printf("wdt event\n");

    //NOTE: The max amount of time we can spend in WDT interrupt is two cycles of 32768[Hz] clock - after that, reset occurs }

6.在主函数中的处理

int main(void) {     uint32_t err_code;

    bsp_board_init(BSP_INIT_LEDS);

    const app_uart_comm_params_t comm_params =       {           RX_PIN_NUMBER,           TX_PIN_NUMBER,           RTS_PIN_NUMBER,           CTS_PIN_NUMBER,           UART_HWFC,           false, #if defined (UART_PRESENT)           NRF_UART_BAUDRATE_115200 #else           NRF_UARTE_BAUDRATE_115200 #endif       };

    APP_UART_FIFO_INIT(&comm_params,                          UART_RX_BUF_SIZE,                          UART_TX_BUF_SIZE,                          uart_error_handle,                          APP_IRQ_PRIORITY_LOWEST,                          err_code);

    APP_ERROR_CHECK(err_code);     printf("\nreset\n");     //Configure WDT.     nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;     err_code = nrf_drv_wdt_init(&config, wdt_event_handler);     APP_ERROR_CHECK(err_code);     err_code = nrf_drv_wdt_channel_alloc(&m_channel_id);     APP_ERROR_CHECK(err_code);     nrf_drv_wdt_enable();    // 使能WDT          while (true)     {      // nrf_drv_wdt_channel_feed(m_channel_id);  //喂狗操作     }

}

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

微信扫码登录

0.4579s