Problem with I2C EEPROM addressing


Results 1 to 15 of 15

Threaded View

  1. #1
    Join Date
    Sep 2006
    Location
    Florida, USA
    Posts
    94

    Default Problem with I2C EEPROM addressing

    Hello - I have a strange problem when trying to access an EEPROM at a certain address. I have a string of five 24LC256 EEPROMs all sharing the same clock and data line. On the first 4, I am storing the position of 4 servos with the position value converted to a byte-sized variable. On the last one, I am storing the state of a relay (1 or 0). The EEPROMs are addressed 000, 001, 010, 011 and 100. I have no problem reading and writing to the first 3 EEPROMs and the last one, but for some reason, I can not read or write to the 4th EEPROM (011). I have tried swapping EEPROMs around and have determined that there is something to do with that address. My code is pretty straight forward - record mode = read the positions of the 4 servos and relay convert to byte-size (servos) and store the data. Playback mode = read the data convert it to word-sized numbers (for servos) and send it out. The same code is used for all 4 servos. 1, 2 and 3 work fine, 4 just pegs out during playback. The servo #4, when under manual control, responds fine. Anyone have any idea what my problem could be? Attached is a drawing showing my EEPROM layout. I thought it might be a timing issue but why does it only affect #4 and not #5?

    PBP 2.5 and 877A PIC.
    Here are some code snipetts:

    Posit var word
    Posit1 var word
    Posit2 var word
    Posit3 var word
    Posit4 var word
    PVal var byte

    'EEPROM 1 will contain posit data for Servo 1
    EChip1W CON %10100000 'Write mode for EEPROM 1
    EChip1R CON %10100001 'Read mode for EEPROM 1

    'EEPROM 2 will contain posit data for Servo 2
    EChip2W CON %10100010 'Write mode for EEPROM 2
    EChip2R CON %10100011 'Read mode for EEPROM 2

    'EEPROM 3 will contain posit data for Servo 3
    EChip3W CON %10100100 'Write mode for EEPROM 3
    EChip3R CON %10100101 'Read mode for EEPROM 3

    'EEPROM 4 will contain posit data for Servo 4
    EChip4W CON %10100110 'Write mode for EEPROM 4
    EChip4R CON %10100111 'Read mode for EEPROM 4

    'EEPROM 5 will contain data for Relay
    EChip5W CON %10101000 'Write mode for EEPROM 5
    EChip5R CON %10101001 'Read mode for EEPROM 5

    Record Mode Code Snipett---
    gosub ReadPot1
    pulsout servo1, posit1
    pause 5

    gosub ReadPot2
    pulsout servo2, posit2
    pause 5

    gosub ReadPot3
    pulsout servo3, posit3
    pause 5

    gosub ReadPot4
    pulsout servo4, posit4
    pause 5

    if recordflag = 1 then 'store data
    posit = (posit1 * 23) / 100 'convert to a value < 255
    pval = posit 'put into a byte variable
    I2CWRITE DPIN, CPIN, EChip1W, Addr, [PVal] 'write it out

    posit = (posit2 * 23) / 100
    pval = posit
    I2CWRITE DPIN, CPIN, EChip2W, Addr, [PVal]

    posit = (posit3 * 23) / 100
    pval = posit
    I2CWRITE DPIN, CPIN, EChip3W, Addr, [PVal]

    posit = (posit4 * 23) / 100
    pval = posit
    I2CWRITE DPIN, CPIN, EChip4W, Addr, [PVal]

    if RelaySw = 1 then
    pval = 1
    else
    pval = 0
    endif
    I2CWRITE DPIN, CPIN, EChip5W, Addr, [PVal]
    addr = addr + 1
    endif

    PlayBack Mode Code Snipett---
    high PlayLED
    read 16, Lastaddr.byte0
    read 17, lastaddr.byte1

    for addr = 1 to lastaddr
    i2cread dpin, cpin, echip1r, addr, [pval]
    posit = pval * 4 'multiply by 4.03 to convert back to word
    posit = posit + ((pval * 3) / 100)
    pulsout servo1, posit
    pause 5

    i2cread dpin, cpin, echip2r, addr, [pval]
    posit = pval * 4
    posit = posit + ((pval * 3) / 100)
    pulsout servo2, posit
    pause 5

    i2cread dpin, cpin, echip3r, addr, [pval]
    posit = pval * 4
    posit = posit + ((pval * 3) / 100)
    pulsout servo3, posit
    pause 5

    i2cread dpin, cpin, echip4r, addr, [pval]
    posit = pval * 4
    posit = posit + ((pval * 3) / 100)
    pulsout servo4, posit
    pause 5

    i2cread dpin, cpin, echip5r, addr, [pval]
    if pval = 0 then
    low Relay
    low RelayLED
    else
    high Relay
    high RelayLED
    endif

    if SSRecBtn = 1 then
    low Relay
    low RelayLED
    low PlayLED
    pause 500
    goto Start
    endif
    next
    Attached Images Attached Images

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. Another I2C Slave Routine Problem
    By DanPBP in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2009, 05:50
  4. Problem with I2C (24c32 eeprom)
    By lab310 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 5th February 2008, 09:00
  5. I2C eeprom and DS1307 @40MHz problem
    By ius01 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 20th July 2007, 07:41

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