STM32接收特定字符串,滤除回车符,直接得到所需字符串
分配USART2用于实现此功能
接收直接中断实现
USART配置
/******************************串口函数******************************/
void USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//第1步:打开GPIO和USART部件的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); //打开GPIOA时钟 允许复用
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //打开USART1时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //打开USART2时钟
// 第2步:将USART Tx的GPIO配置为推挽复用模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_9; //Pin_2 - USART2_TX Pin_9 - USART1_TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// 第3步:将USART Rx的GPIO配置为浮空输入模式
// 由于CPU复位后,GPIO缺省都是浮空输入模式,因此下面这个步骤不是必须的
// 但是,我还是建议加上便于阅读,并且防止其它地方修改了这个口线的设置参数
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_10; //Pin_3 - USART2_RX Pin_10 - USART1_RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;