|
|
View previous topic :: View next topic |
Author |
Message |
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
Copying eeprom contents |
Posted: Wed Jun 22, 2016 1:48 pm |
|
|
Hi, I am storing info in 30 eeprom locations. There are a mixture of floats, bools, int8's etc.
I want to be able to send that data down a serial port to the computer to which it is connected (a Raspberry Pi), so I can save it to disc and then be able to send it back again to rewrite the eeprom locations.
I am using a 18LF2620.
What's the best way of doing it please?
Thanks
Brian |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Jun 22, 2016 2:42 pm |
|
|
hmm.. there is no 'best' way... but if the 30 locations are 8bits ( byte) simply just send them.... now the 'fun' part is the 'other end' that will have to decide which bytes are 'floats',bools,bytes, words.....
Obviously the 'bools' should be 'grouped' into 8 bits ( a byte) so as to look like one byte.
Now do you need error checking like CRC ? That will complicate things a tad...
Jay |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
EEprom data |
Posted: Wed Jun 22, 2016 3:21 pm |
|
|
Thanks for your reply but Oh dear!!
All I want to do is to store the contents of those 30 locations and be able to write those 30 locations back. No processing is needed as it's simply to allow the eeprom data to be replaced if needed, so is it not possible to do a memcpy?
I could send each datatype in sequence but it's a lot of code to achieve it!
Thanks for your help.
Brian |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Jun 22, 2016 6:11 pm |
|
|
make a string[30]
create int16 checksum=0;
read each eeprom location into the string
serial printf the bytes of the string sequentially
using %X format yielding 2 bytes of hex per eeprom location.
as you increment- add the byte value to checksum.
when all 60 byes of hex are written - output the 16 bits as 4 bytes of
checksum -in hex also.
reverse the process to restore eeprom- but first read into a string in sram and verify the simple checksum. it's all you need with a short serial connection and a low baud rate... |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
Re: EEprom data |
Posted: Thu Jun 23, 2016 1:49 am |
|
|
BLL wrote: | is it not possible to do a memcpy? |
No, data EEPROM is not RAM and requires special code to read, and most importantly, write it.
Yes, you can treat it as a region of simple bytes, and not bother about the type of data it contains, but you cannot dump to it wholesale using memcpy or anything like that.
I don't dump eeprom like this in my applications. I always do it as specific types of related functionality. One reason for this is that it allow me to change my implementation, my coding, if I want or need to. It also allows me to transfer data in relevant engineering units rather than, say, ADC counts. A third advantage is that it provides some future proofing. In your case, I would not transfer just those 30 bytes, I'd do at least 32, and probably 64. The currently unused 2 or 66 would be spares for future expansion, because you just know you might need to save something else sometime.
Sending a simple datastream is indeed simple, but not robust. What happens if something gets corrupted? How do the two ends know that they have received good data and not a recipe for rice pudding? Writing to eeprom is not fast, it takes about 4-5ms per byte. So, do you read the incoming data and write it to EEPROM as you go along, in which case how to you make sure everything remains in sync? Or do you store incoming data in RAM buffer and write it to EEPROM later, once you'd got it all? If so, how does the sending end know if what it sent was okay? These are all simple things, which can be solved many ways, depending on your systems design, so we can't give you a "best" way. |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
EEprom |
Posted: Thu Jun 23, 2016 2:54 am |
|
|
Hi, Thanks for your thoughts on it. It seems that I would be well advised to continue doing it as I am, sending each value in a comma delimited string. It's a bit long-winded but it does work!
Thanks again for your help.
Brian |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Thu Jun 23, 2016 5:15 am |
|
|
For a data logger project I used a Vinculum/flash drive for storage. Using the 'Comma Separated Variables' was THE way to store the data ! Once stored, pull drive, push into USB port of PC and eXcel KNEW the data and 'arranged' it all for me !
The other benefit was it was easy to add variables to the list, simple printf...... lines of code, all easy to see and read, something these old eyes appreciate !
Heck, if what you have WORKS , don't get 'fancy'. YOU understand how it works so unless there's a critical reason to upgrade, don't bother !
Jay |
|
|
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
EEprom |
Posted: Thu Jun 23, 2016 9:43 am |
|
|
Yes, I agree with you. I was just trying to make the code smaller, but, as you say, it works, so it will do!
Brian |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|