void Uart2_init(void)
{ /* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOB);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART2);
/* connect port to USARTx_Tx */
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
/* connect port to USARTx_Rx */
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_11);
usart_deinit(USART2);
usart_baudrate_set(USART2, 9600U);
usart_word_length_set(USART2, USART_WL_8BIT);
usart_stop_bit_set(USART2, USART_STB_1BIT);
usart_parity_config(USART2, USART_PM_NONE);
usart_hardware_flow_rts_config(USART2, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(USART2, USART_CTS_DISABLE);
usart_receive_config(USART2, USART_RECEIVE_ENABLE);
usart_transmit_config(USART2, USART_TRANSMIT_ENABLE);
nvic_irq_enable(USART2_IRQn, 10, 0);
/* configure COM2 */
usart_interrupt_enable(USART2, USART_INT_TBE);
usart_interrupt_enable(USART2, USART_INT_RBNE);
usart_receiver_timeout_enable(USART2);
usart_receiver_timeout_threshold_config(USART2, 10);
// usart_interrupt_enable(USART2, USART_INT_IDLE);
// /* wait until USART send the transmitter_buffer */
// while(txcount < tx_size);
//
// while(RESET == usart_flag_get(USART0, USART_FLAG_TC));
usart_enable(USART2);
} |