完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
好的,我使用I2C ALOT,因为我发现它是非常简单的(通常),并且非常有用的限制我的应用程序的PIN计数。我甚至为LCD写了一个奴隶/主人,所以我可以用我的PIN来做更重要的事情。除此之外,我的大多数I2C应用程序都是为像18F2510(我最喜欢的)这样的8位控制器编写的。这对我来说使用PIC32有点新。我不喜欢XC32,但我没有选择的余地。我与AA24512交谈的程序似乎都在起作用。启动、停止、发送数据等。当我将数据写入EEPROM时,所有关于总线上的数据和EEPROM的ACK位看起来都很好。当我试图从EEPROM获取数据时,我遇到了一个问题。根据数据表的过程是:开始,地址(写),内存高地址,内存低地址,重新启动,地址(读取),从EEPROM接收数据字节,停止。使用我的逻辑分析仪,我可以看到所有的流量,直到发送地址(读)和ACEEPROM的ACK。但是什么都没有回来。CLK低,I2C总线高。我不知道我该怎么做才能让EEPROM发送数据。如果这是SPI,我会输出一个哑变量,但是用I2C,只有一个总线。我错过了什么?
以上来自于百度翻译 以下为原文 Ok, I have used I2C alot as I find it to be pretty simple (usually) and very useful in limiting pin count on my apps. I have even written a slave/master for an LCD so I can use my pins for more important stuff. That aside, most of my I2C apps are written for 8-bit controllers like the 18F2510 (my favorite). So this is a bit new for me to be using pic32. I don't really like XC32, but I don't have a choice in this. So, here's the delima. The proceduers I have for talking with the aa24512 all seem to be working. Start, Stop, Send data, etc. When I write data to the EEPROM all looks good with regards to the data on the bus and the ACK bits from the EEPROM. All is good here. When I try to get data back from the EEPROM, I get into a problem. The procedure, according to the datasheet is: start, address (write), memory high address, memory low address, restart, address (read), receive data byte from eeprom, stop. Using my logic analyzer, I can see all the traffic right up to the send address (read) and the ack from the EEPROM. But then nothing comes back. The clk is low and the I2C bus is high. I don't know what I'm supposed to do to get the EEPROM to send the data. If this were SPI I would clock out a dummy variable, but with I2C, there is only the one bus. What have I missed? |
|
相关推荐
5个回答
|
|
嗨,如果SCL很低,SDA很高,它要么是有bug的主代码,要么是在时钟拉伸中保持时钟线的奴隶。如果它是相反的,SCL行高和SDA线Low,那么它通常是被系统复位或类似的中止操作。在这种情况下,可以禁用I2C外围设备,并通过LATX比特=0和SCLIX TIXX位时钟。在寄存器名称不同的情况下,PIC32 MX中的I2C外围基本上与PIC18中的MSSP外围做相同的操作,并且按相同的规则播放。I2C外设的WO实例,您使用I2C1还是I2C2,您确信在所有代码中都使用正确的I2CX寄存器名吗?当通信被卡住时,I2CXCON和I2CXSTAT寄存器的内容是什么?没有更多的信息,或者一个完整的运行和调试的示例程序,就不可能找出原因。迈西尔
以上来自于百度翻译 以下为原文 Hi, If SCL is Low and SDA is High, it is either Master code that have bug, or Slave that is holding clock line in Clock stretching. If it is opposite, SCL line high and SDA line Low, then it is usually a Read operation that have been aborted, by system Reset or similar. In this case, it is possible to disable the I2C peripheral, and clock the SCL line by LATx bit = 0; and toggling TRISx bit. While Register names are different, I2C peripheral in PIC32MX basically do the same thing as MSSP peripheral in PIC18, and play by the same rules. In PIC32MX270F256B there are Two instances of the I2C peripheral, are you using I2C1 or I2C2, are you sure that the correct I2Cx register name is used in All code? What are the contents of I2CxCON and I2CxSTAT registers when communication is stuck? Without more information, or a complete example program to run and debug, it is impossible to identify the cause. Mysil |
|
|
|
我发现了这个问题。我的操作时间太短了。我开始使用EEPROM数据表中列出的轮询例程,以确保在写入操作期间不试图写入它。我现在正在通过代码,但是公共汽车上有很多活动。它需要4.3毫秒(基于逻辑分析器的时间戳),EEPROM将一个字节写入一个地址。根据数据表,这是在最大极限。我想看看有点快,但我想避免问题,并保持公共汽车安静,我只是插入5ms之间的定时器延迟操作。
以上来自于百度翻译 以下为原文 I found the problem. My timing between operations was too short. I started using the polling routine listed in the eeprom datasheet to ensure I was not trying to write to it while it was in the middle of a write operation. I am now getting through the code, but there is alot of activity on the bus. It took 4.3 mS (based on time stamps from the logic analyzer) for the eeprom to write one byte into one address. This is right at the max limit according to the datasheet. I would like to see that a bit faster, but I guess to avoid problems, and keep the bus quiet, I just insert a 5mS timer delay between operations. |
|
|
|
正确的方法是轮询直到芯片告诉它完成。
以上来自于百度翻译 以下为原文 The CORRECT way is to do the polling until the chip tells you it is finished. |
|
|
|
我明白,这就是为什么巴士上有这么多的“噪音”,但是如果我知道写周期大约需要5毫秒,为什么当我用不同的设备做一些有用的事情时,我会一直戳它?我可以发送一个消息到一个不同的外围设备,而我在5ms的数据写入,然后开始一个新的读/写周期。这样,我就不用担心了——比如公共汽车碰撞等。
以上来自于百度翻译 以下为原文 I understand, and that is why there is so much "noise" on the bus, but if I know that it's going to take about 5 mS for the write cycle to finish, why would I keep poking it when I couls be doing something useful with a different device? I can send a message to a different peripheral while I wai the 5mS for the data to write then start a new read/write cycle. This way I'm not going to have to worry -as much- about bus collisions etc. |
|
|
|
如果不使用中断:“轮询”不一定意味着你需要在紧循环中等待直到操作完成,尽管这是最简单的编码方式。如果您正在使用状态机(或类似的逻辑),则可以在一个循环中执行(调度)许多任务。其中一项任务是不时检查你的EEPROM操作是否准备好了,然后写一个额外的字节或任何下一个,如果准备好了。另一种方法可能是,在写入EEPROM之后不要等待,而是在访问EEPROM之前等待。(下一次写入或任何其他操作)。或者你可以同时使用这两种方法。如果你为其他I2C设备使用相同的I2C总线,那么逻辑变得更复杂。是否值得投资这个编码工作,取决于你的应用程序和要求,即5ms的阻塞有多大。因为这可能引入新的bug,并且需要更多的测试,如果需要的话,我只会这样做。
以上来自于百度翻译 以下为原文 If not working with interrupts: "Polling" does not necessarily mean that you need to wait in a tight loop until the operation is done, though this is the easiest way to code. If you are working with a state machine (or similar logic), you could do (dispatch) many tasks in a loop. One of the tasks could be to check from time to time whether your eeprom operation is ready, and then write an additional byte or whatever comes next, if ready. Another approach could be that you do not wait AFTER writing to the eeprom, but instead wait BEFORE accessing the eeprom. (for next write or any other operation). Or you could use both. If you are using the same i2c bus for other i2c devices, then the logic becomes a bit more complicated. Whether it's worth to invest this coding effort, depends on your application and requirements, i.e. how much a blocking of 5ms hurts. Since this may introduce new bugs and requires more testing I would only do that, if needed. |
|
|
|
只有小组成员才能发言,加入小组>>
5129 浏览 9 评论
1984 浏览 8 评论
1914 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3149 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2212 浏览 5 评论
698浏览 1评论
586浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
467浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
603浏览 0评论
495浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-3 16:01 , Processed in 1.297002 second(s), Total 87, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号