完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
main.c
/*********************************************************** FileName: 看门狗实验** Description: 使用外部中断进入一个死循环,从而触发开门狗模式,打印对应消息 ** Author: ********************************************************* /#include “stm32f10x.h” //STM32头文件#include “stm32f10x_wwdg.h”#include “stdio.h”#include “sys.h”void RCC_Configuration(void);void NVIC_Configuration(void);void GPIO_Configuration(void);void USART_Configuration(void);void EXTI_Configuration(void);void WWDG_Configuration(void);int main (void){//主程序 RCC_Configuration(); //时钟设置 NVIC_Configuration(); GPIO_Configuration(); USART_Configuration(); EXTI_Configuration(); if(RCC_GetFlagStatus(RCC_FLAG_WWDGRST)!=RESET) { printf(“rnThe STM32 has been reset by WWDG rn”); RCC_ClearFlag(); } else { WWDG_Configuration(); printf(“rnThe STM32 has been reset by WWDG before rn”); } while(1);}void GPIO_Configuration(void){ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);//设置PA0脚为外部中断0输入通道 //TX端设置为推挽输出 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; GPIO_Init(GPIOA,&GPIO_InitStructure); //RX端设置为浮空输入脚 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA,&GPIO_InitStructure);}void NVIC_Configuration(void){ //嵌套中断向量控制器的设置 NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级 //0通道,0级先占,0级次占 NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); //窗口开门狗,1级先占优先级 NVIC_InitStructure.NVIC_IRQChannel=WWDG_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_Init(&NVIC_InitStructure); }void EXTI_Configuration(void){ //设置中断通道沿下降沿触发 EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitStructure.EXTI_Line=EXTI_Line0; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);//设置PA0脚为外部中断0输入通道}void WWDG_Configuration(void){ WWDG_SetPrescaler(WWDG_Prescaler_8); WWDG_Enable(0x7f); WWDG_ClearFlag(); WWDG_EnableIT();}void USART_Configuration(void){ USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate=115200; USART_InitStructure.USART_WordLength=USART_WordLength_8b; USART_InitStructure.USART_StopBits=USART_StopBits_1; USART_InitStructure.USART_Parity=USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; USART_Init(USART1,&USART_InitStructure); USART_Cmd(USART1,ENABLE);}//将printf函数定位到usatr1int fputc(int ch,FILE *f){ USART_SendData(USART1,(u8)ch); while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET); return ch;} stm32f10x_it.c #include “stm32f10x_it.h”#include “stm32f10x_wwdg.h”#include “stdio.h”void WWDG_IRQHandler(void){ WWDG_SetCounter(0x7f); WWDG_ClearFlag(); printf(“rn The Windows Watch DoG has been flash rn”);}void EXTI0_IRQHandler(void){ while(1);} 实验数据 |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1886 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1663 浏览 1 评论
1152 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
763 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1720 浏览 2 评论
1966浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
795浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
616浏览 3评论
631浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
594浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-15 11:48 , Processed in 0.893677 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (威廉希尔官方网站 图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号