单片机串口设置的问题

展开阅读全文

单片机串口数据接收问题

01-07

单片机串口数据接收,波特率9600.数据包格式为AA 55 A5 5A + 16个数据 + 5A A5 55 AA.rn使用PC的串口调试助手发送一包数据,串口可以接收到并通过CAN总线发送出去。但是和串口数据发送设备联调时串口收不到数据。rn下面是我写的串口接收程序,请各位帮忙看看有什么问题吗?谢谢rn//串口接收中断rnvoid SCI_1_ISR(void)rnrn DatBuf = SCI1DL;rn if(Status == 0)rn rn if(DatBuf == 0xaa)rn rn Status = 1;rn DatBuf = 0;rn rn elsern rn Status = 0;rn DatBuf = 0;rn rn rn else if(Status == 1)rn rn if(DatBuf == 0x55)rn rn Status = 2;rn DatBuf = 0;rn rn elsern rn Status = 0;rn DatBuf = 0;rn rn rn else if(Status == 2)rn rn if(DatBuf == 0xa5)rn rn Status = 3;rn DatBuf = 0;rn rn elsern rn Status = 0;rn DatBuf = 0;rn rn rn else if(Status == 3)rn rn if(DatBuf == 0x5a)rn rn Status = 4;rn DatBuf = 0;rn DatCnt = 0;rn rn elsern rn Status = 0;rn DatBuf = 0;rn rn rn else if(Status == 5)rn rn DatArray[DatCnt] = DatBuf;rn DatCnt++;rn if(DatCnt>=16)rn rn DatCnt = 0;rn Status = 6;rn rn rn else if(Status == 6)rn rn if(DatBuf == 0x5a)rn rn Status = 7;rn DatBuf = 0;rn rn elsern rn Status = 0;rn DatBuf = 0;rn rn rn else if(Status == 7)rn rn if(DatBuf == 0xa5)rn rn Status = 8;rn DatBuf = 0;rn rn elsern rn Status = 0;rn DatBuf = 0;rn rn rn else if(Status == 8)rn rn if(DatBuf == 0x55)rn rn Status = 9;rn DatBuf = 0;rn rn elsern rn Status = 0;rn DatBuf = 0;rn rn rn else if(Status == 9)rn rn if(DatBuf == 0xaa)rn rn Status = 10;rn DatBuf = 0;rn rn elsern rn Status = 0;rn DatBuf = 0;rn rn rnrnrn//主函数中rnwhile(1)rnrn if(Status == 10)rn rn //使用CAN总线发送DatArray[]rn Status = 0;rn rn 论坛

没有更多推荐了,返回首页