Using external EEprom - need a little guidance


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Using external EEprom - need a little guidance

    Guys, having a blonde moment here....

    I want to save data to an external chip, a 24c256 EEPROM, but I can't seem to make it work the way I currently save data to the flash in the PIC.

    Using a DS1307 RTC as an example I2CWrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,RTCCtrl] works fine as each time the update is made it writes the complete string of variables so they remain in the correct order when read back. However I have used designated memory locations eg

    Code:
    WRITE  $50,lightsetHR[0],lightsetMN[0],lightoffHR[0],lightoffMN[1],word droptemp[0] ,word normtemp[0],StartMin[0],StopHour[0],StopMin[0],word alarmhigh[0],StartHour[0],word alarmlow[0] 
    write  $60,lightsetHR[1],lightsetMN[1],lightoffHR[1],lightoffMN[1],word droptemp[1] ,word normtemp[1],StartMin[1],StopHour[1],StopMin[1],word alarmhigh[1],StartHour[1],word alarmlow[1]
    How would I impliment this so it uses the 24c256, do I use the second hex address in the I2CWrite SDApin,SCLpin,$D0,$00, statement thus:

    Code:
    I2CWrite SDApin,SCLpin,$A0,$50 [lightsetHR[0],lightsetMN[0],lightoffHR[0],lightoffMN[1],word droptemp[0] etc etc...]
    I2CWrite SDApin,SCLpin,$A0,$60 [lightsetHR[1],lightsetMN[1], etc etc...... ]

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Using external EEprom - need a little guidance

    When I use
    Code:
    I2CWrite SDApin,SCLpin,$A0,$00,[lightsetHR[0],lightsetMN[0],lightoffHR[0],lightoffMN[1],word droptemp[0] ,word normtemp[0],StartMin[0],StopHour[0],StopMin[0],word alarmhigh[0],StartHour[0],word alarmlow[0]]
    It haults with a "bad expression" error when i attempt to compile, with lots of expected [ and ] !! - but all I've added are the [ and ] at the end of the variable string

  3. #3
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Using external EEprom - need a little guidance

    Scampy,

    A couple of things for I2CWrite for sEEPROMs.

    1. For the Address, per the manual do not use Constants. Use a variable of the size required by the EEPROM. A 24c256 requires a Word address.
    2. When using arrays in I2C you need to use var(0) versus var[0]. This is what is causing all of your compile errors.
    3. You are writing all of these values in a string to the sEEPROM, known as Page Write mode. Make sure that the total BYTES sent to the sEEPROM at one time
    does not exceed its page write buffer. For the 24c256 it is 64 bytes.
    4. Remember the sEEPROMS deal with data on a Byte basis. So for your example if I remember correctly your variables you are writing are WORD variables.
    So make sure you x2 when counting the number of BYTES sent to the sEEPROM in Page Write mode.

    This should get you going.
    Code:
    i2Addr var word
    
    i2Addr = $00
    i2cwrite SDA, SCL, $A0, i2Addr, [lightsetHR(0),lightsetMN(0),lightoffHR(0),lightoffMN(0),droptemp(0),normtemp(0), _
    StartMin(0),StopHour(0),StopMin(0),alarmhigh(0),StartHour(0),alarmlow(0)]
    This will be 24 bytes. Remember the 24c256 is arranged/addressed in rows of 16 bytes. So this data will start at addr $00 and end at addr $17. (0-23).
    The start addr of your next record would be $18.
    Regards,
    TABSoft

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Using external EEprom - need a little guidance

    Thanks for the guidance.

    In replacing the square brackets with round ones, would I also need to change the numeric value too to reflect the array format
    Code:
    normtemp          VAR WORD[4]                   ' used to store the desired temperature setting
      normtemp1       VAR normtemp[0]
      normtemp2       VAR normtemp[1]
      normtemp3       VAR normtemp[2]
      normtemp4       VAR normtemp[3]
    So that normtemp[0] becomes normtemp(1)

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Using external EEprom - need a little guidance

    I still get the bad expression errors with the following
    Code:
    i2cread SDA, SCL, $A0, $00,[lightsetHR(1),lightsetMN(1),lightoffHR(1),lightoffMN(1),word droptemp(1) ,word normtemp(1),StartMin(1),StopHour(1),StopMin(1),word alarmhigh(1),StartHour(1),word alarmlow(1)]  
    i2cread SDA, SCL, $A0, $18,[lightsetHR(2),lightsetMN(2),lightoffHR(2),lightoffMN(2),word droptemp(2) ,word normtemp(2),StartMin[2],StopHour(2),StopMin(2),word alarmhigh(2),StartHour(2),word alarmlow(2)]
    i2cread SDA, SCL, $A0, $36,[lightsetHR(3),lightsetMN(3),lightoffHR(3),lightoffMN(3),word droptemp(3) ,word normtemp(3),StartMin(3),StopHour(3),StopMin(3),word alarmhigh(3),StartHour(3),word alarmlow(3)]
    i2cread SDA, SCL, $A0, $54,[lightsetHR(4),lightsetMN(4),lightoffHR(4),lightoffMN(4),word droptemp(4) ,word normtemp(4),StartMin(4),StopHour(4),StopMin(4),word alarmhigh(4),StartHour(4),word alarmlow(4)]
    Expected "]" but there is one at the end of the statement...
    Edit:
    Even when I corrected the StartMin[2] user error ! - still get the same !!
    Last edited by Scampy; - 6th July 2015 at 22:58.

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Using external EEprom - need a little guidance

    It seems that as soon as I include the WORD statement it errors.
    Code:
    i2cread SDApin, SCLpin, $A0, $00,[lightsetHR(1),lightsetMN(1),lightoffHR(1),lightoffMN(1)]
    compiles fine, but
    Code:
    i2cread SDApin, SCLpin, $A0, $00,[lightsetHR(1),lightsetMN(1),lightoffHR(1),lightoffMN(1),word droptemp(1),word normtemp(1)]
    caused the Error:Expected"]" error message

    Stumped !!!

Similar Threads

  1. ConnectOne and external EEPROM
    By mackrackit in forum Ethernet
    Replies: 9
    Last Post: - 23rd June 2011, 00:31
  2. I2C with External Eeprom
    By ruijc in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 22nd February 2008, 14:13
  3. external eeprom
    By ruijc in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st January 2008, 12:11
  4. Simple External EEPROM Table Example?
    By modifyit in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th October 2006, 20:18
  5. External EEPROM
    By gavo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th July 2006, 22:35

Members who have read this thread : 1

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