Shop OBEX P1 Docs P2 Docs Learn Events
Simple question on how to use Propeller EEPROM object — Parallax Forums

Simple question on how to use Propeller EEPROM object

SteveWoodroughSteveWoodrough Posts: 190
edited 2013-05-13 21:12 in Propeller 1
Need some help here determining what I’m doing wrong. I’m trying to learn how to save data to EEPROM so I can retrieve it back. Below is the code. It should be pretty straight forward.

Thank You
Steve Woodrough

{{
Experiment to understand how to read and write data to the EEPROM.  Will be used in my Magellan Bot project.

}}

CON                                              ' Constant declarations

  ' System clock settings - 80 MHz
  _clkmode = xtal1 + pll16x                      ' Low speed external crystal 16x PLL
  _xinfreq = 5_000_000                           ' Crystal input frequency is 5 MHz
                     
VAR                                              ' Variable declarations

  long A,B,C,D

OBJ                                              ' Object declarations

  eeprom  : "Propeller Eeprom"                   ' Propeller EEPROM object
  FDS     : "FullDuplexSerialPlus"               ' PST

Pub Main

     FDS.start(31, 30, 0, 115200)

   waitcnt(clkfreq+cnt)                                 'Pause a second

   fds.getstr(string(" "))                              'Wait for enter key
      
  repeat


    fds.str(string(13,"Retrieving data from EEPROM"))
    
    eeprom.FromRam(@A,@D, 0)                            'Should be retrieving whatever is in EEPROM 
  
    fds.str(string(13,"Data retrieved from EEPROM")) 

    fds.str(string(13,"Value of A from EEPROM = "))
    fds.dec(A)
    fds.str(string(13,"Value of B from EEPROM = "))
    fds.dec(B)
    fds.str(string(13,"Value of C from EEPROM = "))
    fds.dec(C)

  
  
    fds.str(string(13,"Enter A",13))
    A:=fds.getdec
    fds.str(string("Enter B",13)) 
    B:=fds.getdec    
    fds.str(string("Product is = "))

    C:=A*B
    fds.dec(C)
    
    fds.str(string(13,"Saving data to EEPROM"))
    
    eeprom.FromRam(@A,@D, 0)                            'Should be writng variable data to EEPROM
    
    fds.str(string(13,"Data saved to EEPROM"))

    A:=B:=C:=D:=0                                       'Zero out values


Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-05-13 20:35
    Retrieval from EEPROM is done using the ToRAM method (you have two instances of FromRAM). Also, depending on what EEPROM you are talking to address zero+ may be a bad choice for variable storage.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-05-13 21:00
    You really don't want to be writing to location zero. You won't be able to restart the Prop without loading a program from the PC.

    To save your variable "A" to EEPROM in the same location in the EEPROM use:
    eeprom.fromram(@A, @A + 3, @A)
    

    You need to add the "+ 3" to include the three additional bytes in the long besides the byte located at @A.

    To read this data back from EEPROM use:
    eeprom.toram(@A, @A + 3, @A)
    

    If you want to use free sections of the EEPROM that won't be overwritten when you save a new program, use addresses higher than $8000 (assuming your have a 64K EEPROM).

    So to write your variable "A" to upper EEPROM, use:
    eeprom.fromram(@A, @A + 3, $8000)
    

    To write all four variables to upper EEPROM, use:
    eeprom.fromram(@A, @A + 15, $8000)
    

    or
    eeprom.fromram(@A, @D + 3, $8000)
    
  • SteveWoodroughSteveWoodrough Posts: 190
    edited 2013-05-13 21:01
    THANK YOU! I really should not trying to code new stuff after 10 PM. Just silly errors.
    Thank you for taking the time.

    Point taken on the choice of address. I'll move it up the range. I was just trying to get a result to get a feel for the object.

    Regards,
    Steve
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-05-13 21:12
    If you have a 32K EEPROM, writing to $8000 will actually write to location zero. Most Propeller boards Parallax sells have 64K EEPROMs. If you don't know the size of your EEPROM you can find out with the program attached to post #24 of this thread.

    Don't use the program as a guide to using EEPROM. It's full of bugs. The part which checks the size of the EEPROM works but not much else.
Sign In or Register to comment.