How to store/read numerical parameters from EEPROM ?
How to store/read numerical parameters from EEPROM ?
Hi
Is there any way or method to store/read up to 20 unsigned numbers in the internal EEPROM area (4k) or to add an external flashmemory for storage. I need to save 20 parameters before power down and reload them at next power up.
This must be under control of the basicprogram and not limited to preload of config strings.
I have the EZSBC1 board with the basic interpreter and this is my only problem so far....
Thanks for any advice
Borje
Is there any way or method to store/read up to 20 unsigned numbers in the internal EEPROM area (4k) or to add an external flashmemory for storage. I need to save 20 parameters before power down and reload them at next power up.
This must be under control of the basicprogram and not limited to preload of config strings.
I have the EZSBC1 board with the basic interpreter and this is my only problem so far....
Thanks for any advice
Borje
Last edited by Borje on Sun Nov 10, 2013 11:53 am, edited 1 time in total.
Re: How to store/read numerical parameters from EEPROM ?
Hi
There is no method for writing to the 4k internal memory set aside for the configuration strings. The reason is that the memory is Flash, not EEPROM and can not be written a byte at a time and it can only be erased in large blocks, 4k is the smallest size.
Later today I will post some code to read and write from integers to and from an external EEPROM. In Control-BASIC all numbers are at least 32-bit integers so I will read and write 32-bit numbers from the EEPROM.
Is there a particular EEPROM that you prefer? If not I will use one of the low cost I2C ones for the example.
Daniel
There is no method for writing to the 4k internal memory set aside for the configuration strings. The reason is that the memory is Flash, not EEPROM and can not be written a byte at a time and it can only be erased in large blocks, 4k is the smallest size.
Later today I will post some code to read and write from integers to and from an external EEPROM. In Control-BASIC all numbers are at least 32-bit integers so I will read and write 32-bit numbers from the EEPROM.
Is there a particular EEPROM that you prefer? If not I will use one of the low cost I2C ones for the example.
Daniel
Re: How to store/read numerical parameters from EEPROM ?
Thank you for Your fast feedback
There are no particular EEPROM selected so I can use any type that You propose and that will work well.
I need to store parameters for calibration, setpoint, position, speed and so on... and they can be scaled to be 32 bit integers.
I assume that its a common need for many users to save/restore some parameters so an example code will be helpfull
Best regards
Borje
There are no particular EEPROM selected so I can use any type that You propose and that will work well.
I need to store parameters for calibration, setpoint, position, speed and so on... and they can be scaled to be 32 bit integers.
I assume that its a common need for many users to save/restore some parameters so an example code will be helpfull
Best regards
Borje
Re: How to store/read numerical parameters from EEPROM ?
Hi Daniel
After that I have reading the manual and the list of commands several times is my own conclusion that I strongly believe that there are no direct command to, in an easy way, read/write a 32 bit parameter to and from an external EEPROM (Please correct me if I am wrong).
My conclusion is that that a workaround must be used and that the parameter must be converted to a string and saved/read as a string via I2C to an external EEPROM.
Its not a big deal with that and it's acceptable due to that the procedure will only be used at power up and power down.
I am working on such a procedure now but can't test it yet, I am still waiting for my controllers and project board to arrive.
I have a question related to this issue:
In the manual is stated (or maybe not clarified) that only a single byte address (8 bit) is used in the I2C register-address command . Several EEPROM (larger then 2Kb and 4 Kb) use two byte for address. There are only a few older EEPROM's that can be used if this limitation is true.
I have now 24LC04B, 4 Kb EEPROM, with bank-mapping (2*256 bytes bank) controlled by one additional adressbit in the device-address (A-B-C) byte that will work for me and that allow me to use in total 512 bytes of external memory (will allow me to store 50 parameters with 10 character)
Is my understanding of the address issue correct ? Do You have intention to allow two byte addressing in the future ?
Am I on the wrong track now ?
Any comments is welcome
Borje
After that I have reading the manual and the list of commands several times is my own conclusion that I strongly believe that there are no direct command to, in an easy way, read/write a 32 bit parameter to and from an external EEPROM (Please correct me if I am wrong).
My conclusion is that that a workaround must be used and that the parameter must be converted to a string and saved/read as a string via I2C to an external EEPROM.
Its not a big deal with that and it's acceptable due to that the procedure will only be used at power up and power down.
I am working on such a procedure now but can't test it yet, I am still waiting for my controllers and project board to arrive.
I have a question related to this issue:
In the manual is stated (or maybe not clarified) that only a single byte address (8 bit) is used in the I2C register-address command . Several EEPROM (larger then 2Kb and 4 Kb) use two byte for address. There are only a few older EEPROM's that can be used if this limitation is true.
I have now 24LC04B, 4 Kb EEPROM, with bank-mapping (2*256 bytes bank) controlled by one additional adressbit in the device-address (A-B-C) byte that will work for me and that allow me to use in total 512 bytes of external memory (will allow me to store 50 parameters with 10 character)
Is my understanding of the address issue correct ? Do You have intention to allow two byte addressing in the future ?
Am I on the wrong track now ?
Any comments is welcome
Borje
-
- Posts: 37
- Joined: Thu Nov 01, 2012 10:57 am
- Location: Johannesburg, South Africa
Re: How to store/read numerical parameters from EEPROM ?
Hi Borje.
I can confirm that the current address parameter of the Conrtol Basic I2C command is restricted a single byte (8bit) address, which limits its use to EEPROMs with a single byte address only. EEPROM devices using a two byte address cannot be addressed.
Here is a little demo prog that I used when playing around with the 24LC08 chip some time ago:
Hope this will be of some help.
Best regards
Andries
I can confirm that the current address parameter of the Conrtol Basic I2C command is restricted a single byte (8bit) address, which limits its use to EEPROMs with a single byte address only. EEPROM devices using a two byte address cannot be addressed.
Here is a little demo prog that I used when playing around with the 24LC08 chip some time ago:
Code: Select all
'* Only suitable for EEPROM chips with one byte address *
'The 24LC08 has 4 pages of 255 bytes each.
'The example will write to the first 10 memory
'locations of all 4 pages then
'read back and print to the terminal window.
'Each page is accessed with A0,A1 and A2 internally. So
'the control bits change for each page.
I2CINIT(400000) ' Set Max clock speed to 400kHz
I2CTIME(1)
CLRSCR
PRINT "Writing......"
FOR i=0 TO 9
I2CWR(0xa0,i,CHR$(i),1) ' Page1
REPEAT
UNTIL I2CBUSY(0xa0)=0
I2CWR(0xa2,i,CHR$(i),1) ' Page2
REPEAT
UNTIL I2CBUSY(0xa2)=0
I2CWR(0xa4,i,CHR$(i),1) ' Page3
REPEAT
UNTIL I2CBUSY(0xa4)=0
I2CWR(0xa6,i,CHR$(i),1) ' Page4
REPEAT
UNTIL I2CBUSY(0xa6)=0
NEXT i
'DELAY 8000
CLRSCR
PRINT "Reading......."
FOR i = 0 TO 9
a$=I2CRD$(0xa0, i, 1)
PRINT ASCII(a$,1)," ";
NEXT i
PRINT " PAGE 1 : b10100000 = 0xa0"
FOR i = 0 TO 9
a$=I2CRD$(0xa2, i, 1)
PRINT ASCII(a$,1)," ";
NEXT i
PRINT " PAGE 2 : b10100010 = 0xa2 "
FOR i = 0 TO 9
a$=I2CRD$(0xa4, i, 1)
PRINT ASCII(a$,1)," ";
NEXT i
PRINT " PAGE 3 : b10100100 = 0xa4"
FOR i = 0 TO 9
a$=I2CRD$(0xa6, i, 1)
PRINT ASCII(a$,1)," ";
NEXT i
PRINT " PAGE 4 : b10100110 = 0xa6"
END
Best regards
Andries
Re: How to store/read numerical parameters from EEPROM ?
Thank you Andries, your code was helpfull, it saved me a lot of work .
My controller has now arrived and I was able to test my code package for save and restore integer data on EEPROM and everything works fine.
I will post the code when I know how to do it. I set the resolution in the conversion to 6 byte string (0-999999) due to other limitations in my application but it can easy be set to 10 bits in code.
I also decided to upgrade the EEPROM to 24LS16 2K*8 to allow up to 2Kbyte data (8 pages of 255 bytes), to have some space left over for strings and constants in the future
I am now waiting for my new EEPROM 24LS16 to do the final test
How do you do to add the a "code window" like yours to the Post ?
Thanks a lot for your kind support
Borje
My controller has now arrived and I was able to test my code package for save and restore integer data on EEPROM and everything works fine.
I will post the code when I know how to do it. I set the resolution in the conversion to 6 byte string (0-999999) due to other limitations in my application but it can easy be set to 10 bits in code.
I also decided to upgrade the EEPROM to 24LS16 2K*8 to allow up to 2Kbyte data (8 pages of 255 bytes), to have some space left over for strings and constants in the future
I am now waiting for my new EEPROM 24LS16 to do the final test
How do you do to add the a "code window" like yours to the Post ?
Thanks a lot for your kind support
Borje
-
- Posts: 37
- Joined: Thu Nov 01, 2012 10:57 am
- Location: Johannesburg, South Africa
Re: How to store/read numerical parameters from EEPROM ?
Its a pleasure Borje. I just hope that my code still works. Have not tested in in some time.
To activate code window, just open the POSTREPLY editor, press the Code button A and the text in B will be inserted. Now just paste your code between the square brackets at point B. Press Preview to see the result and then press Submit.
Best regards
Andries Pretorius
To activate code window, just open the POSTREPLY editor, press the Code button A and the text in B will be inserted. Now just paste your code between the square brackets at point B. Press Preview to see the result and then press Submit.
Best regards
Andries Pretorius
Re: How to store/read numerical parameters from EEPROM ?
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
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
Last edited by Borje on Fri Nov 22, 2013 4:22 am, edited 1 time in total.
Re: How to store/read numerical parameters from EEPROM ?
A comment only, the exemple-code can store any decimal number within -9999999 to 9999999 and is not limited to integers only, the stringlenght is fixed and is allways 8 characters including sign and any decimalpoint. ( a parameter can hold: 0.34, 3.14267, -9.12345, 0, -0.00001 or 9999999...)
Last edited by Borje on Fri Nov 22, 2013 11:32 pm, edited 4 times in total.
-
- Posts: 37
- Joined: Thu Nov 01, 2012 10:57 am
- Location: Johannesburg, South Africa
Re: How to store/read numerical parameters from EEPROM ?
Thank you for your feedback Borje. I also now operate the same firmware version and I have tested your program using a 24LC512.
The question of recognising the page boundaries of the EEPROM is quite important. Please refer the following article using an Arduino example:
www.hobbytronics.co.uk/eeprom-page-write
I'm glad that the matter has been resolved.
Best regards
Andries
The question of recognising the page boundaries of the EEPROM is quite important. Please refer the following article using an Arduino example:
www.hobbytronics.co.uk/eeprom-page-write
I'm glad that the matter has been resolved.
Best regards
Andries