初始化GD32W51芯片的串口1,重映射到PC1和PC0以及初始化这两个GPIO引脚,发送字符0xFF
时间: 2024-05-04 18:15:26 浏览: 176
我可以回答这个问题。初始化GD32W51芯片的串口1,重映射到PC1和PC0以及初始化这两个GPIO引脚,可以使用以下代码:
```
#include "gd32f4xx.h"
void init_uart1(void)
{
/* enable the peripherals clock */
rcu_periph_clock_enable(RCU_USART1);
rcu_periph_clock_enable(RCU_GPIOC);
/* configure USART1 Tx as alternate function push-pull */
gpio_init(GPIOC, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
/* configure USART1 Rx as alternate function push-pull */
gpio_init(GPIOC, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
/* USART1 configuration */
usart_deinit(USART1);
usart_baudrate_set(USART1, 115200U);
usart_word_length_set(USART1, USART_WL_8BIT);
usart_stop_bit_set(USART1, USART_STB_1BIT);
usart_parity_config(USART1, USART_PM_NONE);
usart_hardware_flow_rts_config(USART1, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(USART1, USART_CTS_DISABLE);
usart_receive_config(USART1, USART_RECEIVE_ENABLE);
usart_transmit_config(USART1, USART_TRANSMIT_ENABLE);
usart_enable(USART1);
}
void init_gpio(void)
{
/* enable the peripherals clock */
rcu_periph_clock_enable(RCU_GPIOC);
/* configure PC0 and PC1 as output */
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
}
int main(void)
{
init_uart1();
init_gpio();
/* send 0xFF */
usart_data_transmit(USART1, 0xFF);
while (1);
return 0;
}
```
阅读全文