我在发送程序中,写了条指令发送给电脑,数据一致,但我在用电脑的串口工具发送数据时,在接收中断程序中数据不一致?不知道为什么,求大神指教。
@far @interrupt void UART1_Recv_IRQHandler (void)//接收中断服务函数
{
u8 static Checksum,Lencnt=0;
if(UartState == UartStart)
{
if(UART1_DR == RxHeader)
{
UartState = UartWorking;
Checksum = UART1_DR;
UART_Header = RxHeader;
}
else if(UART1_DR == RxHeader1)
{
UartState = UartWorking;
Checksum = UART1_DR;
UART_Header = RxHeader1;
}
else
{
UartState = UartStart;
Lencnt = 0;
Checksum = 0;
}
}
else if(UartState == UartWorking)
{
if(++Lencnt<14)
{
Checksum += UART1_DR;
rxControllerInfobuf[Lencnt] = UART1_DR;
if(Lencnt == 13)
UartState = UartCheck;
else
UartState = UartWorking;
}
}
else if(UartState == UartCheck)
{
if(Checksum == UART1_DR)
{
rxControllerInfobuf[14] = UART1_DR;
UartState = UartOver;
}
else
{
UartState = UartReset;
}
}
else if(UartState == UartOver)
{
if(UART1_DR == Enterkey)
{
UARTREADREADY = 1;
UartState = UartReset;
}
else
{
UartState = UartReset;
}
}
else if(UartState == UartReset)
{
Checksum = 0;
Lencnt = 0;
UARTREADREADY = 0;
UartState = UartStart;
}
else
{
Checksum = 0;
Lencnt = 0;
UARTREADREADY = 0;
UartState = UartStart;
}
}
此帖出自
小平头技术问答
一周热门 更多>