/ ************************************************* ****************************** * Function name: USART1_Init * Function function: USART1 initialization function * Input: bound: Baud rate * Output: None ************************************************ ********************************* / void USART1_Init (u32 bound) { // GPIO port setting GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE); // Enable GPIOA clock RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1, ENABLE); / GPIO_PinAFConfig (GPIOA, GPIO_PinSource9, GPIO_AF_USART1); // GPIOA9 is multiplexed as USART1 GPIO_PinAFConfig (GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // GPIOA10 is multiplexed as USART1 // USART1 port configuration GPIO_InitStructure9GPIO_GP_IO_GP_IO_GP_IO GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Multiplexing function GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Speed 50MHz GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // Push-pull multiplexing output GPIO_InitStructure.GPIO_PuPd = GPIO_Pu = dp_upp = GPIO_Init (GPIOA, & GPIO_InitStructure); // initialize PA9, PA10 // the USART1 Initialize settings USART_InitStructure.USART_BaudRate = bound; // Baud rate setting USART_InitStructure.USART_WordLength = USART_WordLength_8b; // Word length is 8-bit data format USART_InitStructure.USART_StopBits = USART_StopBits_1; // One stop bit USART_InitParity. Bit USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // No hardware data flow control USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; // Transmit and receive mode USART_Init (USART1, & USART_InitStructure); // Enable serial port 1 USART_USART_1 1 USART_ClearFlag (USART1, USART_FLAG_TC); USART_ITConfig (USART1, USART_IT_RXNE, ENABLE); // Turn on related interrupts // Usart1 NVIC configuration NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; // Serial port 1 interrupt channel priority NVIC_InitStructure3Preemption3VPreemption3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; // Subpriority 3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // IRQ channel enable NVIC_Init (& NVIC_InitStructure); // Initialize the VIC register according to the specified parameters, }