I2C and 24LC65


Closed Thread
Results 1 to 7 of 7

Thread: I2C and 24LC65

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello afbecker,
    Here is an example which might be helpful:



    Code:
    ' I2CREAD and I2WRITE Commands with External EEPROM on 12-bit core
    '
    ' Write to the first 36 locations of External I2C EEPROM
    ' Read from eeprom and output sequentaly then as strings
    ' Tested on 12F675  using 24LC01B EEPROM
    @ __config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _WDT_ON & _MCLRE_ON & _CP_OFF & _BODEN_OFF
    DEFINE OSC 4
     
    DEFINE DEBUG_REG	GPIO
    DEFINE DEBUG_BIT	2
    DEFINE DEBUGIN_BIT	5
    DEFINE DEBUG_BAUD	2400
    DEFINE DEBUG_MODE	0
    DEFINE SHIFT_PAUSEUS 1000
    
    EECON1   = 7  'Probably not needed here, enables internal eeprom
    CMCON    = 7  'Disable comparators
    ADCON0.0 = 0  'Disable A/D converters
    ANSEL    = 0  'Disables Analog Select
    DPIN var GPIO.0   'Assign Data pin
    CPIN var GPIO.1   'Assign Clock pin
                ' a nice place to store things
    B0 var byte
    B1 var byte
    B2 var byte
    B3 VAR BYTE
    
    GPIO   = 0 ' set port latches low
    TRISIO = 0 ' set ports as outputs
    
    pause 1000 ' Waste time while serial LCD initiailizes
    
    For B2 = 0 To 35   ' counter for lookup table
    lookup b2,["A","B","C","D","E","F","G","H","I","J","K","L","M",_
    "N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2",_
    "3","4","5","6","7","8","9"],B0 ' store each char in b0 1 at a time
    
    I2CWRITE DPIN,CPIN,$A0,B2,[ b0]  'write to 24C01 eeprom 1 character
    Pause 20
    Next B2       'next character write to eeprom
    DEBUG 254,1   'clear LCD of any leftover data
    loop:
    DEBUG 254,1   'clears away the leftovers each loop
    
    For B3 = 0 To 35   ' counter for reading 35 characters
    I2CREAD DPIN,CPIN,$A0,b3,[B1]  ' read each character 1 at a time
    pause 500           ' time to see each character on the LCD
    
    
    DEBUG 254,2,"CHAR ",B1,"          " ' display the characters 1 at a time
    '
    Next B3                             ' get next character
    
    I2CREAD DPIN,CPIN,$A0,0,[STR B1\20] ' read a string of  20 characters
    DEBUG 254,2,STR B1\20               ' display those 20 characters
    I2CREAD DPIN,CPIN,$A0,16,[STR B1\16]' get the last 16 characters
    DEBUG 254,$C0,STR B1\16,"    "      ' display those 16 characters
    DEBUG 254,$94,"I2C EEPROM DEMO"     ' display this program's purpose
    DEBUG 254,$D4,"USING ARRAY & STRING" 
    PAUSE 1500                          ' time to read the LCD
    'NEXT B3                            ' go do it all again
    Goto loop
    end
    POKECODE @$3FF, $4C  'read your PIC before erasing and put the cal. data here
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Mar 2005
    Location
    Madison, WI, USA
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Thanks for the quick reply

    Gentlemen,

    Thanks for the quick reply, I can work on this tonight!

    Aratti: For my future reference, can you tell me what the difference is between the control bytes, particularily the read control byte ending in 1? I wondered if that was the key to making my specific part work.

    Joe S.: I appreciate the code example. Reading example code is a way I find that I can learn new concepts very easily.

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I wondered if that was the key to making my specific part work.
    Although in this forum, I have read in several posts that I2CRead set the LSB to 1 automatically, I have never been able to read successfully, from external memory, without setting LSB to 1 myself. Now I do it as a standard in all my codes using I2C commands.

    Al.
    All progress began with an idea

  4. #4
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default I2c problem

    I think your problem is with the address for READ and WRITE.

    The 24LC64 EEPROM needs a WORD size address - even if the actual address is 0.

    Change your program to

    DEFINE B0 WORD ; Must not be a BYTE size or CONSTANT

    B0 = 0
    I2CWRITE, DataPin,ClockPin,$A0,B0,[Value]

    and so on....

    Good luck. I stuffed around with EEPROM for ages and eventualy found that all my errors were due to using BYTES when the chips expected a WORD. The spec sheet for the chip will tell you what it expects. The example in the PBP book is for a smaller EEPROM that only needs a BYTE address.

    Regards Bill Legge

  5. #5
    Join Date
    Mar 2005
    Location
    Madison, WI, USA
    Posts
    20


    Did you find this post helpful? Yes | No

    Default The EPROM problem

    Bill,

    You are absolutely correct.

    It came to me last night in a flash (pun intended.) I was re-reading the docs. and I realized I had defined the address variable as a byte type and the address of this part is a word type.

    After I had changed it everything works superbly!

    As a quick reply to Arratti: I am embarassed that I asked the question about the control word difference. At the time I replied I hadn't looked at the EPROM docs. for about two weeks. I forgot the difference in control words was due to the read/write mode.

    Rhetorical question: Isn't it amazing how elementary a problem suddenly becomes once you have figured out the solution?

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