|
by
George Martin
Start
The Basics Getting
the Routine Down Debugging Your Reads
and Writes Sources
THE BASICS
The data exchange with the 24C32P is
through the SCL (serial clock) and SDA (serial data) pins. The clock
signal indicates when data should be transferred to or from the device,
and the clock pin serves as a bidirectional output pin from the CPU.
The data signal is used to read data from or write it to the device.
When data is written to the memory, the
CPU outputs a one or zero to the memory. When data is read from the
memory, the CPU writes a high to the data pin and then reads it as
an input. The memory drives the data pin either high or low for the
CPU to read. Up to eight 24C32P devices can have their clock and data
pins tied together and, by using address pins A0, A1, and A2 as hard-wired
1 of 8 decode-logic inputs, each chip's memory can be accessed individually.
Let me point out that, as you read and
write this type of memory (flash memory works this way too), there's
a lot going on in the background. A write command may actually perform
a read-modify-write or an erase-write cycle. You only receive a busy/ready
indication, signifying completion of the operation.
THE READ/WRITE SEQUENCE
On powerup, put the device in standby
mode by raising the clock and the data lines. In this state, no read
or write activity takes place.
The first command written to the device
is Start Data Transfer, which is activated by lowering the
data line while the clock is high. After you've lowered the clock
line, set the data line (either high or low), and then give the last
command, Stop Data Transfer, which raises the data line. One
bit is then transferred to or from the device. This serial sequencing
continues until all the data is transferred.
Let's look at the requirements for reading
a byte of data. The read sequence consists of the following operations:
Send Start Data Transfer
Send Control Byte
Send Address Byte 1
Send Address Byte 0
Read Data Byte
Send Stop Data Transfer/
The write sequence looks very
similar:
Send Start Data Transfer
Send Control Byte
Send Address Byte 1
Send Address Byte 0
Write Data Byte
Send
Stop Data Transfer/
After every byte transfer, the 24C32P
acknowledges the transfer, indicating that it went well. If you don't
get an acknowledgement, you can assume there's been an error.
Other types of memory have different
command sequences, so don't just blindly type in commands. Instead,
look carefully at the datasheet. Also, the 24C32P supports block reading
and writing. You only need to write the command and address once.
After that, you can speed up transferring large blocks of data by
using multiple read or write operations.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ęCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |