21ic问答首页 - GD32E103VB Uart0
GD32E103VB Uart0
TZK1232021-04-27
为什么我用的GD32E103VB 的Uart打印出来是乱码。。。代码如下:#include "gd32e10x.h"
#include "gd32e103v_eval.h"
#include "systick.h"
#include <stdio.h>
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(USART0, (uint8_t)ch);
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
return ch;
}
void uart_init(void)
{
rcu_periph_clock_enable(RCU_AF);
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
//gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* connect port to USARTx_Tx */
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
/* connect port to USARTx_Rx */
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
//gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
/* USART configure */
usart_deinit(USART0);
usart_baudrate_set(USART0, 115200U);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_enable(USART0);
}
int main(void)
{
systick_config();
uart_init();
while(1)
{
printf("hello world\n");
}
}
打印结果如下:
l"l"Xl"H$ ll"l"XlDl"l。。。。。。
#include "gd32e103v_eval.h"
#include "systick.h"
#include <stdio.h>
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(USART0, (uint8_t)ch);
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
return ch;
}
void uart_init(void)
{
rcu_periph_clock_enable(RCU_AF);
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
//gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* connect port to USARTx_Tx */
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
/* connect port to USARTx_Rx */
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
//gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
/* USART configure */
usart_deinit(USART0);
usart_baudrate_set(USART0, 115200U);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_enable(USART0);
}
int main(void)
{
systick_config();
uart_init();
while(1)
{
printf("hello world\n");
}
}
打印结果如下:
l"l"Xl"H$ ll"l"XlDl"l。。。。。。
您需要登录后才可以回复 登录 | 注册