使用串口助手发送数据:wr,1,0,100,0,1,1,3,0,3,0,1,100,0,100,0,100,0,65536,0,1,0,0,0,0,0,2,1,1,2,0,16,0,0,0,1,0,1,
单次发送一切正常,在间隔1s连续发送时出现接收出错的情况,该如何解决
中断函数如下:
void USART1_IRQHandler(void) //串口1中断服务程序
{
u8 Res;
#if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS为真,则需要支持OS.
OSIntEnter();
#endif
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { //接收中断(接收到的数据必须是0x0d 0x0a结尾)
Res = USART_ReceiveData(USART1); //读取接收到的数据
//printf("%c", Res);
if((USART_RX_STA & 0x8000) == 0) { //接收未完成
if(USART_RX_STA & 0x4000) { //接收到了0x0d
if(Res != 0x0a) //接收错误,重新开始
USART_RX_STA = 0;
else USART_RX_STA |= 0x8000; //接收完成了
}
else { //还没收到0X0D
if(Res == 0x0d)
USART_RX_STA |= 0x4000;
else {
USART_RX_BUF[USART_RX_STA & 0X3FFF] = Res ;
USART_RX_STA++;
if(USART_RX_STA > (USART_REC_LEN - 1)) //接收数据错误,重新开始接收
USART_RX_STA = 0;
}
}
}
}
#if SYSTEM_SUPPORT_OS //如果SYSTEM_SUPPORT_OS为真,则需要支持OS.
OSIntExit();
#endif
}
#endif
|