本帖最后由 jiangwanbo 于 2024-11-23 12:53 编辑
使用GD32F103VET6替代STM32F103VET6时,发现GD32F103VET6的usart2 uart3 uart4 工作不正常。
void Uart3_Init(void)
{
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOC);
/* enable USART clock */
rcu_periph_clock_enable(RCU_UART3);
/* connect port to USARTx_Tx */
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
/* connect port to USARTx_Rx */
gpio_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_11);
usart_deinit(UART3);
usart_baudrate_set(UART3, 115200U);
usart_word_length_set(UART3, USART_WL_8BIT);
usart_stop_bit_set(UART3, USART_STB_1BIT);
usart_parity_config(UART3, USART_PM_NONE);
usart_hardware_flow_rts_config(UART3, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(UART3, USART_CTS_DISABLE);
usart_receive_config(UART3, USART_RECEIVE_ENABLE);
usart_transmit_config(UART3, USART_TRANSMIT_ENABLE);
usart_enable(UART3);
}
{
//usart_data_transmit(UART3, 0X5A);
//usart_flag_clear(UART3, USART_FLAG_TBE);
//usart_flag_clear(UART3, USART_FLAG_TC);
usart_data_transmit(UART3, (uint8_t)0X5A);
//(*(volatile uint32_t *)0x40004c04) = 0x01;
while(RESET == usart_flag_get(UART3, USART_FLAG_TBE));
//usart_flag_clear(USART1, USART_FLAG_TBE);
//usart_flag_clear(USART0, USART_FLAG_TC);
usart_data_transmit(USART0, 0X5A);
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
在这里usart0 可以正常输出,uart3就不可以。uart3使用usart_data_transmit(UART3, (uint8_t)0X5A)发送数据时,TBE不清空,data无变化。 我测试了USART2和uart5,同样现象。 |