失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > NRF52832 WDT

NRF52832 WDT

时间:2022-01-13 18:53:58

相关推荐

NRF52832 WDT

1.在sdk_config.h中加入宏

// <e> WDT_ENABLED - nrf_drv_wdt - WDT peripheral driver - legacy layer

//==========================================================

#ifndef WDT_ENABLED

#define WDT_ENABLED 1

#endif

// <o> WDT_CONFIG_BEHAVIOUR - WDT behavior in CPU SLEEP or HALT mode

// <1=> Run in SLEEP, Pause in HALT

// <8=> Pause in SLEEP, Run in HALT

// <9=> Run in SLEEP and HALT

// <0=> Pause in SLEEP and HALT

#ifndef WDT_CONFIG_BEHAVIOUR

#define WDT_CONFIG_BEHAVIOUR 1

#endif

// <o> WDT_CONFIG_RELOAD_VALUE - Reload value <15-4294967295>

#ifndef WDT_CONFIG_RELOAD_VALUE

#define WDT_CONFIG_RELOAD_VALUE 2000

#endif

// <o> WDT_CONFIG_IRQ_PRIORITY - Interrupt priority

// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice

// <0=> 0 (highest)

// <1=> 1

// <2=> 2

// <3=> 3

// <4=> 4

// <5=> 5

// <6=> 6

// <7=> 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); //喂狗操作

}

}

如果觉得《NRF52832 WDT》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。
相关阅读
看门狗(WDT)

看门狗(WDT)

2020-06-19

WDT

WDT

2023-07-21

watchdog/wdt

watchdog/wdt

2024-02-18

15.WDT实验

15.WDT实验

2024-05-02