Thanks to Daniels great support do we now have a working solution to store/restore a lot of parameters on EEPROM.
There are anyhow some critera to keep in mind.....
1. A string is not allowed to cross the page boundary on the EEPROM used (boundary bug in EEPROM), control that the string fit into the page (otherwise it will be "wrap around" writing on the page), this example do not cross page boundary.
2. Give the EEPROM time to store the EEPROM buffer, WAIT(20) at least
3. This code is 16 bit address code and is not tested on 8 bit adress EEPROM
4 Firmware version 0.77 is installed
The example-code store and restore 35 parameter (+9,999,999 to -9,999,999) on 24LC256 or 24LC512. The area may be extended up to the size of the EEPROM, Do not change the lenght of the string in the example, change may create unpredicable result
Code: Select all
' Parameter save/restore to EEPROM, procedure for 24LC256 and 24LC512
' ====================================================================
' Conversion of a parameter with signed integer -9,999,999 to +9,999,999
' Parameterarea is saved to EEPROM with a sign + 7 decimal ASCII string
'
' Set up......
DIM myarea(35)=1,9999999,3,-9999999,325205,6,7,8,9,10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,-21,-22,-23,-24,-25,26,27,28,29,30,31,32,33,34,35 ' area....
I2CINIT(400000) 'EEPROM clock 400Khz
I2CTIME(50)
'
' Convert the parameter to a string and write to EEPROM
FOR Index = 1 TO 35
MyPar=myarea(Index) ' get parameter
SSign$=II$(MyPar <0,"-","+") ' check sign
numstring$=STR$(ABS(MyPar)) ' convert parameter to a string
mystring$="0000000"+numstring$ ' add leeding zeros
mystring$=RIGHT$(mystring$,7) ' adjust to a 7 characters string
mystring$=SSign$+ mystring$ ' add sign
'
' Now send the string to EEPROM (under...test)
I2CWR16((0xa0),(Index*8),mystring$,8)
REPEAT
UNTIL I2CBUSY(0xa0)=0
WAIT (20)
NEXT Index
'
WAIT (100) ' Write is done. Now read/convert and Print it
'
' Read EEPROM, convert and print
FOR Index = 1 TO 35
mystring$=""
mystring$=I2CRD16$((0xa0),(Index*8),8)
REPEAT
UNTIL I2CBUSY(0xa0)=0
myarea(Index)=VAL(mystring$)
PRINT Index," ",TAB(15), myarea(Index),TAB(30), " ",mystring$,TAB(50)
WAIT(20)
NEXT Index
END