I2C  implementation: Accessing the 24LC01 Serial EEPROM Introduction                  This application note presents programming techniques for reading from and writing to a serial EEPROM
using I2C data transfer protocol. This implementation uses the Parallax demo board and takes advantage of their
SX demo software's UART and user interface features to allow simple access to the EEPROM contents. Additions to the Parallax SX Demo interface Three new commands have been added to the SX demo UART interface to access the EEPROM, as follows: 1) Store: (a) S - sample the analog to digital converter ADC1 and store it in current memory address (b) S xx - put the hex value xx into current memory address 2) View: (a) V - display all currently stored values (b) V xx - display the value at hex memory address xx (c) V FF - display all of the EEPROM contents 3) Erase: E - write zeroes to the entire EEPROM How the circuit and program work                  Thanks to the basic hardware requirements of the I2C protocol, the circuit is very simple, using only two
port pins (PortA pins 0 and 1) of the SX to provide serial access to the 24LC01 EEPROM. PortA.0 functions as
the serial data clock SCL which provides the timing reference for data transfer to and from the EEPROM, and
PortA bit 1 is SDA, the actual data bit stream. As on the demo board, a 10K1 pull-up resistor should be
connected from the SDA2 pin to V
dd                                                                    since the EEPROM's data port is open-collector.
The two main functions of the program are to read to and write from the EEPROM. Data transfers to and
from the 24LC01 are composed of 8 bit data bytes which can be read/written in a random access format (i.e. one
byte at a time) or in a sequential3 format, the latter not being implemented here.
                 To write to the 24LC01 in random access mode, the SX must initiate the write operation by sending the
EEPROM a 'START' signal, followed by a control byte 10100000b (which identifies the 24LC01 as the device to
be accessed and signals that the operation to be performed is a write), followed by the address where the byte is
to be written to, followed by the data byte to be written, followed by a STOP signal. It should be noted that after
each byte of this sequence is sent, the program toggles the I/O status of the SDA line to read an acknowledge
signal (that a byte has been received) from the EEPROM. Both the write and read sequences, as implemented
here, use acknowledge polling. This technique sends a repeating control byte query to the EEPROM until a valid
                                                       I2C is a registered trademark of Philips Semiconductor, Inc. 1A value of 10K is sufficient for the data transfer rate used here. For faster rates, the pull-up may need to be reduced in order to allow
successful operation. If speed is not an important issue, the external pull-up may be eliminated entirely by increasing the t_all bus
timing delay and using the SX's internal pull-up resistor feature (see SX data sheet for programming details) on the SDA port pin.
2No pull-up is needed for the SCL line since it is always driven high or low by the SX
3The maximum number of bytes allowed during a sequential write is 8 for the 24LC01, though sequential reads have no byte count
limit.