Read\Write Entire EEPROM?
christo1423
Posts: 19
I need to know if it is possible to overwrite the entire EEPROM including the program that is running from the program that is running.I also need to know that if the EEPROM was overwriten with a new program wether or not that program would run.Lastly I need some code to read and write·to and from the EEPROM one byte at a time.The goal of this project is to have locally loadable dynamic code.I have a BS2 so multibanking is not an option and I am hopeing to interface to some higher capicity storage anyways.The information for the overwrite will need to come from this storage medium.·
Comments
So yes, it is possible. Now, the open question is, what happens when the write statements actually hit the executing statements. This will happen ON one of the WRITE statements, and probably erase the final GOTO. I don't know what will happen next.
So no, you can't overwrite the ENTIRE EEPROM, you at least have to leave alone the small executing program that is over-writing it. Now, in theory this small program could be a 'loader', which reads a program from an external eeprom and writes it to the 'local' eeprom, then does a 'GOTO' to the loaded location in the 'local' eeprom.
And the "READ Addr, Databyte" and "WRITE Addr, Databyte" commands do the one-byte at a time thing.
Note you are chasing a "chicken and egg" problem here -- in order to erase the eeprom, you need a program to erase the eeprom.· If you erase the program which is erasing the eeprom, then you have nothing left to load the eeprom from somewhere else.· And the built-in loader only loads the eeprom from the built-in serial port, so I assume you can't use that.
Yup, having a 'loader' as the first thing in each program, then use the first-version 'loader' to load the others (without over-writing the first-version 'loader') should work.
·
Probably not. At some point the program that's running will crash as you start replacing valid tokens with "blank" bytes -- once the program stops, you're toast until reset which may go nowhere fast since you've replaced the program with bad bytes. Get a BS2p-family module; you can read from or write to one bank from another without actually changing banks (use STORE to point to the target bank).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I'm still not sure exactly what you're trying to accomplish, but perhaps you'll find the Stache remote program loader of interest:
http://www.emesystems.com/stache.htm
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Write your 'loader' program (basically, read from serial port (or external EEPROM)) and use the WRITE keyword to write to the EEPROM 'above' a certain address.
Then Click the 'red check' icon to compile, then the 'Percent' icon to bring up a memory map of your compiled program. Scroll the scroll bar all the way to the bottom -- and those are your loader tokens. My simple program, loaded as a test, leaves 7C0 down to 00 free.
So "7C0" becomes that 'certain address' mentioned above.
Now, you'll want to write a 'saver' program, which writes the eeprom space from 7C0 to 00 to an external eeprom.
So, the idea here is every program you write will have the 'loader' portion put in the front. The 'loader' portion will, on some condition (a select switch? A serial port time-out?) decide which external eeprom 'saved' program to load. If you don't want it to load, it will 'GOTO' a destination address following the loader, and run your program.
If you DO want it to load, it will over-write the destination address down to zero with your program read from externall eeprom, and THEN do a 'GOTO' to the same destination address -- which now holds your NEW program.
P.S. Note this process may be 'slow'.· The Bs2P "write to another program slot" approach Jon mentions is probably simpler and more robust.· And we still don't know what you are trying to accomplish by doing all this.· Concievably you can do the same thing just by loading different programs in the·8 program slots of the BS2P, and just selecting which slot to 'run'.
So what are you trying to do?
Post Edited By Moderator (Chris Savage (Parallax)) : 7/12/2005 6:32:47 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Now, some programs are really short, so won't take the entire 2000 bytes. Still, I think you're barking up the wrong tree. Perhaps you should use some other processor, like an SX28 or SX52. These have WAY more memory, run at 50 MIPS, and are cheaper per chip than the BS2.
P.S. Chris has pointed out to me (off-line) that the memory space is actually 2048 bytes, not 2000.· Neat, those 48 bytes will come in handy.
Post Edited (allanlane5) : 7/13/2005 6:43:53 PM GMT