Using EEPROM to store variables...


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125

    Question Using EEPROM to store variables...

    I would like to store some values in EEPROM, and then read these out later when I need them.. The problem is what I I2CWRITE is not what I see when I I2Cread... Where I THINK I store a '1', I see it read back as '127' or '80'...???

    Consider this - I want to store a baud rate for SERIN2 - a value of "16572".

    So, I create a varable:

    WBD var Word ' variable to be stored
    LOC_WBD = 20 ' memory location to store it

    Then I write the value to EEPROM

    Assume: WBD = 16572, then ->

    I2CWrite DPIN, CPIN, CHIP1, LOC_WBD, WBD.byte0
    pause 10
    I2CWrite DPIN, CPIN, CHIP1, LOC_WBD+1, WBD.byte1
    pause 10

    -> I'd EXPECT I just stored the variable 16572 into memory location 20 and 21 (Word)

    THEN to get it back, I'd :

    I2Cread DPIN, CPIN, CHIP1, LOC_WBD, WBD.byte0
    I2Cread DPIN, CPIN, CHIP1, LOC_WBD+1, WBD.byte1


    WBD should be 16572... but it is not. What did I miss?

    Same goes for BYTE sized storage of varables..

    B0 = 1
    LOC_B0 = 22

    I2CWrite DPIN, CPIN, CHIP1, LOC_BO, B0
    pause 10

    ( I think I stored '1' in memory location 22)

    BUT:

    I2Cread DPIN, CPIN, CHIP1, LOC_BO, B0
    LCDout "BO is: ",#BO

    Displays 127 or 80 - not '1'...


    I am missing something FUNDAMENTAL here..

    Tom

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    will be interesting to know your EEPROM model before. Did you read/ compare your code+schematic to the PBP manual before? Have a search in this forum, you'll find a load of answer!!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    http://www.picbasic.co.uk/forum/showthread.php?t=587

    You WILL need pull-up's on the Clock and Data lines (weak pull-up's just don't work reliably here)... 4K7 is recommended.

  4. #4
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Question

    Deeper question - sorry - let me explain..

    The external EEPROM is working.. I am storing and retrieving data. So yes, I know the lines are working, etc. I have pull-ups, etc.

    However, I am trying to KEEP data alive even after power down, and this does not seem to be working 100%. Some survives, some does not!!

    24LC512s - I am using two of them. The software can tell them apart, and know them as 'Chip1', and 'Chip2'. When I write data to the Chips, then retrieve it, I get valid data, even if I fill up both chips. It works fine at a gross level.

    The issue is deeper than if the EEPROM is recording or not - it has to do with saving specific BYTES in EEPROM between power cycles..

    My program writes logging data to the EEPROM in Page Mode. My data is 36 bytes long, so I actually read 3 times into an array of a size of 108 (which works on the 18F2525). That way each page has 108 of the 128 bytes used.

    1. I ALSO want to store some variables that I need BETWEEN power cycles in EEPROM.
    A. the last used memory location, so when I start up again I know where I ws.
    B. the user selected 'baud rate' for download
    C. the 'passthru flag' - tells the code if it should just record to memory only, or also send that data to the serial port.

    SO - I write my LOGGING data in memory positions

    128-64000 - in chip 1 -> saving address 0-127
    0-64000 in chip 2

    I WANT to use the first 'page' on chip one as a place to keep persistent variables. SO I write to the address range 0-127 for these variables.

    The memory locations are defined as:

    Symbol ADR_loc = 10 ' next usable address
    Symbol CHP_loc = 12 ' the chip we are on
    Symbol D_baud_loc = 14 ' the download baud value
    Symbol pass_loc = 20 ' the flag for passthru
    Symbol wpt_loc = 30 ' the flag for waypoints
    Symbol W_baud_loc = 40 ' waypoint baud rate


    Then, I collect data from the user or from the program, and I2CWRITE the data into the memory locations as per above. The PROBLEM seems to be that when I write for example a '1' into "pass_loc", when I I2CREAD that same memory location later DURING the same power cycle, it is fine - it reads back what I'd expect. The PROBLEM is that if I power cycle, the data gets smashed...

    HOWEVER, the data I write in PAGE MODE appears to survive a power cycle....

    Any ideas why?? Can you not save persistent data to EEPROM?

  5. #5
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    . . .Can you not save persistent data to EEPROM?
    of course you can, this is why we use EEPROMs!

    I see several reasons for EEPROM data not being what you expect it to be:

    It has not been written to EEPROM (is your timing ok?)
    or
    it is being overwritten during the power up.

    In both cases there must be something wrong in your code.

    I assume you have already tried a different chip to ensure the EEPROM itself is ok.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  6. #6
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Default

    Have not checked memory - I will. Funny tho how perfectly well it works AS LONG AS I DON'T POWER DOWN.. So the culprit MUST be something in the intitialzation somehow?? hmm.

    Maybe the fact I am declaring the memory locations as SYMBOLS is a problem? When I start up, for example, I declare the memory location to store baud rate as

    wptbd Symbol = 10

    Does this need to be a VARIABLE? I will never write the value for Waypoint Baud to anywhere EXCEPT position 10.. that is so I know where to get it when I need it.

    I saw mention of not using SYMBOLS in I2C..

    ??

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    O.k this is why,

    with your EEPROM, your address must be a word sized variable, so use

    wptbd VAR WORD
    wptbd = 10
    And with wptbd Symbol = 10 written as is you didn't get any compilation error??
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  3. How to write/read strings EEPROM/LCD
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 11th February 2007, 06:26
  4. eeprom how many data can store
    By DragonBall_6 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th December 2006, 11:39
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts