用的是UART0中断接收的,接收20个字节,但是使用过程中有时候蓝牙发过来的数据接收不完整,后来我加上了清除OR中断,就有时候是一次成功,有时候就是得多发几次才能成功,如何解决这
void UART0_IRQHandler(void)
{
static U8 Uartbit0 = 0;
UART0_MemMapPtr Channel0;
Channel0 = UART_0;
/* Wait until character has been received */
while (!(UART0_S1_REG(Channel0) & UART0_S1_RDRF_MASK));
/* Return the 8-bit data from the receiver */
Uart[Uartbit0] = UART0_D_REG(Channel0);
Uartbit0++;
if((Uart[0]==0x01) && (Uart[10]==0x02))
{
Uartcmd = 1;
Uartbit0 = 0;
}
else if((UART0_S1_REG(Channel0)&0x08) == UART_S1_OR_MASK)
{
Uartbit0 = 0;
memset(Uart,0,20);
UART0_S1_REG(Channel0) |= UART_S1_OR_MASK;
}
}
|