我用两片M16用SPI试通信,主机发一串数据,从机接收偶乐出错,所以想加上回送重发指令,可是回送的数老是不对,比如主机发的是76 34 70 ab fd 11 39 98 aa ………,从机回送0,可主机接收到的数据如下,夹杂有很多送出的数。 AA 00 76 00 00 00 00 00 39 98 00 00 00 00 00 00 00 00 00 00 FD 00 00 00 00 00 14 00 00 00 00 34 00 00 00 00 00 00 AA 00 00 00 00 00 76 00 00 00 00 00 39 00 00 00 00 00 00 00 00 00 00 AB 00 00 00 00 00 00 2B 00 00 00 00 34 00 00 00 00 00 98 00 00 00 00 00 00 00 00 00 00 FD 11 00 00 00 00 00 38 00 00 00 00 00 AB 00 00 00 00 00 7E 00 00 00 00 76 00 00 00 00 00 00 98 00 00 00 00 00 00 00 00 00 00 FD 00 00 00 00 00 52 A4 00 00 00 34 70 00 00 00 00 00 AA 00 00 00 00 00 76 00 00 00 00 00 39 00 00 00 00 00 00 00 00 00 00 00 FD 00 00 00 00 00 6A 00 00 00 00 34 00 00 00 00 00 98 AA 00 00 00 00 00 00 00 00 00 00 00 39 00 00 00 00 00 00 00 00 00 00 AB 00 00 00 00 00 7E 81 00 00 00 76 34 00 00 00 00 00 98 00 00 00 00 00 00 00 00 00 00 FD 00 00 00 00 00 00 1A 00 00 00 00 70 00 00 00 00 00 AA 00 00 00 00 00 00 00 00 00 00 00 39 00 00 00 00 00 00 00 00 00 00 00 FD 00 00 00 00 00 A8 00 00 00 00 34 00 00 00 00 00 00 AA 00 00 00 00 00 00 00 00 00 00 11 00 00 00 00 00 24 00 00 00 00 70 AB 00 00 00 00 00 7E 00 00 00 00 00 00 70 00 00 00 00 00 AA 7E 80 00 00 00 00 00 70 00 00 00 00 00 AA 7E 00 00 00 00 76 34 00 00 00 00 00 98 00 00 00 00 00 00 00 00 00 00 FD 00 00 00 00 00 00 30
如果从机不回送,删掉SPDR=0;一句,主机接收到是就是它发出的数据,当然慢一个字节。晕了,是不是从机不够快呀?没有及时更新SPDR,各位有经验的老大说一下。 |