Microchip
直播中

任黎平

8年用户 150经验值
私信 关注
[问答]

为什么只有当发送一组奇数值ASCII数据时spi receive才会挂起?

你好,我正在使用SPI在无线ZigBee模块(从机)和PIC18F420(主机)之间进行通信。这里是SPI部分:/*SS_Set();(len--){unsigned char TempVar;TempVar=SSPBUF;.//Clears BFPIR1bits.SSPIF=0;.//Clear inter.flagSSPCON1bits.WCOL=0;SSPBUF=*pBuf;.//启动SPI bu轮到你了!(PIR1bits.SSPIF);..//等待,直到“BF”位被设置*pBuf+=SSPBUF;}SS_Clr();..//Slave Clear(Active.)*/如果接收到奇值ascii数据,SPI代码似乎挂起。例如:无线模块(1)=A.Module(2)+PIC(Master)=B当A向B发送一组数据(“AAA”或“0x41,0x41,0x41”)时,B中实现的代码在接收到两到三组之后似乎挂起。没有任何问题。只有当发送一组奇数值ASCII数据时,它才会挂起。

以上来自于百度翻译


      以下为原文

    Hello,
I'm communicating between a wireless zigbee module (Slave) and pic18f4520(master) using SPI. Here is the SPI part:

/*
SS_Set();                                                    //Slave Set (Active Low)
while (len--)
{
unsigned char TempVar;
TempVar = SSPBUF;                                    // Clears BF
PIR1bits.SSPIF = 0;                                    // Clear interrupt flag
SSPCON1bits.WCOL = 0;

SSPBUF = *pBuf;                                       // initiate SPI bus cycle
while(!PIR1bits.SSPIF);                               // wait until 'BF' bit is set
*pBuf++ = SSPBUF;
}
SS_Clr();                                                  //Slave Clear (Active Low)
*/

The SPI code seems to hang if an odd-value ascii data is received. For example:

Wireless Module (1) = A
Wireless Module(2)+PIC(Master) = B

When A sends a set of data ("AAA" or "0x41,0x41,0x41") to B, the code which is implemented in B seems to hang after receiving two or three sets.

When A sends a set of data ("BBB" or "0x42,0x42,0x42") to B, it receives continuously without any issues. It only hangs if A sends a set of odd-value ascii data.

回帖(4)

王焕树

2019-7-25 12:41:25
你发送的数据触发周期有什么关系?现在,您发送的是接收到的前一个字节,这可能是个问题。

以上来自于百度翻译


      以下为原文

    Does it matter what data you are sending to trigger the cycles?
Right now you are sending the previous byte that was received, which could be a problem.
Try changing:
SSPBUF = *pBuf;                                       // initiate SPI bus cycle
to
SSPBUF = 0;                                       // initiate SPI bus cycle
 
举报

陈丹丽

2019-7-25 12:49:14
谢谢你的回复。我使用:SSPBUF=*pBuf;as*pBuf指向缓冲区,其中包含使用微控制器设置从设备(无线模块作为路由器)所需的信息。因此,我通过从主设备发送所需的命令,将无线模块设置为使用SPI通信的路由器。我是否应该为发送和接收不来自PIC的数据创建另一个功能?

以上来自于百度翻译


      以下为原文

    Thank you for your reply. I used:
SSPBUF = *pBuf; 
as *pBuf points to the buffer which contains information needed to set up the slave (wireless module as router) using the microcontroller. So I set up the wireless module to behave as a router using SPI communication by sending the required commands from the master. 

Should I create another function for sending and receiving data which is not coming from the PIC ?
举报

tijing忽忽

2019-7-25 13:07:12
我建议看一下这部分的勘误表,有一些时间问题和BF/SSPBUF/SSPIF需要考虑。可能会有答案吗?

以上来自于百度翻译


      以下为原文

    I suggest a look at the errata sheets for this part, there are some issues of timing and the BF/SSPBUF/SSPIF that need to be considered. Possibly an answer in there?
举报

张娜

2019-7-25 13:36:43
***

以上来自于百度翻译


      以下为原文

    ***
举报

更多回帖

发帖
×
20
完善资料,
赚取积分