Shop OBEX P1 Docs P2 Docs Learn Events
Writing Text to EEPROM — Parallax Forums

Writing Text to EEPROM

I've been playing with storing things like product serial number, calibration dates, etc. in the upper 32K of a 64K EEPROM. I'm using Chris Gadd's I2C driver. In the attached example code I have a product date, name, and serial number setup, then write them to the EEPROM. You'll see the demo works perfectly and that's the issue! It seems like to me (and the other resident prop. person) that the date should be written to EEPROM by doing something like:
I2C.writeBytes(EEPROM,DATE_Base,@Prod_Date, 8)

But instead a simple single writeByte works:
I2C.writeByte(EEPROM,DATE_Base,@Prod_Date)

How is this so? The date is "01/19/16", which takes 8 bytes to store. It seems like the code attached should produce garbled non-sense instead of the actual desired result. (I'm really not storing a lot of this as strings, but stumbled on this and can't figure it out!)

Comments

  • The writeByte method writes an immediate value to the EEPROM, in your test you're storing the address of the date string in the EEPROM. Then later on you read that address back out, and pass that address to the PST.str method, which reads the string from the DAT section. So that's how that's working.

    I've verified that the writeBytes method does store the entire string in EEPROM, but it must either be displayed one byte at a time, or read into an array and then displayed as a string:
      i2c.writeBytes(EEPROM,DATE_Base,@Prod_Date, 9)
    
      repeat I from 0 to 7
        pst.char(i2c.readByte(EEPROM,DATE_Base + I))
      pst.char(13)
      i2c.readBytes(EEPROM,DATE_Base,@Array,9)       ' Need to read the null terminator also
      pst.str(@array)
    
  • ChrisGadd wrote: »
    The writeByte method writes an immediate value to the EEPROM, in your test you're storing the address of the date string in the EEPROM. Then later on you read that address back out, and pass that address to the PST.str method, which reads the string from the DAT section.

    Hey Chris. That makes perfect sense. Thank you for the quick and handy explanation! I didn't even remotely think of that possibility.

    Also, thanks for this driver! I use it a lot. Cheers.
Sign In or Register to comment.