Shop OBEX P1 Docs P2 Docs Learn Events
Multiple EEPROM writes — Parallax Forums

Multiple EEPROM writes

AGCBAGCB Posts: 327
edited 2014-04-19 12:06 in Propeller 1
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

Comments

  • T ChapT Chap Posts: 4,223
    edited 2014-04-12 19:33
    If the value is a byte only, you can add a 1 to each address location you are going to write to. Assuming the time and date are multiple bytes, you will have to increment the addresses by a value that allows room for the largest possible time and date. If you post what you have already we can better give you advise.
  • AGCBAGCB Posts: 327
    edited 2014-04-13 05:13
    I'll do that later today, no time right now. Thanks T-Chap
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-13 08:17
    The EEPROM will automatically advance its own address pointer after each write. You really only need to set the address for the record (0..N) being recorded times the number of bytes in the record. CAVEAT: EEPROMs have page boundaries and you must ensure that your record will fit onto the current page of the EEPROM; if not, part of the record will wrap around to the beginning of the page, damaging other records.
  • AGCBAGCB Posts: 327
    edited 2014-04-13 11:16
    So if I write 7 bytes to the EEPROM, the next time I write 7 bytes they will be in the next 7 address.

    Then reading would be the same provided I start the 1st read at the 1st address, the following will read the next 7 etc?
  • AGCBAGCB Posts: 327
    edited 2014-04-13 11:31
    Am I correct in that the AT24C32, which has 256 pages of 32 bytes each
    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?
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-13 12:28
    What you want to do is called a block write. You start by writing the beginning address, then write the data; the EEPROM will advance it's pointer internally. The same thing happens with a block read, but you have to restart in read mode after writing the first address of the block. Again, be very careful that your block does not overlap a page boundary.

    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.
  • AGCBAGCB Posts: 327
    edited 2014-04-13 12:56
    Thanks Jon. I often use your objects.
    Aaron
  • AGCBAGCB Posts: 327
    edited 2014-04-17 04:41
    Follow-up question

    How do I advance to the next page in a large data write operation?

    Thanks Aaron
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-04-17 06:03
    AGCB wrote: »
    Follow-up question

    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

  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-17 08:05
    How do I advance to the next page in a large data write operation?

    You write the data one byte at a time to ensure that EEPROM address is set.
  • AGCBAGCB Posts: 327
    edited 2014-04-17 12:25
    OK, thanks.
    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
  • AGCBAGCB Posts: 327
    edited 2014-04-19 09:38
    OK, so I think I got the reading and writing figured out pretty good.

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2014-04-19 11:34
    For 128 bytes per page, the addresses are like: $000-$07F, $080-$0FF, $100-$17F, $180-$1FF, etc.
  • AGCBAGCB Posts: 327
    edited 2014-04-19 11:41
    I don't quite understand that

    128 bytes times 8 = 1024 bits or $400. What am I figuring wrong?
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-19 11:54
    EEPROMs are addressed as bytes, not bits.

    The confusing thing is that their size is specified in bits, hence a 24LC512 is 64K bytes (512 x 1024 / 8 = 64K bytes)
  • AGCBAGCB Posts: 327
    edited 2014-04-19 11:57
    So, what are the starting and ending addresses of the 1st 2 lines/pages?
  • AGCBAGCB Posts: 327
    edited 2014-04-19 12:06
    Mike Green wrote: »
    For 128 bytes per page, the addresses are like: $000-$07F, $080-$0FF, $100-$17F, $180-$1FF, etc.

    I see it now!!! Thanks Mike
Sign In or Register to comment.