Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
I had this problem before. I am not able to read correct values that I want.
Here is the reason why.
Here is the explanation given by Les on thiscopied from www.picbasic.org)
The compiler is not at fault, but your understanding of eeprom access is not complete. Eeproms are not as random access as people think, they work with pages. Some eeproms have a page of 8, 16, 32 or 64 bytes. The 24LC128, and 24LC256 have page boundaries of 64 bytes.
If you examine the datasheet for the eeprom, you will see two forms of writing, PAGE access and RANDOM write. RANDOM writing must be within a 64 byte boundary, and cannot cross it without first sending a stop command and waiting for the memory to be allocated into the eeprom's matrix.
So the boundaries are 0 to 63, 64 to 127, 128 to 191 and so on.
Your code writes in multiples of 6 bytes without a STOP command being sent to the I2C bus, so when the count reaches 64, the eeprom automatically attempts to write a page, and ignores all other commands on the bus until it's finished, but your code is still trying to write another 4 bytes .i.e. 60 to 63.
When performing RANDOM access to an eeprom, it must be on a single byte transfer, any more may violate the protocol.
Reading from an eeprom is truly random access however.
Try altering your code so that the step size is 8 in the for next loop, and write and read 8 bytes at a time. This will cure it.
hi,
The reason of saying that my dataget corrupted is I am able to read and write it correctly out of 100 time 99 time i am able to read the value currectly
There may be many reasons for this.
1) You are not waiting for 10mS for write cycle to get complete before initiating new write cycle.
2) Your I2C clock is too fast. i.e. greater than your EEPROMs speed specification (100kHz or 400kHZ)
3) Write Protect pin of EEPROM is left floating. Even though datasheet mentions that you can keep it floating (internally pulled down), i recommend you to ground it externally or use microcontroller's I/O pin to activate writing only during write cycle.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.