2.0库和3.0库不能通用互换不说,还没说明文档,且是一库难求,而且库中的例程是漏洞百出,
在GD的GD32F1x0_Firmware_Library_V3.0.0库中有一个Receivertimeout串口接收超时的例程,看看里面的程序是如何写的
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
uint32_t i=0, j=0;
nvic_config();
gd_eval_COMinit(EVAL_COM1);
printf("a usart receive timeout test example!");
while (1){
if(0 == rxcount){
/* enable the USART receive interrupt */
usart_interrupt_enable( EVAL_COM1, USART_INT_RBNEIE);
}else{
/* enable the USART receive timeout and configure the time of timeout */
usart_receiver_timeout_enable(EVAL_COM1);
usart_receiver_timeout_config(EVAL_COM1, 115200*3);
while(RESET == usart_flag_get(EVAL_COM1, USART_STAT_RTF));
for(i=0; i<rxcount; i++){
txbuffer=rxbuffer[j++];
}
/* disable the USART receive interrupt and enable the USART transmit interrupt */
usart_interrupt_disable(EVAL_COM1 , USART_INT_RBNEIE);
usart_interrupt_enable(EVAL_COM1, USART_INT_TBEIE);
while(txcount < rxcount);
usart_flag_clear(EVAL_COM1, USART_STAT_RTF);
txcount=0;
rxcount=0;
i=0;
j=0;
}
}
}
在看看gd32f1x0_usart.c中对于串口中断的定义
/*!
\brief enable usart interrupt
\param[in] usart_periph: USARTx(x=0)
\param[in] inttype: interrupt type
\arg USART_INT_IDLEIE: idle interrupt
\arg USART_INT_RBNEIE: read data buffer not empty interrupt and
overrun error interrupt enable interrupt
\arg USART_INT_TCIE: transmission complete interrupt
\arg USART_INT_TBEIE: transmit data register empty interrupt
\arg USART_INT_PERRIE: parity error interrupt
\arg USART_INT_AMIE: address match interrupt
\arg USART_INT_RTIE: receiver timeout interrupt
\arg USART_INT_EBIE: end of block interrupt
\arg USART_INT_LBDIE: LIN break detection interrupt
\arg USART_INT_ERRIE: error interrupt enable in multibuffer communication
\arg USART_INT_CTSIE: CTS interrupt
\arg USART_INT_WUIE: wakeup from Deep-sleep mode interrupt
\param[out] none
\retval none
*/
GD让我爱你不容易啊
|