Shop OBEX P1 Docs P2 Docs Learn Events
Writing sensor data to a 25LC640 EEPROM — Parallax Forums

Writing sensor data to a 25LC640 EEPROM

Robert@HCCRobert@HCC Posts: 80
edited 2005-12-24 10:49 in BASIC Stamp
I have a Microchip 25LC640 EEPROM I am learning to use with the BS2. So far, I have been able to R/W by storing a value in a variable, incrementing the value in the variable, while incrementing the address. I have been able to confirm what I am doing by using the debug window, as well as reading the stored value into StampDaq.

But for the life of me, I cant seem to get a hold on to how I can grab data from my sensors ( Sensirion SHT1x temp/humidity, Memsic accellerometer) and into the variable "EEPROM_data" and write it to the EEPROM.

For instance this is my code to write:

WriteEEPROM:
  GOSUB EEPROMreadstatus
  IF EEPROM_Busy =1 THEN WriteEEPROM
  LOW CS
  SHIFTOUT SerData,SerClk,MSBFIRST,[noparse][[/noparse]WREN_EEPROM]
  HIGH CS
  LOW CS
  SHIFTOUT SerData,SerClk,MSBFIRST,
  [noparse][[/noparse]Write_EEPROM,Address\16,EEPROM_data\8]
  HIGH CS
RETURN



And what I get after processing the temp data in the subroutines :

GOSUB SHT_Measure_Celcius
  PAUSE 500
  SEROUT TxD, Baud48, [noparse][[/noparse] MoveTo, 0, 3]
  SEROUT TxD, Baud48, [noparse][[/noparse] "Deg C...  ",
  DEC (info / 10), ".", DEC1 info, DegSym,CR]




Can anyone give me some pointers on how I can grab that data in the last SEROUT and write to the EEPROM?
I am trying to display the data during collection, but would also like to store the data for later processing in StampDAQ.
Aloha, and thanks for any replies!
Robert

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-12-23 13:49
    Robert -

    Adding routines to a program given only a few select existing subroutines is difficult t best, but the fact that the routine labelled "SHT_Measure_Celcius" is missing, makes it all the more difficult. At least two variables (possibly more) are derived from that subroutine:
    "MoveTo", and "Info", which lack sufficient self-documentation in naming, that I'm not sure what they are.

    Try posting all of what you have either inline as you did, or as an attachment and we'll HELP you put the jigsaw puzzle together.

    The basic program flow will be something like this:

    All below, "if necessary"

    Initialize variables
    Initialize sensor(s)
    Initialize LCD
    Pause

    Set-up sensor for a reading
    Fetch sensor information
    Manipulate retrieved information

    Set-up EEPROM addressing information
    Increment EEPROM store address
    Store necessary information in EEPROM
    Pause
    Ensure write was completed

    Set-up information to be displayed
    Establish cursor position and data spacing
    Write necessary data fields
    Pause

    Reset variables
    Pause
    Repeat next iteration when necessary

    That should be most of it. I hope that's enough to get you started thinking about the structure of the soon-to-be program.

    Regards,

    Bruce Bates
  • Robert@HCCRobert@HCC Posts: 80
    edited 2005-12-23 14:27
    Yeah - that was my thought, that posting those snippets wasnt enough. I am on a 28kbs connect (free college internet service lol ) , so this post timesout if I try to attach or post the full code..
    I actually have all the sensors working - just want to add a datalogging function since I have some EEPROMS laying about. But like I said, still learning here.... tongue.gif
    I will post the complete code tommorow when I will be on a faster connect.
    Aloha,
    Robert
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-12-23 17:09
    It should be pretty easy, really. After you call the routine that reads the temperature from the SHT, you will have the reading in the variable you call "info". Then set your variable "EEPROM_data" equal to that and call your WriteEEPROM subroutine.
    GOSUB SHT_Measure_Celcius
      EEPROM_data = info
       GOSUB WriteEEPROM
     GOSUB SHT_Measure_RH
      EEPROM_data = info
       GOSUB WriteEEPROM
    




    The only thing is, you will probably want to make EEPROM_data a Word variable, so that it can handle a full range of values including negative.
    SHIFTOUT SerData,SerClk,MSBFIRST, [noparse][[/noparse]Write_EEPROM,Address\16,EEPROM_data\16]   '< note \16 for the data!!!
      Address = Address+2  ' note address increments by 2!
    


    That is not essential but if you use bytes you have to be sure the data is compressed to fit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Robert@HCCRobert@HCC Posts: 80
    edited 2005-12-24 10:49
    Sweet!! I was hoping you would stop in here Mr. Allen, as I knew you where very familiar with the SHT1x , as well as the src.

    My main problem as I worked through ( and lost some hairs, but mostly grey ,so no prob) this was my variables for the sensors were word-sized, and my EEPROM routine wrote the data a byte at a time! I had setup code like your first example, but but could not grab the data properly.

    I think I just had one... no two.. of those "AHA!! moments Jon Williams talks about in his NV articles- usually after pounding in " read th e datasheets, manuals, etc"

    I figured out that part about :
    SHIFTOUT SerData,SerClk,MSBFIRST, [noparse][[/noparse]Write_EEPROM,Address\16,EEPROM_data\16]
    



    and changing the 8 to 16 , but never figured out that I would have to increment address by two instead of one! makes perfect sense now, of course [noparse]:D[/noparse] Excellent!

    I also figured out that I could write a subroutine that split my word-sized variable "info" into "info.HIGHBYTE" and "info.LOWBYTE" then send it to the Write_EEPROM subroutine for further processing like so:
    info         VAR   Word     
    infoL       VAR  info.HIGHBYTE
    infoH       VAR info.LOWBYTE
    
    
    storetemp:                              'store temp to EEPROM
      EEPROM_data = infoH          'High byte of TEMP
      GOSUB writeEEPROM             'write high byte to memory
      address = address +1            'increment address
      EEPROM_data = infoL           'Low btye of TEMP
      GOSUB writeEEPROM             'write low byte to memory
      address = address +1            'increment address
    RETURN
    
    



    All in all, and excellent learning experience, and I now have two ways to process my data - gonna test out your solution now, Tracy....iT seems much more..well, cleaner than mine!
    Thank you!
    and then I am off to play with some I2C EEPROMS for a change of pace. :O

    Thank you one and all for your replies!
    Robert Allen <
    seems to be alot of those here tongue.gif

    Post Edited (Robert@HCC) : 12/24/2005 10:56:14 AM GMT
Sign In or Register to comment.