欢迎来到天天文库
浏览记录
ID:16001863
大小:27.00 KB
页数:3页
时间:2018-08-07
《stm32快速学习5——串口中断接收》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、串口自发自收设定串口时钟设定引脚功能中断优先级设定串口 Main文件#include "stm32f10x.h"void RCC_Configuration(void);void GPIO_Configuration(void);void USART_Configuration(void);void NVIC_Configuration(void);int main(void){ RCC_Configuration(); GPIO_Configuration(); NVIC_Configuration(); USART_Configuration();
2、 while(1);}void RCC_Configuration(void){ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);}void GPIO_Configuration(void){ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPI
3、OA, &GPIO_InitStructure); 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);}void USART_Configuration(void){ USART_InitTypeDef USART_InitStructure;
4、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_HardwareFlowCo
5、ntrol_None; USART_InitStructure.USART_Mode = USART_Mode_Tx
6、 USART_Mode_Rx; USART_Init(USART1 , &USART_InitStructure); USART_Cmd(USART1, ENABLE); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); /*接收中断使能*/}void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC
7、_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; /*3.4的库不是使用USART1_IRQChannel,看stm32f10x.h吧*/ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }Stm3
8、2f10x_it.c加入void USART1_IRQHandler(void) { unsigned int i; if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET) { i = USART_ReceiveData(USART1); USART_SendData(USART1,i); while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) ;
9、
此文档下载收益归作者所有