另问:M051的UART中断处理函数如下:
void UART_INT_HANDLE(uint32_t u32IntStatus)
{
uint8_t bInChar[1]={0xFF};
if(u32IntStatus & DRVUART_RDAINT)
{
printf("\r\nInput:");
/* Get all the input characters */
while(UART0->ISR.RDA_IF==1)
{
/* Get the character from UART Buffer */
DrvUART_Read(UART_PORT0,bInChar,1);
printf("%c ", bInChar[0]);
if(bInChar[0] == '0')
{
g_bWait = FALSE;
}
/* Check if buffer full */
if(comRbytes < RXBUFSIZE)
{
/* Enqueue the character */
comRbuf[comRtail] = bInChar[0];
comRtail = (comRtail == (RXBUFSIZE-1)) ? 0 : (comRtail+1);
comRbytes++;
}
}
printf("\r\nTransmission Test:");
} else if(u32IntStatus & DRVUART_THREINT)
{
uint16_t tmp;
tmp = comRtail;
if(comRhead != tmp)
{
bInChar[0] = comRbuf[comRhead];
DrvUART_Write(UART_PORT0,bInChar,1);
comRhead = (comRhead == (RXBUFSIZE-1)) ? 0 : (comRhead+1);
comRbytes--;
}
}
}
那为什么我接收时会出现如下现象:
+-----------------------------------------------------------+
| UART Sample Program |
+-----------------------------------------------------------+
| UART function test - [1] |
| IrDA funtion test - [2] |
| RS485 Receive funtion test - [3] |
| RS485 Transmit funtion test - [4] |
+-----------------------------------------------------------+
| Quit - [ESC] |
+-----------------------------------------------------------+
Please Select key (1~4): 1
UART Sample Demo. (Press '0' to exit)
Input:u
Transmission Test:
Input:t r t i n t e r r u p t t e
Transmission Test:utrt interrupt te
请注意红色这体部分,接收程序和实际接收的数据不符?
我通过PC发送的数据为uart interrupt test,之所以会少了,这个在前面已经说到过,这里要讨论的是为什么会输出两次的input,两次的transmission test。按我的理解应该只出现一次。
感觉上是 while(UART0->ISR.RDA_IF==1) 这条语句在做第二次判断的时候不成立,所以才会退出while循环。请问这是为什么呢?还有单步的时候没发现这个问题!
|