3595 views |0 replies
Last login 2023-4-18
Online Time 282 hours
Prestige 75 points
Points 44 points
[GD32F350 Development Sharing 6] Dual Serial Port Application of USART0 and USART1
[Copy link]
As shown in the figure, GD32F350 has two serial ports, USART0 and USART1. You can refer to the manual for details on which pins are multiplexed into the serial ports. My GPIO multiplexing configuration is as follows
The serial port initialization function isvoid gd_eval_com_init(uint32_t com) { uint32_t COM_ID; if(EVAL_COM1 == com){ COM_ID = 0U; }else{ COM_ID = 1U; } /* enable COM GPIO clock */ rcu_periph_clock_enable(EVAL_COM_GPIO_CLK); /* enable USART clock */ rcu_periph_clock_enable(COM_CLK[COM_ID]); /* connect port to USARTx_Tx */ gpio_af_set(EVAL_COM_GPIO_PORT, EVAL_COM_AF, COM_TX_PIN[COM_ID]); /* connect port to USARTx_Rx */ gpio_af_set(EVAL_COM_GPIO_PORT, EVAL_COM_AF, COM_RX_PIN[COM_ID]); /* configure USART Tx as alternate function push-pull */ gpio_mode_set(EVAL_COM_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, COM_TX_PIN[COM_ID]); gpio_output_options_set(EVAL_COM_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, COM_TX_PIN[COM_ID]); /* configure USART Rx as alternate function push-pull */ gpio_mode_set(EVAL_COM_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, COM_RX_PIN[COM_ID]); gpio_output_options_set(EVAL_COM_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, COM_RX_PIN[COM_ID]); /* USART configure */ usart_deinit(com); usart_baudrate_set(com, 115200U); usart_receive_config(com, USART_RECEIVE_ENABLE); usart_transmit_config(com, USART_TRANSMIT_ENABLE); usart_enable(com); } 复制代码 Serial port sending function, serial port 0 as an example [code]void USART_SendBuffer(uint8_t *buf, uint16_t Size) { uint16_t len=0; for (len=0;len
[GD32F350 Development Sharing 6] Dual Serial Port Application of USART0 and USART1