- void UART_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- /* Enable USART3 clock */
- RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3, ENABLE);
- // GPIO Settings for USART3
- // PB10: TXD_ROOM
- GPIO_StructInit(&GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- // PB11: RXD_ROOM
- GPIO_StructInit(&GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* USARTx configuration ------------------------------------------------------*/
- /* USARTx configured as follow:
- - BaudRate = 600 baud
- - Word Length = 8 Bits
- - Two Stop Bit
- - Even parity
- - Hardware flow control disabled (RTS and CTS signals)
- - Receive and transmit enabled
- */
- USART_DeInit(USART3);
- USART_InitStructure.USART_BaudRate =9600;
- USART_InitStructure.USART_WordLength = USART_WordLength_9b;
- USART_InitStructure.USART_StopBits = USART_StopBits_2;
- USART_InitStructure.USART_Parity = USART_Parity_Even;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- USART_Init(USART3, &USART_InitStructure);
- UartRxON();
- // In initial state, waiting for indoor data...
- USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
- USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
- UART_State=UART_RX; //0; // 0: received state 1: transmit state
- /* Enable the USART3 Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Enable USART3 */
- USART_Cmd(USART3, ENABLE);
- }
|