21ic问答首页 - GD32F103 串口0 remap 问题
GD32F103 串口0 remap 问题
liboguang2022-05-16
我使用PB6、PB7作为串口0。第一版调试时,程序收发都正常。第二次生产串口出现只能发,不能收。个别的板子可以接收。是芯片的问题吗?感觉这个芯片不稳定呢rcu_periph_clock_enable(RCU_USART0);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_AF);
gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
/* connect port to USARTx_Rx */
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
/* connect port to USARTx_Tx */
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
/* USART0 baudrate configuration */
usart_baudrate_set(USART0, 115200);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_enable(USART0);
//usart_interrupt_enable(USART0, USART_INT_IDLE);//线路空闲
//usart_interrupt_enable(USART0, USART_INT_TBE); /* enable USART TBE interrupt */
usart_interrupt_enable(USART0, USART_INT_RBNE);
/* USART interrupt configuration */
nvic_irq_enable(USART0_IRQn, 0, 2);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_AF);
gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
/* connect port to USARTx_Rx */
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
/* connect port to USARTx_Tx */
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
/* USART0 baudrate configuration */
usart_baudrate_set(USART0, 115200);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_enable(USART0);
//usart_interrupt_enable(USART0, USART_INT_IDLE);//线路空闲
//usart_interrupt_enable(USART0, USART_INT_TBE); /* enable USART TBE interrupt */
usart_interrupt_enable(USART0, USART_INT_RBNE);
/* USART interrupt configuration */
nvic_irq_enable(USART0_IRQn, 0, 2);
您需要登录后才可以回复 登录 | 注册