完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/*********************************************************
** FileName: 中断实验 ** Description: 实验中断触发,用串口通信进行检测。 ** Author: 老猫 ** Date: 2019/10/7 ** Others: *********************************************************/ #include "stm32f10x.h" //STM32头文件 #include "sys.h" #include "stdio.h" #include "delay.h" void RCC_Configuration(void); void NVIC_Configuration(void); void GPIO_Configuration(void); void USART_Configuration(void); void EXIT_Configuration(void); int main (void){//主程序 RCC_Configuration(); //时钟设置 NVIC_Configuration(); GPIO_Configuration(); USART_Configuration(); EXIT_Configuration(); while(1); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);//设置PA0脚为外部中断0输入通道 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource1);//设置PA1脚为外部中断0输入通道 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource2);//设置PA2脚为外部中断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通道,2级先占优先级,0级次占优先级 NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); //1通道,1级先占,0级次占 NVIC_InitStructure.NVIC_IRQChannel=EXTI1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); //2通道,0级先占,0级次占 NVIC_InitStructure.NVIC_IRQChannel=EXTI2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); } void EXIT_Configuration(void) { //设置中断通道沿下降沿触发 EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitStructure.EXTI_Line=EXTI_Line0|EXTI_Line1|EXTI_Line2; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); } 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函数定位到usatr1 int fputc(int ch,FILE *f) { USART_SendData(USART1,(u8)ch); while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET); return ch; } #include "stm32f10x_it.h" #include "stdio.h" //外部中断0中断服务函数 void EXTI0_IRQHandler(void) { printf("rnEXIT0 enter.rn"); EXTI_GenerateSWInterrupt(EXTI_Line1); printf("rnEXIT0 return.rn"); EXTI_ClearFlag(EXTI_Line0); } //外部中断1中断服务函数 void EXTI1_IRQHandler(void) { printf("rnEXIT1 enter.rn"); EXTI_GenerateSWInterrupt(EXTI_Line2); printf("rnEXIT1 return.rn"); EXTI_ClearFlag(EXTI_Line1); } //外部中断2中断服务函数 void EXTI2_IRQHandler(void) { printf("rnEXIT2 enter.rn"); printf("rnEXIT2 return.rn"); EXTI_ClearFlag(EXTI_Line2); } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1752 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1611 浏览 1 评论
1052 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
721 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1666 浏览 2 评论
1926浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
711浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
560浏览 3评论
584浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
544浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 02:00 , Processed in 0.735776 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号