You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9 KiB
C

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "SWM221.h"
void SerialInit(void);
int main(void)
{
uint32_t i;
SystemInit();
SerialInit();
if(SYS->RSTSR & SYS_RSTSR_WDT_Msk)
{
SYS->RSTSR = (1 << SYS_RSTSR_WDT_Pos);
printf("WDT Reset Happened\r\n");
}
WDT_Init(WDT, 0, 1000);
WDT_Start(WDT);
while(1==1)
{
WDT_Feed(WDT); //注释掉喂狗操作观察WDT复位现象
/* 注意:
* 1、两次喂狗之间至少间隔 5 个 WDT 时钟周期,即 1000000 / 32768 * 5 = 150us又考虑到 WDT 时钟误差很大,建议间隔不小于 300us
* 2、WDT 停止状态下,不要执行 WDT_Feed()
* 3、执行 WDT_Feed() 后,不能立即执行 WDT_Stop(),必须间隔 5 个 WDT 时钟周期再执行 WDT_Stop()
*/
for(i = 0; i < CyclesPerUs * 300 / 4; i++) __NOP();
}
}
void SerialInit(void)
{
UART_InitStructure UART_initStruct;
PORT_Init(PORTA, PIN0, PORTA_PIN0_UART0_RX, 1); //GPIOA.0配置为UART0 RXD
PORT_Init(PORTA, PIN1, PORTA_PIN1_UART0_TX, 0); //GPIOA.1配置为UART0 TXD
UART_initStruct.Baudrate = 57600;
UART_initStruct.DataBits = UART_DATA_8BIT;
UART_initStruct.Parity = UART_PARITY_NONE;
UART_initStruct.StopBits = UART_STOP_1BIT;
UART_initStruct.RXThreshold = 3;
UART_initStruct.RXThresholdIEn = 0;
UART_initStruct.TXThreshold = 3;
UART_initStruct.TXThresholdIEn = 0;
UART_initStruct.TimeoutTime = 10;
UART_initStruct.TimeoutIEn = 0;
UART_Init(UART0, &UART_initStruct);
UART_Open(UART0);
}
/******************************************************************************************************************************************
* 函数名称: fputc()
* 功能说明: printf()使用此函数完成实际的串口打印动作
* 输 入: int ch 要打印的字符
* FILE *f 文件句柄
* 输 出: 无
* 注意事项: 无
******************************************************************************************************************************************/
int fputc(int ch, FILE *f)
{
UART_WriteByte(UART0, ch);
while(UART_IsTXBusy(UART0));
return ch;
}