#include "stm32f10x.h" #include #include void Usart2_Init(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); USART_DeInit(USART2); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitTypeDef USART_InitStruture; USART_InitStruture.USART_BaudRate = 115200; USART_InitStruture.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStruture.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStruture.USART_Parity = USART_Parity_No; USART_InitStruture.USART_StopBits = USART_StopBits_1; USART_InitStruture.USART_WordLength = USART_WordLength_8b; USART_Init(USART2, &USART_InitStruture); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_Init(&NVIC_InitStructure); USART_Cmd(USART2, ENABLE); }