storing data in RAM
shmow
Posts: 109
Hey y'all,
I just need a little clarity on storing data in EEPROM.
Here's a little sample code that I've tested - and it works.
The only problem - I think - is the location where the data is stored in the eeprom. It must conflict with the code.
I say that after pasting parts of this code into another program I'm running.
The other program runs perfectly fine until I store data in the eeprom.
The value I have for the variable eepromaddress is 0, or can it be $0000 - $7FFF? In any case there's a conflict.
If you have any suggestions then by gosh I'm all ears.
Regards,
Shmow
Sample code below:
I just need a little clarity on storing data in EEPROM.
Here's a little sample code that I've tested - and it works.
The only problem - I think - is the location where the data is stored in the eeprom. It must conflict with the code.
I say that after pasting parts of this code into another program I'm running.
The other program runs perfectly fine until I store data in the eeprom.
The value I have for the variable eepromaddress is 0, or can it be $0000 - $7FFF? In any case there's a conflict.
If you have any suggestions then by gosh I'm all ears.
Regards,
Shmow
Sample code below:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 SCL = 28 StoreData = 255 'VALUE TO BE STORED IN EEPROM eepromaddress = 0 VAR byte buffer[noparse][[/noparse]32] byte retrievedData OBJ i2c : "Minimal_I2C_Driver" sio : "FullDuplexSerialPlus" PUB Main sio.start(31,30,0,115200) i2c.initialize(SCL) ' i2c.readit dira[noparse][[/noparse]16..17]~~ ' INDICATOR LIGHT TO SHOW PROGRAM WILL START IN 4 SECONDS ' GIVES ME TIME TO OPEN PARALLAX SERIAL TERMINAL outa[noparse][[/noparse]17]~~ waitcnt(clkfreq*4+cnt) outa[noparse][[/noparse]17]~ repeat ' WHEN BUTTON IS PRESSED, VALUE OF 255 IS STORED IN EEPROM if ina[noparse][[/noparse]0] == 1 StoreVal waitcnt(clkfreq*3+cnt) else ' WHEN BUTTON IS NOT PRESSED, RETRIEVED DATA IS DISPLAYED ON PST (PARALLAX SERIAL TERMINAL) RetrieveVal PRI StoreVal buffer[noparse][[/noparse]eepromAddress // 32] := 255 writeIt PRI RetrieveVal ' VARIABLE IS ASSIGNED VALUE AT BUFFER LOCATION 32 readit retrievedData := buffer[noparse][[/noparse]eepromAddress // 32] ' SHOW DATA ON P SERIAL TERMINAL sio.dec(retrievedData) sio.Str(string(13," ",13,13)) waitcnt(clkfreq+cnt) PRI readIt if i2c.ReadPage(i2c#BootPin, i2c#EEPROM, eepromAddress, @buffer, 32) abort ' an error occurred during the read PRI writeIt | startTime if i2c.WritePage(i2c#BootPin, i2c#EEPROM, eepromAddress, @buffer, 32) abort ' an error occured during the write startTime := cnt ' prepare to check for a timeout repeat while i2c.WriteWait(i2c#BootPin, i2c#EEPROM, eepromAddress) if cnt - startTime > clkfreq / 10 abort ' waited more than a 1/10 second for the write to finish
Comments
Yes, you program is messing up the program stored in EEPROM.