Problems with driving external EEPROM M24256


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Thumbs up

    Hi Mike and Jerson!

    Good news. It started to work finally
    Not going straight into point, I must mention, that my EEPROM is M24256W. Address PINs are in EEPROM - M24256B! So there is kind of big difference, which doesn't seem so important at first place.
    To conclude some things in my experiment (perhaps it would be helpful for somebody, who deals with same problem):
    Check pin connections! (This time all connections were right)
    Data pin must be pulled-up! (If you are using open collector, then also clock pin)
    Pause after writing has to be at least 10ms. (Not 30us as I had it in my code )

    By the way. Everything else what was mentioned under this topic was right. This address splitting to higher and lower byte is working and also it is not necessary to set Control byte separately for reading and writing. Anyways, as it came out now, it is also working without splitting and you can set also Control byte separately for reading and writing. It works!

    And now the main point. I went through again PIC Basic handbook, after hours of experimenting with different cases and connections. I even changed ports for data and clock in my PIC. So in this book, there are descriptions about defines for I2C. So, when I added DEFINE I2C_SCLOUT 1, everything started to work. This define makes the I2C clock line bipolar. I don't know why it is necessary in my case, but it makes everything to work

    So here is the final code, which works with this PIC and EEPROM:

    -------------------------------------------------------------

    DEFINE OSC 4
    define I2C_SCLOUT 1 ' Makes I2C clock line bipolar

    Include "modedefs.bas"

    CVRCON = 0 ' No reference
    CMCON = 7 ' No comparator
    TRISA = %00000000 ' Set PORTA pins into output
    TRISB = %00000000 ' Set PORTB pins into output
    TRISC = %00000000 ' Set PORTC pins into output

    addr var word ' Address of EEPROM
    val var byte ' Value of writable variable
    val2 var byte ' Value of readable variable
    D var PORTC.2 ' Serial Data pin
    C var PORTC.3 ' Clock pin
    cont var byte ' Control

    Pause 1000 ' Pause 1 sec.

    val2 = 5 ' Starting value

    loop: ' Loop forever

    ' OK to use cont = %10100000 'Control is set to write
    val = 0
    for addr = 1 to 10
    val = val + 1
    I2Cwrite D, C, $A0, addr, [val] 'Write to EEPROM

    ' OK I2Cwrite D, C, $A0, addr.highbyte, addr.Lowbyte, [val] 'Writes value to EEPROM address 1
    ' OK I2Cwrite D, C, cont, addr.highbyte, addr.Lowbyte, [val] 'Writes value to EEPROM address 1
    ' OK I2Cwrite D, C, cont, addr, [val]
    Pause 10 ' Pause for 10ms. Needed for writing!
    next addr

    ' OK to use cont = %10100001 'Control is set to read

    for addr = 1 to 10
    I2Cread D, C, $A0, addr, [val2] 'Read from EEPROM

    ' OK I2Cread D, C, $A0, addr.highbyte, addr.Lowbyte, [val2] ' Dump EEPROM Contents
    ' OK I2Cread D, C, cont, addr.highbyte, addr.Lowbyte, [val2] ' Dump EEPROM Contents
    ' OK I2Cread D, C, cont, addr, [val2]
    serout PORTC.6, N9600, [val2] 'Value to serial port
    next addr
    Pause 200

    Goto loop ' Forever

    -----------------------------------------------------------------

    Soon I'll got also EEPROM 24LC16B in my hand, which I want to drive with this PIC. I hope it will not cause anymore problems.

    Thank you for your support Mike and Jerson!

    Kristjan

  2. #2
    Join Date
    Dec 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default driving external EEPROM M24256

    Hey ! glad to see that every thing worked out for you,, I was sorta worried my taking a different approch than Mr. Jerson would cause some confusion, but I see things worked out in the end..

    good Luck

    Mike

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. Replies: 1
    Last Post: - 28th January 2010, 22:15
  3. Replies: 5
    Last Post: - 24th June 2009, 03:01
  4. 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
  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