24LC256 woes
phred
Posts: 6
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
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
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
· 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
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
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