完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我使用24C04串行EEPROM集成电路。从PIC16LF1847通信。我能写个人数据和页面(最多16字节)。但是,阅读中的问题,尤其是网页阅读。如果我读完整页,即16字节,我已经写了16字节itoEEPROM。即使在复位PIC单片机之后,我也能一直读取数据。但是,如果我只读取部分页面数据,例如6字节,它只读取一次数据。如果重置处理器并重新运行程序,它会挂起。因为设置了一个位。在发出任何命令之前,我正在检查ASPEN和SSPXCON1寄存器的其他位,以了解I2C状态。当我看到SSP1BUF时,它包含了我最初提供的读取EEPROM的地址。如何解决这个问题,我需要您选择合适的串行EEPROM来满足我的以下要求。谢谢,PMK
以上来自于百度翻译 以下为原文 Hi all, I am using 24C04 serial EEPROM IC. Communicating from PIC16LF1847. I can able to write Individual data and Page (up to 16 bytes). But, a problem in reading, especially Page reading. If I read full page i.e. 16 bytes, I have written 16 bytes into EEPROM. I can able to read the data all the time even after resetting the PIC MCU. But, if I read only partial page data for example 6 bytes, it reads the data but only one time. If reset the processor and re-run the program, it hangs. Because ACKEN bit is set. I am checking the ACKEN and other bits of SSPxCON1 register to know the i2c status before issuing any commands. When I see the SSP1BUF, it contains the address I initially supplied to read the EEPROM. How to resolve the issue. //WAIT UNTIL I2C FREE void I2C_Master_Wait(void){ while ((SSP1STAT & 0x04) || (SSP1CON2 & 0x1F)); // while (SSP1STAT & 0x04); } char strData[16]; char Temp; //Read Data unsigned char I2C_Master_Read(unsigned short a){ I2C_Master_Wait(); SSP1CON2bits.RCEN = 1; I2C_Master_Wait(); Temp = SSP1BUF; //Read data from SSPBUF I2C_Master_Wait(); SSP1CON2bits.ACKDT = (a)?0:1; //Acknowledge bit SSP1CON2bits.ACKEN = 1; //Acknowledge sequence return Temp; } // ****************** EEPROM READ CODE ****************** // I2C_Master_Start(); //Start condition // 7 bit EEPROM device address I2C_Master_Write(0xA0 | ((0x00>>7) & 0x0E)); // Address to Read from I2C_Master_Write((unsigned char)0x00 & 0xFF); I2C_Master_RepeatedStart(); //re Start condition // 7 bit EEPROM device address + Read I2C_Master_Write(0xA1); // READ ENTIRE 16 BYTE PAGE for(int j = 0; j < 16; j++){ // SAVE VALUE & SEND ACK FOR NEXT BYTE strData[j] = I2C_Master_Read(1); } SSP1CON2bits.ACKDT = 0; //Nack bit SSP1CON2bits.ACKEN = 1; //Acknowledge sequence I2C_Master_Stop(); // STOP __delay_ms(5); // ****************** EEPROM READ CODE ****************** // I need your suggestion on selecting suitable serial EEPROM for my following requirements. EmployeeID = 4 digits Count = 7 digits Total no of Employee = 9999 (so, 9999 records x 11 digits) thanks, pmk |
|
相关推荐
6个回答
|
|
从数据表,它说,0=确认;1=NoToCal知识;但是,当我使用“0”进行顺序读取时,EEPROM没有应答。相反,我必须使用1来顺序检索正确的数据。我遗漏了什么吗?PMK
以上来自于百度翻译 以下为原文 From datasheet, It says, 0 = Acknowledge; 1 =Not Acknowledge; But, when I use "0" for sequential reading, EEPROM does not reply. strData[j] = I2C_Master_Read(0); Instead, I have to use 1 for retrieving the correct data sequentially. strData[j] = I2C_Master_Read(1); Am I missing anything? pmk Attached Image(s) |
|
|
|
嗨,在I2C.MexMyRead内部有一个确认信号,所以这是错误的:你可以这样做:MySILAOK问题在消息2数据表中是正确的,但是当调用I2C.MistMauleRead(a)时,在I2C.MigMistRead中,有一个代码颠倒倒转:奇怪的构造。(a)?0:1;将测试参数,并使用给定的值,因此当In=0时,I2CyMistar读取(a)a=1;//发送ACK信号;//当接收到字节时发送NACK信号。迈西尔
以上来自于百度翻译 以下为原文 Hi, There is Acknowledge signal made inside I2C_Master_read, so this is wrong: for(int j = 0; j < 16; j++){ // SAVE VALUE & SEND ACK FOR NEXT BYTE strData[j] = I2C_Master_Read(1); } SSP1CON2bits.ACKDT = 0; //Nack bit SSP1CON2bits.ACKEN = 1; //Acknowledge sequence Instead you may do like this: // Read n-1 bytes in loop for(int j = 0; j < (16-1); j++){ // SAVE VALUE & SEND ACK FOR NEXT BYTE strData[j] = I2C_Master_Read(1); } // Fetch last byte and send NAck signal strData[16-1] = I2C_Master_Read(0); Mysil About question in message #2 Datasheet is correct, but when calling: I2C_Master_Read(a); then inside I2C_Master_Read , there is code that turn the argument upside down: SSP1CON2bits.ACKDT = (a)?0:1; //Acknowledge bit The strange construct: (a)?0:1; will test the argument, and use the values given, so argument to I2C_Master_Read(a) a= 1; // Send ACK signal when byte is Received a= 0; // Send NACK signal when byte have been received. Mysil |
|
|
|
谢谢你,Mysil。这两个问题都解决了,但出现了一个新问题。我无法在数组中存储这些值。当我调试时,它正确读取并存储在char温度下。但是当我复制到一个数组中时,它只显示空的。原因何在?谢谢,PMK
以上来自于百度翻译 以下为原文 Thank you Mysil. Both problems solved but a new problem arises. I could not able to store the values in the array. When I debug, It correctly reads and stored in a char Temp. But when I copy into an array, it shows only empty. What could be the reason? thanks, pmk Attached Image(s) |
|
|
|
它试图将数据显示为字符。更改监视窗口将其显示为十六进制值。此外,您的注释表示您正在读取16字节,但是您的代码仅读取6 + 1=7字节。
以上来自于百度翻译 以下为原文 It is trying to display the data as characters. Change the watch window to show it as hex values. Also, your comment says you are reading 16 bytes, but your code is only reading 6+1=7 bytes. |
|
|
|
微笑:哦,天哪。谢谢。它是测试读取记录(读取个人数据,读取整个(16字节)页数据等)。谢谢QYPMK
以上来自于百度翻译 以下为原文 Smile: . Oh my goodness. thank you. It is testing to read records (reading individual data, reading entire (16 byte) page data, etc). thank you qyb pmk |
|
|
|
SHINGEGE构造的HiMimo是具有正逻辑的布尔参数与带有负逻辑的硬件比特之间的转换。只是我的2美分。
以上来自于百度翻译 以下为原文 Hi IMHO that starnge construct is the convertion between a boolean argument with positive logic to the hardware bit with negative logic. Just my 2 cents... Best regards Jorge |
|
|
|
只有小组成员才能发言,加入小组>>
5237 浏览 9 评论
2027 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3202 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
772浏览 1评论
662浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
590浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
672浏览 0评论
572浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 20:58 , Processed in 1.411297 second(s), Total 107, Slave 91 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号