我用的是GD32F405RGT6单片机,串口初始化后,单片机能接收数据,但发送不出去,请问有那位大神可以为在下解惑?
int USART1_put_char(int ch)
{
usart_data_transmit(USART1, (unsigned char)ch );
while ( usart_flag_get(USART1, USART_FLAG_TBE) == RESET) {}
return ch;
}
void EvbUart1Config(void)
{
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_USART1);
/* connect port to USART1_Tx */
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_2);
/* connect port to USARTx_R1 */
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_3);
/* configure USART1 Tx as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP,GPIO_PIN_2);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_2);
/* configure USART2 Rx as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP,GPIO_PIN_3);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_3);
/* USART2 configure */
usart_deinit(USART1);
usart_baudrate_set(USART1,115200);
usart_receive_config(USART1, USART_RECEIVE_ENABLE);
usart_transmit_config(USART1, USART_TRANSMIT_ENABLE);
usart_enable(USART1);
}
void uart_init()
{
usart_deinit(USART1);
usart_baudrate_set(USART1,115200);
usart_parity_config(USART1, USART_PM_NONE);
usart_word_length_set(USART1, USART_WL_8BIT);
usart_stop_bit_set(USART1, USART_STB_1BIT);
usart_receive_config(USART1, USART_RECEIVE_ENABLE);
usart_transmit_config(USART1, USART_TRANSMIT_ENABLE);
usart_interrupt_enable(USART1, USART_INT_RBNE);
nvic_irq_enable(USART1_IRQn, 0, 2);
usart_enable(USART1);
}
unsigned char tmp = 0;
void USART1_IRQHandler()
{
tmp = usart_data_receive(USART1);
//uart1_write_ch(tmp);
}
|