Shop OBEX P1 Docs P2 Docs Learn Events
24LC256 woes — Parallax Forums

24LC256 woes

phredphred Posts: 6
edited 2005-09-28 01:52 in BASIC Stamp
Hello, I've got the EEPROM blues. Am trying to lash a 24LC256 to a BS2p. Have combed this list,googled,and read the datasheet. My latest attempt is the code below which gives me 255 and not what i try to write to the EEProm.

Issues I've already addressed:
-wiring: I have pins 1-4 of the EEProm pulled low
-have tried pullups on SDA and SCL as low as 1k (BSmanual), 2k (data sheet),and 10k (data sheet and some code comments)
-have tried both PIN0 and PIN 8 as SDA with SCL one pin higher in each case
- have swapped EEPROM's

Here's a boiled down version of my failed code:

' {$STAMP BS2p}
' {$PBASIC 2.5}
'

'
' I/O Definitions
'

SDA PIN 8 ' I2C serial data line
SCL PIN sda+1 ' I2C serial clock line
mybytes VAR Byte(10)
idx VAR Byte
addr VAR Word
block VAR Nib
value VAR Byte
addr=1 ' addr must be fed as a word
GOSUB I2C_Start
DEBUG "made it back from start",CR,CR

I2COUT sda,$A0, addr, [noparse][[/noparse]99]

I2CIN sda,$A1, addr, [noparse][[/noparse]idx]

DEBUG "idx: ",BIN idx,CR


END

'
'low level routines
'
I2C_Start:
INPUT SDA
INPUT SCL
LOW SDA

Clock_Hold:
DO : LOOP UNTIL (SCL = 1)
RETURN

Comments

  • ForrestForrest Posts: 1,341
    edited 2005-09-27 22:52
    I've seen it mentioned on Parallax's website that SDA and SCL should get 4.7K pullup resistors on 24LCxxx devices. See www.parallax.com/detail.asp?product_id=602-00013 for more information and a sample program.
  • JonathanJonathan Posts: 1,023
    edited 2005-09-28 00:48
    phred,

    Why is the chip address $A1 in the I2CIN statement? The address should remain the same, and $A0 is correct if you have all the address pins held low. Also, do you have the code protect line tied low? If left floating it can cause problems.

    Otherwise, the code seems OK.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-28 01:00
    With the BS2p you only need I2COUT and I2CIN.· With the address parameter, however, you have to split it up like this when using the 24LC256 as it requires two bytes:

    · I2COUT SDA, $A0, addr.BYTE1\addr.BYTE0, [noparse][[/noparse]myValue]

    I know the example in the help file is different, but it is using a different device that has its upper address bits sent as part of the SlaveID byte.· When dealing with an I2C device is imperative that you consult the documentation so that you can configure I2COUT and I2CIN properly.· The commands are flexible, and should work with any device you want to work with.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • JonathanJonathan Posts: 1,023
    edited 2005-09-28 01:00
    Phred,

    Also, why the I2C_start routine? The built in commands of the BSp take care of all that.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • phredphred Posts: 6
    edited 2005-09-28 01:28
    Argh! i've tried all of the above. Even the 4.7k pullups and pulling the WPpin low. The I2C_Start was remnants of workingthru Jon Williams code to see if not using theI2C routines of the BS2P did anything for me...
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-28 01:52
    The worst possible thing to do is take a shot-gun approach ... it leads to more frustration than success.· The program I've attached has been tested, you'll just need to adjust the pins for your setup.· And do double-check your connections; that gets us all from time-to-time.

    I just thought of something else -- you may not be allowing the write cycle to complete before attempting the read.· Note the short delay in the program I've attached.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.