static void USART1_Configuration(void) { // Periph CLK Init RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE); // GPIO Pins for UART1 USART1_GPIO_Configuration(); // NVIC for UART1 USART1_NVIC_Configuration(); // --------------- USART1 configuration --------------- // USART1 configured as follow: 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; // Configure the USART1 USART_Init(USART1, &USART_InitStructure); // Enable the USART Transmoit interrupt: this interrupt is generated when the // USART1 transmit data register is empty // USART_ITConfig(USART1, USART_IT_TXE, ENABLE); // Enable the USART Receive interrupt: this interrupt is generated when the // USART1 receive data register is not empty USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // Enable USART1 USART_Cmd(USART1, ENABLE); }
void USART1_Init(void) { USART1_GPIO_Configuration(); USART1_Configuration(); NVIC_Configuration(); USART_ClearFlag(USART2,USART_FLAG_TC); }
void init_rs232(void) { USART1_RCC_Configuration(); USART1_GPIO_Configuration(); USART1_Configuration(); }