完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,在我以前的帖子中,我确信关于MCC如何设置它们我有一些注册问题,但是我已经确认了注册是正确的。使用调试器,我发现当我调用I2C MasterWrite函数时,我的代码陷入这个循环:if(i2c2_object.tr..s..!= true)//它运行这个if语句,它发现该if语句为假,并跳转到else语句{I2C2_MasterWriteTRBBuild(&trBlock,pdata,.,address);I2C2_MasterTRBInsert(1, &trBlock,pflag);}.{pflag=I2C2_MESSAGE_FAIL;//我的代码在这里,设置为失败然后跳过很不幸,我无法用I2C代码做头或尾,如果有人能给我解释如何实现代码,那将是非常棒的。我需要使用什么功能,如何处理错误处理,碰撞等等。谢谢!
以上来自于百度翻译 以下为原文 Hello, In my previous posts I was sure that I had some sort of register issue with regards to how MCC set them, but I have confirmed the registers are correct. Using a debugger, I have found that when I call I2C MasterWrite function, my code gets caught up in this loop: if (i2c2_object.trStatus.s.full != true) //It runs this if statement, which it finds to be false and skips to the else statement { I2C2_MasterWriteTRBBuild(&trBlock, pdata, length, address); I2C2_MasterTRBInsert(1, &trBlock, pflag); } else { *pflag = I2C2_MESSAGE_FAIL; //My code comes here, sets this to fail and then leaves the masterwrite function } unfortunately I cannot make heads or tails with the I2C code and would be extremely greatful if someone can explain to me how to implement the code. What functions do I actually need to use, how to handle error handling, collisions, etc. Thank you! |
|
相关推荐
7个回答
|
|
如果您发布到您自己的线程,而不是为每个消息创建一个新的线程。http://www..hip.com/for./m942207.aspx我认为您交换了ANSELC设置(FRMPdf)的含义。ANSELC寄存器(寄存器11-20)用于将I/O引脚的输入模式配置为模拟。设置适当的ANSELC位高将导致引脚上的所有数字读数被读为“0”,并且允许引脚上的功能正确操作。但是您需要数字引脚,至少对于SDA2。像这样阅读SDA2可能会导致“0”被解释为“总线碰撞”,没有任何进展。你也可以检查你的I2C2状态寄存器(更好地跳过MCC进行第一次测试)。
以上来自于百度翻译 以下为原文 It would be easier, if you post to your own thread instead of creating a new one for each message. http://www.microchip.com/forums/m942207.aspx I think you swapped the meaning of your ANSELC setting (your FRM pdf) The ANSELC register (Register 11-20) is used to configure the Input mode of an I/O pin to analog. Setting the appropriate ANSELC bit high will cause all digital reads on the pin to be read as '0' and allow analog functions on the pin to operate correctly. But you need digital pins instead, at least for SDA2. Reading SDA2 like this will likely result in a '0' interpreted as "bus collision" and nothing will proceed. You might also check your i2c2 status register (better skip MCC for a first test) for this bus collision. |
|
|
|
YAHHTTP://www. MigCHIP.COM/FUMMS/M942442.ASPXHTTP://www. McCHIP.COM/FUMMS/M942495.ASPX
以上来自于百度翻译 以下为原文 yeah http://www.microchip.com/forums/m942442.aspx http://www.microchip.com/forums/m942395.aspx |
|
|
|
嗯,我想我把端口C的RC1和位0混合了。无论如何,检查值并明确地查看状态寄存器是值得的。如果可能的话,在执行这个MCC行之后,直接发送开始条件I2C2_START_CONDIT._ENABLE_BIT=1;
以上来自于百度翻译 以下为原文 Uups, I think I mixed RC1 and Bit 0 of the port C. Anyway, it's worth to check the values and definitively have a look at your status register. If possible, directly after executing this MCC line: // send the start condition I2C2_START_CONDITION_ENABLE_BIT = 1; |
|
|
|
你好,很抱歉,由于某些原因,我没有收到邮件更新。通过阅读你写的评论,设置ANSELC=0X5将使RC1(SDA2)和RC4(SCLK2)成为数字输出。因此,如果我理解正确,您相信这些寄存器是正确的。您发送的行表示://发送开始条件I2C2_START_CONDIT._ENABLE_BIT=1;在我的代码中似乎没有定义。这是我需要发送的东西,让它工作吗?编辑:我调试了我的程序,把所有的寄存器都保持原样,我发现代码第一次运行时,它遍历了整个MasterWrite函数,包括启动条件、发送地址等。= SmithMaist-Delphi;
以上来自于百度翻译 以下为原文 Hello, Sorry for all the posts, I was not getting email updates for some reason. By reading the comments you wrote, setting ANSELC = 0X5 would make RC1 (SDA2) and RC4 (SCLK2) as digital outputs. So If I am understanding correctly, you believe those registers to be correct. The line you sent that says: // send the start condition I2C2_START_CONDITION_ENABLE_BIT = 1; Doesn't appear to be defined in my code. Is this something that I need to send in order for it to work? EDIT: I debugged my program keeping all the registers the way they are and I found that the first time the code runs, it goes through the whole MasterWrite function including the start-condition, send address, etc. On the second time around it gets caught up here: while(i2c2_state != S_MASTER_IDLE); |
|
|
|
忽略我对I2C2_START_CONDIT._ENABLE_BIT=1的注释;它只是MCC代码来生成开始条件。从您的另一篇文章:只要您有问题,我就不会用i2c协议附加一个以上的传感器。关于ANSELC=0X5:不是这个想法,请阅读有关ANSEL或ANSELC含义在您的手册(11. 6)中,您必须确保,您的SDA2引脚可以用作数字输入。如果是RC1,那么这个位必须是“0”。重要的是,SDA2必须能够同时输入和输出,并且附加了上拉。也请查阅您的手册(DS40001795B)表1。现在,虽然我只是想指出您必须处理的事情,但现在我看到您的描述不适合该表。您所说的“我已经将RC4设置为sCLK2和RC1为SDA2”,但至少默认设置是RC1= SDA1和RC4=SCL2。所以你正在混合这两个外围设备。也许可以用PPS来配置这个,但是它看起来更像是你的错误。当然,AsSELC= 0x5在这种情况下也是过时的。请检查一下。如果这不能解决问题,请告诉我们,您肯定没有重新配置i2c外围引脚。表11中i2c引脚的注释/微芯片注释:默认外围输入。输入可以移动到任何其他引脚与PPS输入选择寄存器。3:这些外围功能是双向的。输出管脚的选择必须与输入管脚的选择相同。4:这些管脚被配置为用于I2C逻辑电平;时钟和数据信号可以分配给这些管脚中的任何一个。分配给其他引脚(例如RA5)将操作,但逻辑电平将是标准的TTL/ST,由ILVL寄存器选择。
以上来自于百度翻译 以下为原文 Ignore my comment on I2C2_START_CONDITION_ENABLE_BIT = 1; it is just the MCC code to generate the start condition. From your other post: As long as you have problems I would not attach more than one sensor with i2c protocol. Concerning ANSELC = 0X5: No thats not the idea, please read about the ANSEL or ANSELC meaning in your manual (11.6.6) You must ensure, that your SDA2 pin can be used as digital input. If it is RC1 then this bit must be '0'. The important thing is that SDA2 must be able to be both input and output And that you have the pullup attached. Please also refere to your manual (DS40001795B) Table 1. Now, while I just wanted to point you to things you have to take care of, I now see that your description does not fit that table. You are talking about "I have set RC4 to SCLK2 and RC1 as SDA2", but at least the default settings are RC1 = SDA1 and RC4 = SCL2. So you are mixing the two peripherals. May be it is possible to configure this with PPS, but it looks more like an error of yours. Of course ANSELC = 0x5 is also obsolete in this case. Please check that. In case this does not resolve the problems, please let us know that you definitely do not reconfigure the i2c peripheral pins. Notes / Microchip comments for i2c pins in Table 1 1: Default peripheral input. Input can be moved to any other pin with the PPS input selection registers. 3: These peripheral functions are bidirectional. The output pin selections must be the same as the input pin selections. 4: These pins are configured for I2C logic levels; clock and data signals may be assigned to any of these pins. Assignments to the other pins (e.g., RA5) will operate, but logic levels will be standard TTL/ST as selected by the INLVL register |
|
|
|
现在我在你的其他帖子中看到了这一点。不清楚什么是打字或真实的或哪些信息覆盖了以前的帖子。我迷路了,出去了。
以上来自于百度翻译 以下为原文 Now I see this in one of your other posts. Not clear what is typo or real or which information overrides previous posts. -> I'm lost and "out". |
|
|
|
问题是我设置“RC1到SDA2”而不是“RC1到SCLK1”。你的意思是因为我更改了默认值,所以我不能将RC1用作SDA2,而将RC4用作SCLK2?所附的图片是我现在看到的,紫线是SDA2,蓝线是SCLK2EDIT:发现问题,在我应该选择HFINOSC时,我选择了32PPL振荡器。它工作得很好…现在确保数据是正确的。谢谢大家的帮助!
以上来自于百度翻译 以下为原文 The typo is that I set "RC1 to SDA2" instead of "RC1 to SCLK1". Are you saying that because I changed the default values, I cannot use RC1 as SDA2 and RC4 as SCLK2? The attached image is what I see now, the purple line is SDA2 and the Blue line is SCLK2 EDIT: Found the Issue, it appears that I chose the 32 PPL oscillator when I should have chosen the HFINOSC. It works great... now to make sure the data is correct. Thank you all for who helped! Attached Image(s) |
|
|
|
只有小组成员才能发言,加入小组>>
5309 浏览 9 评论
2070 浏览 8 评论
1974 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3243 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2281 浏览 5 评论
828浏览 1评论
721浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
668浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
719浏览 0评论
616浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-28 12:52 , Processed in 1.409277 second(s), Total 87, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号