The code for this 64k*8 I2C EEPROM was tested on an Atmel EB55 board.
$0A0 constant 24c512_id0 \ -- $A0 ; up to four devices
The base device address (devaddr) of a 24C512.
$10000 constant 24c512_size \ -- 64k
Memory size of a 24C512 device.
$080 constant 24c512_page \ -- 128
Size of a 24C512 page to write.
#10 constant 24c512_twr \ -- n ;
The write time in milliseconds at 2.7v or above. Note that at 1.8v, this value must be increased to 20 ms.
: 24c512_send_addr \ Eaddr devaddr --
Issue a device address and EEPROM address.
: 24c512_write_byte \ byte Eaddr devaddr --
Write byte to the EEPROM devaddr at EEPROM address Eaddr. Note that the system must wait at least 24C512_TWR milliseconds before accessing the same device again.
: 24c512_write_page \ src len Eaddr devaddr --
Write len bytes of memory at src to the EEPROM devaddr starting at EEPROM address Eaddr. If len is 0, the address Eaddr is written to the EEPROM and becomes the current address, although no data is written. Note that the system must wait at least 24C512_TWR milliseconds before accessing the same device again.
: 24c512_read_byte \ Eaddr devaddr -- byte
Using EEPROM devaddr, read the byte at EEPROM address Eaddr.
: 24c512_read_block \ dest len Eaddr devaddr --
Using EEPROM devaddr, read len bytes at EEPROM address Eaddr to the buffer at dest.
: 24c512_read_seq \ dest len devaddr --
Read len bytes to dest from the current/next EEPROM address.
: NextBinAlign \ addr n -- addr'
Align an address to the next n-byte boundary, where n must be a power of 2.
: 24c512_read_len \ len seprom -- len'
Determine how much can be read in one go.
: 24c512_write_len \ len seprom -- len'
Determine how much can be written in one go.
: SEPROM! \ sram-addr length(bytes) seprom-addr --
Write length bytes to EEPROM address seprom-addr from the buffer at sram-addr.
: SEPROM@ \ sram-addr length(bytes) seprom-addr --
Read length bytes at EEPROM address seprom-addr to the buffer at sram-addr.