Multiple EEPROM writes
AGCB
Posts: 327
I am working on a program that records the time and date of events using a RTC and EEPROM. I have been able to make it work with one event but would like to record multiple events on the EEPROM and then be able to read them later. How do I advance the EEPROM address between writes ?. Is it as simple as adding a constant number each time? And then the same for reading it?
Thanks Aaron
Thanks Aaron
Comments
Then reading would be the same provided I start the 1st read at the 1st address, the following will read the next 7 etc?
I can write up to 4 events of 7 bytes each and then must start a new page to write the next 4 events?
If I advance a variable at each write and then test for =<4 before each write, I'll know when to start at a new base address?
Yes, that EEPROM has 32-byte pages, so if your record is 7 bytes, using block writes you could only fit four records into a page. It's slower, but you could do individual byte writes (which resets the EEPROM address pointer on every write) and not have to worry about page boundary issues.
For my projects I use a 24LC512 (64K) EEPROM which lets me put the program in the lower half and non-volatile (even betwee program updates) data in the upper half. I've attached my eeprom and i2c objects as they may be helpful.
Aaron
How do I advance to the next page in a large data write operation?
Thanks Aaron
I don't know why you aren't just using normal byte or even long write operations whereby the address is supplied each write. I've just done an access control system using RFID cards and I just use the top 32k of a 64kB EEPROM that's used for the Prop boot. I have methods for byte or long writes and I write the time stamp as one long comprised of 2 bytes (11 bits of minutes, 5 bits for the day of the month) and a card index byte and a log code byte such "O" for open etc. To make it easier to keep track of where the end of the log is I write a -1 as a long (32-bits) after the last entry to indicate end-of-file and then at startup I just scan through until I find this blank long and set a write pointer with a mask for wrap-around. It's done this way rather than maintaining a write pointer in EEPROM to make sure the same location is not "worn out".
Here's a sample of a log report via Bluetooth which also shows the gate being opening automatically at 8 in the morning and closing at 11 at night. The card index byte is translated back into the card number using another EEPROM file which has a list of all the valid cards.
.LOGS
16-15:23 R #000 ********
<snip>
16-18:04 M #017 06201860
16-18:08 R #000 ********
16-18:08 O #000 ********
16-23:00 C #000 ********
16-23:17 M #017 06201860
17-08:00 O #000 ********
17-22:39 R #000 ******** ok
You write the data one byte at a time to ensure that EEPROM address is set.
I think I'm getting the idea. Maybe making the address in the EEPROM for different items a constant to use in the write/read calls would take the human memory work out of it.
Thanks, Aaron
Now I'd like to get inside the EEPROM memory with my brain and cruise around the town. So here are a few things I think are true but I may be off my rocker.
For a 32 byte per page EEPROM, is this what the 1st 3 pages look like? The left column being the base?
0000 01 02 03 04 05 ~~~~~~~~~~~~~~~~ ~~ 0d 0E 0F
0010 11 12 13 14 ~~~~~~~~~~~~~~~~~~~~ 1D 1E 1F
0020 21 22 23 24 ~~~~~~~~~~~~~~~~~~~~~~~ 2E 2F
And for a 128 byte per page EEPROM like a 24LC512
0000 0001 0002 0003 ~~~~~~~~~~~~~~~~~~~~~ 3FD 3FE 3FF
0400 0401 0402 0403 ~~~~~~~~~~~~~~~~ ~~ 04FD 04FE 04FF
0500 0501 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 05FF
0600
~~
~~
~~
FF00 FF01 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FFFF
Thanks for your time in looking!
Aaron
128 bytes times 8 = 1024 bits or $400. What am I figuring wrong?
The confusing thing is that their size is specified in bits, hence a 24LC512 is 64K bytes (512 x 1024 / 8 = 64K bytes)
I see it now!!! Thanks Mike