完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
HI到ALI正在尝试为PIC 18F56K42实现I2C主控。MPLAB IDX 4.10和XC8 1.45硬件配置为内部OSC 64 MHz,I2C具有MimtoSc I2C时钟频率为500 kHz,FSCK=125kHz,上拉电阻为4.7K。连接到总线上的是MC23017和一个EEPROM AT24C02。我已经实现了TB3159的解决方案(例3),但是它不工作,因为当I2C2CON2&L:ADB&GT=0(启用地址缓冲区)数据表页567时,您必须设置开始位来启动通信。我把这个代码行添加到下面的代码中:EEPROM地址是0B10100000,ADRYRG=0B000 000 101,数据=0B00 100101。范围信号是:I2C Wr.JPG和I2C写ZOM.JPG.三个“尖峰”是来自EEPROM从机的ACK=0。这些尖峰是奇怪的,但它的工作。读取代码是:见附件的范围信号:I2CRADAD.JPG-读代码停止工作在指令“”()!I2C1STAT1BIT.RXBF);“我检查寄存器I2C1STAT1<RXBF>和PIR5& LT;RXBF & GT;并且两者都是零,如果我已经收到有效数据。寄存器I2C2RXB有一个有效的数据。范围也显示了数据接收任何人知道我可以解决这个问题!提前感谢,最好的挽回
以上来自于百度翻译 以下为原文 hi to all I'm trying to implement a I2C master for the PIC 18F56K42. MPLAB IDE X 4.10 and XC8 1.45. The hardware configuration is Internal OSC 64MHz, I2c with MFINTOSC I2C clock frequency 500kHz and fsck=125kHz and the pull up resistors are 4.7k. Connected to the bus I have MCP23017 and one eeprom AT24c02. I have implemented the solution (example 3) of TB3159, but it doesn't work because you have to set START bit to start the communication when I2C2CON2 void I2C2_Initialize(void) { GIE = 0; PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x00; // unlock PPS I2C2SDAPPSbits.I2C2SDAPPS = 0x19; //RD1->I2C2:SDA2; //11 001 RD1PPS = 0x24; //RD1->I2C2:SDA2; I2C2SCLPPSbits.I2C2SCLPPS = 0x18; //RD0->I2C2:SCL2; 11 000 RD0PPS = 0x23; //RD0->I2C2:SCL2; PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x01; // lock PPS LATD = 0; PORTD = 0; TRISD = 0b00001000; ANSELD = 0x00; ODCOND = 0b00000011; //RD0 e RD1 OD per I2C2 bus SLRCOND = 0b11111100; // Set the I2C levels RD0I2Cbits.TH = 1; RD1I2Cbits.TH = 1; RD0I2Cbits.SLEW = 1; RD1I2Cbits.SLEW = 1; // -- -- -- -- CLK<3:0> // CLK MFINTOSC; I2C2CLK = 0x03; // 0 0 0 0 0 0 1 1 // EN RSEN S CSTR MDR MODE<2:0> I2C2CON0 = 0x04; // 0 0 0 0 0 1 0 0 // ACKCNT ACKDT ACKSTAT ACKT -- RXOV TXU CSD I2C2CON1 = 0x80;// 1 0 0 0 0 0 0 0 // ACNT GCEN FME ADB* SDAHT<3:2> BFRET<1:0> I2C2CON2 = 0x21; // 0 0 1 0 0 0 0 1 I2C2PIR = 0;// ;Clear all the error flags I2C2ERR = 0; I2C2CON0bits.EN = 1; // enable I2C module } void i2c2_write1ByteRegister(uint8_t address, uint8_t adr_reg, uint8_t data) { I2C2ADB1 = address; //The address byte has 8th bit to 0 I2C2CNT = 2; I2C2CON0bits.S = 1; //Start Bit I2C2TXB = adr_reg; while(!I2C2STAT1bits.TXBE); //Wait butter empty I2C2TXB = data; while(!I2C2STAT1bits.TXBE); while(!I2C2PIRbits.PCIF); //Wait stop condition ClrWdt(); } the EEPROM address is 0b10100000, adr_reg = 0b00000101, data = 0b00100101 the scope signals are : I2C write.jpg and i2C write zoom.jpg the three "spikes" are the ACK=0 from EEPROM slave. These spikes are strange but it works. the read code is: uint8_t i2c2_read1ByteRegister(uint8_t address, uint8_t adr_reg) { uint8_t result; I2C2ADB1 = address; I2C2CNT = 1; I2C2CON0bits.S = 1; //Start I2C2CON0bits.RSEN = 1; I2C2TXB = adr_reg; while(!I2C2STAT1bits.TXBE); while(!I2C2CON0bits.MDR); I2C2CNT = 1; I2C2CON0bits.RSEN = 0; I2C2ADB1 = (address| 0x01); //Change the R/W bit for read I2C2CON0bits.S = 1; //Start while (!I2C1STAT1bits.RXBF); result = I2C1RXB; while(!I2C2PIRbits.PCIF); ///WAIT STOP return result; } See attached the scope signals: I2Cread.jpg the read code stop to work at the instruction" while (!I2C1STAT1bits.RXBF);" I check the registers I2C1STAT1 Anyone know I can solve this problem ! Thanks in advance and best reagrds |
|
相关推荐
8个回答
|
|
|
|
|
|
我解决了这个问题,我的错误,我使用的是正确的寄存器:现在我有一个新的奇怪的事情,如果我做了以下的循环:读取例程“I2C2A Read 1ByeTeGistor”停止工作:因为主机收到地址后的NACK。附加范围图像(NACK.JPG)。任何人都知道我可以解决这个问题。谢谢。
以上来自于百度翻译 以下为原文 I solved this problem, my mistake, I used while (!I2C1STAT1bits.RXBF); result = I2C1RXB;while the right registers were : while (!I2C2STAT1bits.RXBF); result = I2C2RXB;Now I have a new strange thing if i do the following cycle: for(;;){ var= 0; i2c2_write1ByteRegister(0b10100000, 0x05, 37); var= i2c2_read1ByteRegister(0b10100000, 0x05); } the read routine "i2c2_read1ByteRegister" stops to work to : while(!I2C2STAT1bits.TXBE);because the master receives a NACK after address. Attached scope image (NACK.jpg). Anyone know i can solve this problem. thanks Attached Image(s) |
|
|
|
TB3159示例和我的工作代码不设置RSEN,轮询RXBF而不是RXBE,并且不轮询MDR。
以上来自于百度翻译 以下为原文 The TB3159 example, and my working code, does not set RSEN, polled RXBF not RXBE, and does not poll MDR |
|
|
|
在向EEPROM写入之后,EEPROM将不在一定的时间间隔内响应进一步的命令。你必须做一个循环,反复尝试对EEPROM进行寻址。在EEPROM数据表中寻找一个叫做“确认轮询”的部分。
以上来自于百度翻译 以下为原文 After you write to the EEPROM there will be a certain time interval in which the EEPROM will not respond to further commands. You have to make a loop that repeatedly tries to address the EEPROM. Look for a section in the EEPROM data sheet called "Acknowledge Polling" or some such thing. Regards, Dave Attached Image(s) |
|
|
|
感谢EEPROM的建议,我只用MC23017做了一个循环:但是没有改变!我试着在这两个函数的末尾加上一个延迟:我测试了它的两个小时的连续循环,它看起来是正确的。这两个延迟是一个非常糟糕的解决方案,任何人都有一个想法,我怎样才能解决这个问题。如果我以随机的方式移除这两个延迟,系统就停止工作到这条线(这个)。是真实的两个功能R/W)谢谢
以上来自于百度翻译 以下为原文 Thanks about the suggestion for the EEPROM. I made a cycle only with MCP23017: for(;;){ var= 0; i2c2_write1ByteRegister(0b01000000, 0x14, 3); var= i2c2_read1ByteRegister(0b10100000, 0x14); } but nothing is changed !! I tried to put a delay at the end of the two functions: for(;;){ var= 0; i2c2_write1ByteRegister(0b01000000, 0x14, 3); __delay_us(200); var= i2c2_read1ByteRegister(0b10100000, 0x14); __delay_us(200); } I tested it for two hours of continue cycle and it seems work correctly. the two delays are a very bad solution, anyone has an idea how can I solve the problem. If I remove the two delays in random way the system stop to work to this line (this is true for both the funtions R/W) while(!I2C2STAT1bits.TXBE); Thanks |
|
|
|
请再读第5页,你没有做建议。
以上来自于百度翻译 以下为原文 Please read post#5 again. You have NOT done what was suggested. |
|
|
|
我删除了EEPROM,我只有MC23017。对于EEPROM,我将用DaveW7X的提示在接下来的几天测试它。
以上来自于百度翻译 以下为原文 I removed the EEPROM I have only MCP23017. For the EEPROM I will test it the next days with the tips from davekw7x. |
|
|
|
我的业余代码的东西可能有助于www. eTeal-OnLim.COM/thReSs/PIC18F25K42-A工作进度。15200
以上来自于百度翻译 以下为原文 My amateur code stuff may help www.electro-tech-online.com/threads/pic18f25k42-a-work-in-progress.152004/ |
|
|
|
只有小组成员才能发言,加入小组>>
5132 浏览 9 评论
1985 浏览 8 评论
1914 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3153 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2213 浏览 5 评论
702浏览 1评论
593浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
476浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
608浏览 0评论
499浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-5 11:23 , Processed in 1.497840 second(s), Total 90, Slave 74 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号