Newbie I2C EEPROM Question
wbn
Posts: 29
Am I safe in assuming that the SX/B I2C EEPROM example, I2C.SXB, will not work with a 4K x 8, 8K x 8, ... 24LC32, 24LC64, ... as the MEMIN/MEMOUT subroutines were written with the 8 x 256 x 8 24LC16 in mind? If so, would someone be so kind as to refer me to a version of the MEMIN/MEMOUT SX/B subroutines which would work in conjunction with an nK x 8 I2C EEPROM.
Thank you,
wbn
Thank you,
wbn
Comments
'
' Constants
'
SlaveID··CON·$A0
Ack····· CON·0
Nak····· CON·1
'
' Subroutines Code
'
' Use: MEMOUT addrLo, addrHi, aVal
' -- writes 'aVal' to 24LC16 at location addrHi/addrLo
MEMOUT:
· temp1 = __PARAM1
· temp2 = __PARAM2
· temp3 = __PARAM3
· I2CSTART SDA
··temp4 = SlaveID·········· ' create control byte (with no chip select)
'·temp4.0 = 0·············· ' set RW bit for write
· I2CSEND SDA, temp4······ ·' send slave ID
· I2CSEND SDA, temp2········' send word address
· I2CSEND SDA, temp1······ ·' send word address
· I2CSEND SDA, temp3······ ·' send data byte
· I2CSTOP SDA·············· ' finish
· RETURN
' Use: MEMIN addrLo, addrHi, @aVal
' -- reads 'aVal' from 24LCXX with·XXK x 8·bits at location addrHi/addrLo
MEMIN:
· temp1 = __PARAM1
· temp2 = __PARAM2
· temp3 = __PARAM3
· I2CSTART SDA
· temp4 = SlaveID····· ···· ' create control byte (with no chip select)
'·temp4.0 = 0·············· ' set RW bit for write
· I2CSEND SDA, temp4······· ' send slave ID
· I2CSEND SDA, temp2······· ' send address high byte
· I2CSEND SDA, temp1······· ' send address low byte
· I2CSTART SDA
· temp4.0 = 1············· ·' set RW bit for read
· I2CSEND SDA, temp4······· ' resend slave ID
· I2CRECV SDA, temp4, Nak···' get one byte
· I2CSTOP SDA
· __RAM(temp3) = temp4····· ' move to target RAM
· RETURN
Another thing to keep in mind is that as of version 1.3, SX/B·subroutines can return a value so you don't have to pass address parameters anymore. This simplifies code and eliminates one temporary variable.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax