Typically EEPROMs store between 0.5 to 64KB of data. Data is retained even after powering off. For example, if you wanted to retain a temperature setting for a temperature controller, you could simply store the value of the temperature in the EEPROM in case of a power outage.
The Cubloc has an internal EEPROM of 4KB. This EEPROM can be used to store small amounts of data. If a larger EEPROM is needed, the 24LC512 can be used to store up to 64KB of data.
The following example will demonstrate how to access the 24LC32 4KB EEPROM using the I2C protocol. Serial EEPROMs usually support either SPI or I2C. I2C EEPROM part numbers begin with 24XXXX and SPI EEPROM part numbers begin with 93XXX.
Const Device = CB220 Dim adr As Integer Dim data As Byte Dim a As Byte data = &ha6 adr = &h3 Set I2C 7,6 Do I2CStart If I2CWrite(&b10100000)= 1 Then Goto err_proc a=I2CWrite(adr.byte1) a=I2CWrite(adr.lowbyte) a=I2CWrite(data) I2CStop Delay 1000 I2CStart a=I2CWrite(&b10100000) a=I2CWrite(adr.byte1) a=I2CWrite(adr.lowbyte) I2CStart a=I2CWrite(&b10100001) a=I2CRread(0) I2CStop Debug Hex a,cr ADR = ADR + 1 DATA = DATA + 1 Loop err_proc: Debug "Error !" Do Loop
This example program will write a number to the EEPROM and read it back. When this program runs correctly, numbers will increment in the debug window. This program can be easily modified to support other EEPROMs.
Note: Typically, EEPROMs need a delay of about 5ms after a write operation.