
串口的配置 //复用口的打开 GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA | \ RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|\ RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO, ENABLE); //始终配置 RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2|RCC_APB1Periph_USART3|\ RCC_APB1Periph_UART4,ENABLE); //USART1 GPIO配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //USART2 GPIO配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //串口的配置 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_Init(USART2, &USART_InitStructure); //中断的配置,注意在中断函数里面清除中断标志 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //ʹÄÜÖÐ¶Ï USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //ʹÄÜÖÐ¶Ï USART_ITConfig(UART4, USART_IT_RXNE, ENABLE); USART_Cmd(USART1, ENABLE); //ʹÄÜÍâÉè USART_Cmd(USART2, ENABLE); //ʹÄÜ |