Saving data to Proto board EEPROM
EB
Posts: 8
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....
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?
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