完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
请容忍我。我是新的I2C,在PIC16F1936(增强的中程)上实现。我有一个尴尬的问题。我已经能够使用主模式从EEPROM写入和接收。我在使用从模式时遇到了问题。我的问题是,在读取设备时,我似乎不知道如何识别重启条件?(或者开始或停止,1)。我知道在哪里可以设置SSPCON1,(3-0)SSPM位到b'1110',以便启用具有启动和停止中断的7位从模式。我知道在哪里可以设置SSPCON3、PCIE和SSCIE位,以便分别启用开始位中断和停止位中断。我看到SSPSTAT、P和SSPSTAT的S位反映了已经接收到的最后一位(开始或停止)的当前状态。(我有点困惑,为什么有aP和S位,因为它们看起来是彼此相反的,很容易一个或者另一个就足够了?)4。在数据表中说,在启动条件下,设置SSPIF标志。但是…设置SSPIF标志…对于所有的事情,如果有这样的事情,决定什么是SPIF标志?开始条件与停止条件VS第八时钟信号的下降沿与时钟信号的第九下降沿…我特别关注第259页的数据表的图24-17。这显示了信号…除了使用一些已保存的变量作为代码指针,并希望它开始时正确,并且永远不会搞砸之外,我看不出任何逻辑方法来确定这一点?我知道如果我启用AHEN和DHEN,AktiM位将告诉我SSPIF中断是否是由于第八下降沿与第九下降沿。但我看不到停止与开始位的区别在于其他SSPIF中断。如果每个都有一个中断标志,那就容易多了!我肯定有一些明显的东西我错过了吗?S和P比特作为标志吗?如果我自己清除S/P位,如果我这样做,它会保持畅通吗?编辑:逻辑思考这一点,我已经得出结论,P和S位必须作为中断标志?他们唯一的特殊之处是,当它们被设置时,它们会自动地相互清除。因此,当设置SSPIF标志时,我必须首先检查S,如果设置它是START,但是我必须清除它,以便知道下一个SSPIF标志是第8个下降时钟周期,而不是RESTART?为什么他们不显示软件/用户明确的S位?为什么它不叫“SCIF”呢?我想我得亲自检查一下,这已经是令人沮丧的3天了。叹息。
以上来自于百度翻译 以下为原文 Please bear with me. I am new to I2C, implementing on a PIC 16F1936 (enhanced midrange). And I have an embarrassing problem. I have been able to use Master mode to write and receive from an EEPROM. I am having issue using Slave mode. The crux of my problem is that during a read of the device, I can't seem to figure out how to recognize a restart condition?? (Or a start or stop, for that matter). 1. I see where I can set up SSPCON1,(3-0) SSPM bits to b'1110', in order to enable 7 bit slave mode with start and stop interrupts. 2. I see where I can set SSPCON3,PCIE and SSPCON3,SCIE bits in order to enable start bit interrupt and stop bit interrupt respectively. 3. I see where SSPSTAT,P and SSPSTAT,S bits reflect the current state of last bit (start or stop) that has been received. (Which I am a little confused why there is a P and an S bit, since they seem to be the inverse of each other, and easily one or the other would suffice?) 4. In the datasheet is says that on a start condition, SSPIF flag is set. But... the SSPIF flag is set... for everything. What would be the conventional way, if there is such a thing, to determine what set the SSPIF flag? Start condition vs a stop condition vs the 8th falling edge of the clock signal vs the 9th falling edge of the clock signal...? I'm looking in particular at figure 24-17 of the datasheet on page 259. This shows the signals... And I see no logical way to determine this, other than using some saved variable as a code pointer and hoping it starts out correct and never gets messed up? I see where if I enable AHEN and DHEN, ACKTIM bit will tell me if SSPIF interrupt is due to 8th falling edge vs 9th falling edge. But I do not see where the stop vs start bits are differentiated from other SSPIF interrupts. It would be much easier if there was an interrupt flag for each! I am sure there is some obvious thing I am missing? Do the S and P bits act as flags? If I clear the S/P bit myself will it stay cleared, if I do this? Edit: Logically thinking this thru, I have come to conclusion that P and S bits must act as interrupt flags? And the only thing special about them is that they automatically clear each other when they are set? So when SSPIF flag is set, I must first check S, if set it is a START, but I must clear it in order to know that the next SSPIF flag is the 8th falling clock cycle and not a RESTART? Why they do not show software/user clear of the S bit? And why is it not called "SCIF"? I suppose I have to check this for myself, and it has been a frustrating 3 days, already.. sigh. |
|
相关推荐
3个回答
|
|
这就是我的问题所在。而在ISR中为I2C通信服务。如何识别重启?重启会触发中断。但是我已经被打断了。我不知道主人是否打算写下一个字节,或者如果它重新启动,以便发送一个读命令?还是我忽略了重新启动,并检查下一个字节是否是一个数据与地址读D/A位?(在这种情况下,我无法写入与设备的SSPADD地址匹配的数据字节)????对不起,如果这是没有意义的。这对我来说是完全正确的。我的代码在工作。我的奴隶正在识别它的地址和发送ACK。它接收第一个数据字节。但我在重启时输了。我不知道如何识别重新启动条件?在数据表中没有重新启动的文档。在示例中,它总是显示主发送不ACK或停止位。这个主机既不使用,也不使用重新启动位。我看不出识别这种情况的方法。
以上来自于百度翻译 以下为原文 So herein lies my problem. While in the ISR servicing the I2C communication. How do I recognize a RESTART? A RESTART would trigger an interrupt. But I'm already in the interrupt. I have no way to know if the master intends to write the next byte or if it has restarted in order to send a read command? Or do I ignore the restart and check to see if the next byte is a data vs address by reading the D/A bit? (in which case, I cannot ever write a byte of data that happens to match the SSPADD address of your device??? I'm sorry if this makes no sense. It makes perfect sense to me. My code is working. My slave is recognizing it's address and sending ACK. It is receiving the first data byte. But I am losing it at the RESTART. I do not understand how to recognize the RESTART condition? There is no documentation of RESTART in the datasheet. In the examples it always shows the master sending a not ack or a stop bit. This master does neither and uses a restart bit. I do not see a way to identify this condition? |
|
|
|
嗯,我想这能解决问题。荒山亮似乎也发现了同样的问题。我想我可以停止尝试找出它并开始创建我自己的FLAG.HTPP//www. McCHIP.COM/FUMMS/M1431.ASPX
以上来自于百度翻译 以下为原文 Well, I guess this settles it. Ric seems to have found the same problem. I guess I can stop trying to figure it out and start creating my own flags. http://www.microchip.com/forums/m14311.aspx |
|
|
|
我想您应该测试一下D/A。据我所知,地址字节只能在开始或重新启动之后出现,它不会在数据值上触发。
以上来自于百度翻译 以下为原文 I think you test the D/A bit. As I understand it an address byte can only come after a start or restart, it won't trigger on data values. |
|
|
|
只有小组成员才能发言,加入小组>>
5244 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3214 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2261 浏览 5 评论
779浏览 1评论
675浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
601浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
683浏览 0评论
580浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 23:25 , Processed in 1.258947 second(s), Total 83, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号