完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,我正在使用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个回答
|
|
你发送的数据触发周期有什么关系?现在,您发送的是接收到的前一个字节,这可能是个问题。
以上来自于百度翻译 以下为原文 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 |
|
|
|
谢谢你的回复。我使用: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 ? |
|
|
|
我建议看一下这部分的勘误表,有一些时间问题和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? |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5250 浏览 9 评论
2037 浏览 8 评论
1958 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3218 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2266 浏览 5 评论
789浏览 1评论
681浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
610浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
685浏览 0评论
582浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 09:15 , Processed in 4.437640 second(s), Total 83, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号