完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,在用2个图片创建SPI通信时,我想在从SPI接收数据时创建中断代码。我使用这个代码,但我没有收到正确的数据:从:PIC24F14KL402,如果有人现在怎么做?非常感谢大家的帮助!:)
以上来自于百度翻译 以下为原文 Hi, After create SPI communication with 2 PICs, I want to create interrupt code when slave spi receive data. I use this code but I don't receive the right data : void _ISRFAST _SPI1Interrupt(void){ IFS1bits.SSP1IF=0; while (SSP1STATbits.BF==0); datafrommaster=SSP1BUF; SSP1BUF=datatosend; } Slave : PIC24F14KL402 If someone now how to do this ? Thank a lot everyone for your help ! :) |
|
相关推荐
4个回答
|
|
在中断服务代码中去掉这个阻塞环。我不相信这是你的直接问题,但是它不应该存在。只有中断被调用的事实告诉你数据已经准备好了。
以上来自于百度翻译 以下为原文 Get rid of this line while (SSP1STATbits.BF==0); Never put blocking loops inside interrupt service code. I'm not convinced that is your immediate problem, but it shouldn't be there. The mere fact the interrupt has been called tells you there is data ready. |
|
|
|
你收到了什么?你期望得到什么?我将再次重复自己:“不工作”几乎无用,如果它“工作”,你可能不会张贴在论坛上的援助请求。你必须告诉我们更多:什么工作,什么不工作,你期待什么,你得到什么?然后你可能会得到更多的猜测(真正的猜测有时,但最好不要“希望”)。
以上来自于百度翻译 以下为原文 What do you receive? What are you expecting to receive? I will repeat myself once more: "doesn't work" is nearly useless, if it "worked" you probably would not be posting a request for assistance on a forum. You MUST tell us more: what works, what does not work, what are you expecting, what do you get instead? Then you may get something more then guesses (really good guesses sometimes but best not to "hope" for that). |
|
|
|
我有2个图片,一个PIC在主模式中,另一个在从属模式中,我在这2个图片之间创建了一个简单的SPI通信。现在,我也想把我的从属代码放在中断模式中,当我从主机发送数据时,我的从属PIC将这个值保存到它的内部EEPROM中。用于连接我的2个PIC。S(PIC24F16KA102主控器和PIC24F16KL402从机)PICKAKA=PICKLKCS(Pi26)=CS(Pi26)MoSi(Pi24)=MISO(Pi21)MISO(Pi21)=MOSI(Pin 24)CLK(Pin 22)=CLK(Pin 22),当我创建中断时,我的从属器不接收来自主机的数据,反之亦然,主机不从从属数据接收数据。所以我试着把我的中断放到状态机中,我得到正确的值,但是当我把我的主代码放在无限循环中时,我就什么也得不到:
以上来自于百度翻译 以下为原文 I have 2 PICs, One pic in Master mode The other in Slave modes First, I created a simple SPI communication between this 2 PICS. Now, I would like too put my slave code in interrupt mode for when I send data from master, my slave PIC save the value into its internal EEPROM. For connecting between my 2 PICS ( PIC24F16KA102-Master and PIC24F16KL402-Slave) PIC_KA=PIC_KL CS(PIN26)=CS(PIN26) MOSI(PIN24)=MISO(PIN21) MISO(PIN21)=MOSI(PIN24) CLK(PIN22)=CLK(PIN22) When I create my interrupt , my slave doesn't receive data from master and vice versa master doesn't receive data from slave. So I try to put my interrupt into state machine and I get the right values but when I put my master code outside in infinite loop, I don't get anything : int main(void) { ANSB=0x0000000000000000; TRISB = 0x00; ODCBbits.ODB12=0; TRISAbits.TRISA0 = 0; // LED enum { IDLE, SPI_SLAVE,EEPROM, LED }State; SPI1Init(); SSP1BUF=0; while(1) { switch (State) { case IDLE: State=LED; break; case LED : LATAbits.LATA0^=1; State= SPI_SLAVE; break ; case SPI_SLAVE : if (IFS1bits.SSP1IF==1){ IFS1bits.SSP1IF=0; while (SSP1STATbits.BF==0); datafrommaster=SSP1BUF; SSP1BUF=dataformslave; } EEwrite(writeaddress,datafrommaster); State=EEPROM; break; case EEPROM : dataEEPROM=EEread(writeaddress); break; State=IDLE; default : State=IDLE; break; } } } |
|
|
|
你是说POST 4中的代码有效吗?像往常一样,发布代码片段几乎总是意味着你忽略了重要的位。请张贴不工作的整个源文件。
以上来自于百度翻译 以下为原文 Are you saying the code in post #4 DOES work? As always, posting snippets of code nearly always means you leave out the vital bit. Please post the entire source file that doesn't work. |
|
|
|
只有小组成员才能发言,加入小组>>
5248 浏览 9 评论
2037 浏览 8 评论
1957 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3218 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2265 浏览 5 评论
788浏览 1评论
680浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
608浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
685浏览 0评论
582浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-28 10:33 , Processed in 1.184047 second(s), Total 82, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号