Shop OBEX P1 Docs P2 Docs Learn Events
Saving data to Proto board EEPROM — Parallax Forums

Saving data to Proto board EEPROM

EBEB Posts: 8
edited 2008-08-08 22:43 in Propeller 1
I'm trying to save the entire DAT section of a Spin program to the top (i.e. unused) 32k of the 64k EEPROM on the Propeller Proto board. Using the Basic_I2C_Driver from the object exchange, I have two sections:

To read:
· i2c.Initialize(i2c#BootPin)
· iTemp := i2c.ReadByte(i2c#BootPin, i2c#EEPROM, eeprom_dat)
· if iTemp == first_byte
··· if i2c.ReadPage(i2c#BootPin, i2c#EEPROM, eeprom_dat, @first_byte, dat_size)
····· bytemove(@msg_buffer, string($C, 1, "Read failed"), 14)
··· else
····· bytemove(@msg_buffer, string($C, 6, "Settings loaded from last save"), 32)
· else
··· bytemove(@msg_buffer, string($C, 6, "Loaded default settings"), 25)
And to write:
· i2c.Initialize(i2c#BootPin)
· if i2c.WritePage(i2c#BootPin, i2c#EEPROM, eeprom_dat, @first_byte, dat_size)
··· bytemove(@msg_buffer, string($C, 1, "Write failed "), 16)
· else
··· startTime := cnt ' prepare to check for a timeout
··

· · repeat while i2c.WriteWait(i2c#BootPin, i2c#EEPROM, eeprom_dat)
····· if cnt - startTime > clkfreq / 10
······· bytemove(@msg_buffer, string($C, 1, "Write timed out"), 18)



The variables are....
  • eeprom_dat = $8000
  • dat_size = @last_byte - @first_byte
  • first_byte is a single byte at the begining of the DAT block
  • last_byte is a single byte and the end of the DAT block
  • msg_buffer is a 32 byte DAT variable for storing messages to the user

The problem is this: both the read and write both claim not to fail, but the data seems not to make it through the round trip.

Any ideas?


Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-08 22:43
    WritePage writes a single EEPROM page at a time. As described in the comments, the page size varies from EEPROM model to EEPROM model, but typically is 128 or 256 bytes. If you try to write outside the page, the internal EEPROM buffer wraps around to the beginning of the page. You're starting at $8000 which is always the beginning of a page. Try putting the IF statement with the WritePage in a REPEAT loop where it writes 128 bytes at a time, waits for the write to finish, then does the next block of 128.
Sign In or Register to comment.