Proton BASIC Compiler - New Article

  • PicŪ Basic

  • Retrieved data does not match entered data

    Storing data in EEPROM (24LCxx) is not very complicated. But it happens that the retrieved data may not match what was stored. After a certain amount of stored data, it seems that some data is corrupted.

    Here is the explanation given by Les on this:

    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.

    contributed by Olivier.