完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在尝试将I2C RTC(MCP7940N)和EEPROM(24LC32 A)与18F420接口。我以前在18F45 2上做了一个实验室(是的,我知道它已经过时了,它是我必须学习的DEV板Labx1),在其中我为同一EEPROM写了I2C函数,它运行在4MHz。我把代码移植到在20MHz XTAL上运行在18F420上的我的项目上。我改变了SSPADAD= 0x31;具体来说,我要做的是读取RTC芯片上的寄存器。代码执行;直到SSPCON2BIT.RCEN=1;//启用接收同时(!)SSPSTATbits.BF),它挂在时间,显然表明,SSPBUF从来没有填补。我为EEPROM和RTC写了单独的读写功能,因为EEPROM的内部存储器从0x00到0x0FFF,而RTC只有一个字节的存储器地址从0x00到0x60,所以我必须写两个地址从EEPROM和一个RTC。我认为这可能是一个问题的函数,所以我试着从EEPROM读取它是挂在同一点,SSPSTATbits.BF总是停留在0。我选择了一个非法的XTAL值吗?我是否将SSPADD设置为正确的值?它在数据表中说,在SSPCON2BITS RCEN=1之前,I2C必须是空闲的,但我认为我正在这样做…它似乎是写作,因为否则它会挂在等待ACK,对不对?我错过了什么?我的I2C函数位于代码的最底层…
以上来自于百度翻译 以下为原文 I am trying to interface an I2C RTC (MCP7940N) and EEPROM (24LC32a) with the 18F4520. I had previously done a lab on the 18F452 (yes I know it's terribly obsolete, it's the dev board LabX1 I had to learn on) in which I wrote I2C functions for the same EEPROM and it worked running at 4MHz. I ported the code over to my project running on the 18F4520 on a 20MHz Xtal. I changed the SSPADD=0x31; Specifically, what I'm trying to do is read the registers on the RTC chip. The code executes until; SSPCON2bits.RCEN=1; // enable receive while( !SSPSTATbits.BF ); It hangs on the while, apparently indicating that the SSPBUF is never filling. I wrote separate read and write functions for the EEPROM and the RTC because the internal memory of the EEPROM goes from 0x0000 to 0x0FFF while the RTC only has one byte of memory addresses from 0x00 to 0x60, so I have to write two addresses from the EEPROM and one for the RTC. I thought it might be a problem with the function, so I tried reading from the EEPROM and it is hanging at the exact same point, SSPSTATbits.BF is always stuck on 0. Did I pick an illegal Xtal value? Did I set the SSPADD to a correct value? It says in the datasheet that i2c must be idle before SSPCON2bits.RCEN = 1, but I think I am doing that... It seems to be writing because otherwise it would hang waiting for the ACK, right? What am I missing? My i2c functions are at the very bottom of the code... Attachment(s) Battery_OneWire_LCD.c (64.06 KB) - downloaded 67 times |
|
相关推荐
4个回答
|
|
谢谢你的帮助,非常感谢。微笑:好的,我已经修改了i2cx写()函数,以便它轮询ACKSTAT,并将该值保存到变量NoToACK。如果变量是“1”,我调用I2C*WrreEsStutter()函数。I2CyWrad将返回变量NoToACK。我已经修改了所有调用I2CX写的函数,以便检查该函数的返回。如果(NOTIACK){返回;}从函数中跳出并跳回到主()中。AddisSpCn2BITS.ACKDT=1;在读取I2CX Read SoSo中的SSPBUF之后。我还添加了一些对LCD的调用,用于在I2C*Read短()中进行故障排除。LCDSGOOTYY(1, 1);PrtTf(“是”);I2CyReaveEnabable();//启用SurvivCDGoToYy(1, 2);PrtTf(“使它”);“是”显示在我的LCD屏幕上,但是“使”不是。
以上来自于百度翻译 以下为原文 Thanks for your help, it's much appreciated. Smile: Okay, I have modified the i2c_write() function so that it polls ACKSTAT and saves the value to a variable not_ack. If the variable is '1', I call my i2c_write_stop() function. i2c_write will return the variable not_ack. I have modified all of the functions calling i2c_write so that it will check the return from that function. if(not_ack){ return; } To break out of the function and jump back to main(). I've added SSPCON2bits.ACKDT = 1; after I read the SSPBUF in the i2c_read_short() and i2c_read_byte() functions. I also added some calls to my LCD for troubleshooting in i2c_read_short(). lcd_gotoxy( 1, 1); printf("yes"); i2c_receive_enable(); // enable receive lcd_gotoxy( 1, 2); printf("made it"); The 'yes' is showing up on my lcd screen, but the 'made it' is not. Attachment(s) Battery_OneWire_LCD.c (65.55 KB) - downloaded 69 times |
|
|
|
它只指定在设置AKEN位时应该发送什么值,这是您没有做的。在PIC18F420数据表的段落“174.11I2C主模式接收”的结尾提到了这一点。
以上来自于百度翻译 以下为原文 That just specifies what value should be sent when you set the ACKEN bit, which you haven't done. This is mentioned at the end of the paragraph "17.4.11 I2C MASTER MODE RECEPTION" in the PIC18F420 datasheet. |
|
|
|
好吧,我肯定错过了数据表上的内容。我有Addidi2CyrtCyByth= SSPBUF;//Read数据。SSPCON2BITS.ACKDT=1;//这是最后一个字节,一次读取一个字节SSPCON2BITS AKEN=1;//在我的两个读取函数的传输结束时发送确认。我仍然有同样的问题,它冻结了一段时间(!)SSPSTATbits.BF);
以上来自于百度翻译 以下为原文 Okay I must have missed that on the datasheet. I've added i2c_RTC_byte=SSPBUF; // read data. SSPCON2bits.ACKDT = 1; //this is the last byte, one byte read at a time SSPCON2bits.ACKEN = 1; //send acknowledge at end of transaction in my two read functions. I'm still having the same problem with it freezing at while( !SSPSTATbits.BF ); Attachment(s) Battery_OneWire_LCD.c (65.66 KB) - downloaded 81 times |
|
|
|
我似乎已经解决了这个问题,在那一点上不再僵化了。我写信和阅读我的RTC芯片没有问题。该键似乎已经生成了一个函数:空I2CyDelad(空){(SSPCON2BITS.S.SPCON2BITS.RSEN)SSPCON2BITS.PENNSSPCON2BITS RCENN SSPCON2BITS。不完全清楚它为什么工作,但它确实如此。这是一个更好的问题,因为它不工作,不知道为什么…
以上来自于百度翻译 以下为原文 I seem to have resolved the issue, it's no longer freezing at that point. I'm writing to and reading from my RTC chip with no problems. The key appears to have been to make a function: void i2c_idle(void) { while(SSPCON2bits.SEN || SSPCON2bits.RSEN || SSPCON2bits.PEN || SSPCON2bits.RCEN || SSPCON2bits.ACKEN|| SSPSTATbits.R_W); } and add that in to the read functions in the place of my other while waits. Not totally sure why it works but it does. That's a better problem to have than it not working and not knowing why... Attachment(s) Battery_OneWire_LCD.c (68.60 KB) - downloaded 72 times |
|
|
|
只有小组成员才能发言,加入小组>>
5231 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3200 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
669浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 10:27 , Processed in 1.357925 second(s), Total 84, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号