大家有谁有用GD的芯片开发过串口485通信,涉及512DMX协议的项目(舞台灯光)吗?我用GDE103C8开发的,发现串口接收数据异常,接收的数据不完整,而且全都是错误的数据!而且串口的代码都是按官方的demo写的!广大的万能网友的提供帮助吗。在下非常感谢!
附串口代码
void uart_init(void)
{
rcu_periph_clock_enable(RCU_GPIOC); /* enable GPIO clock */
rcu_periph_clock_enable(RCU_USART0);/* enable USART clock */
gpio_init(GPIOC, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9); /* connect port to USARTx_Tx */
gpio_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);/* connect port to USARTx_Rx */
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12); // T/R control gpio
/* USART configure */
usart_deinit(USART0);
usart_baudrate_set(USART0, 250000U);//512DMX协议波特率是250k
usart_parity_config(USART0,USART_PM_NONE); //configure USART parity: no parity
usart_word_length_set(USART0,USART_WL_8BIT); //USART_WL_8BIT/USART_WL_9BIT
usart_stop_bit_set(USART0,USART_STB_2BIT);//configure USART stop bit length
usart_receive_config(USART0, USART_RECEIVE_ENABLE); // receive enable
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); // transmit enable
/* USART interrupt configuration */
nvic_irq_enable(USART0_IRQn, 0, 0);
usart_interrupt_enable(USART0, USART_INT_RBNE);/* enable USART0 receive interrupt */
usart_interrupt_enable(USART0, USART_INT_ERR); //USART_INT_ERR: error interrupt
//uart enable
usart_enable(USART0);
gpio_bit_reset(GPIOC,GPIO_PIN_12); //0= receive T/R
}
//串口中断只做接收数据处理,仿真检验数据是否接收正常
uint8_t rx_buffer[512];
uint8_t rx_counter = 0;
void USART0_IRQHandler(void)
{
if(SET == usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE))
{
usart_interrupt_flag_clear(USART0, USART_INT_FLAG_RBNE);
rx_buffer[rx_counter++] = (uint8_t)usart_data_receive(USART0);
}
} |