your program, you might have a good candidate for using
a function. Figure 2 illustrates the function concept using
the read EEPROM function. (The timing and port register
controls have been removed to focus on the function
parameters. Complete details of the function timing are
shown in Figure 5.)
The end result of calling this function is that the edata
variable contains the data at address eaddr in the Master
EEPROM. In my write_eeprom function, no data is
returned so the first word in the function statement is
EEPROM Burner Program
void loop ()
My first step was to build a quick prototype to prove
the concept that I could actually read and write the
EEPROM. I used a breadboard, a ZIF socket, and some
pre-cut jumper wires to connect to the Arduino Mega.
My first program just turned on each of the address, data,
and control bits in turn, so I could verify the wiring using
my logic analyzer. Without a logic analyzer, it would be
extremely difficult to troubleshoot problems with a digital
circuit like this. I use a Rigol DS1052D but there are many
less expensive alternatives including an open source
hardware/software logic analyzer that is around $45.
By the time I had completed the wiring the blank
EEPROMs had arrived and I was ready for my first big test.
I wrote a program to read all 8K bytes and display them
on my PC. After tweaking a few programming errors, I had
my first big success and a bit of a surprise. Instead of
being blank, the new EEPROMs started at address 0 with
0xAA (hex) and then alternated 0x00 0xFF for 32 bytes,
then changed to 0xFF 0x00 for 32 bytes, and repeated this
for the remaining data.
Now I was ready for the ultimate test of writing data
to the chip. However, the write operation was more
complicated than the read because the chip used
Software Data Protection (SDP) to protect against
inadvertent writes as shown in Figure 3.
I wrote a program to write one byte of 0xBB at
address 5 and read it back, but the output showed
the write had failed. I checked the timing signals
with the ones on the datasheet and everything
looked correct. After much pointless
troubleshooting, I decided to put the circuit away
and reread the EEPROM datasheet from cover to
cover. I discovered that there is one important
control signal that is not included in the timing
diagrams: Write Control — which I had failed to
connect to the chip. This signal must be low for all
write operations so I just connected it to ground
and finally the write routine worked. Next, I
modified the write routine to write a fixed pattern
byte read_eeprom(int address, byte ce)
Generates the required timing signals to return one byte
(fdata) at the specified address for either the Master or Slave
EEPROMs. The parameter ce is the bit in the L register that
provides the Chip Enable signal.
void write_eeprom(int address, byte data)
Writes one byte of data to the address specified in the Slave
EEPROM. Note this function actually generates four write
commands (calls to the raw_write function). The first three don’t
actually change any value in the EEPROM but are used to
prevent inadvertent writes to the chip. Only the fourth write
command actually stores data in the EEP
ROM. A delay is generated at the end of the function to
make sure the t WC maximum write timing is met.
void raw_write(int raddress, byte rdata)
Generates the write timing signals and data to the EEPROM.
Figure 5 shows the write timing diagram from the X88C64
datasheet and the corresponding write function showing how
each signal is generated by the program. Note that the timing
diagram is from the perspective of the EEPROM, while the
function reflects signals from the Mega. (Output data from the
function is input data to the EEPROM). The “nop\n\t” instructions
are assembly code that represents a clock cycle delay or no
operation (no-op). These were inserted to guarantee the setup
and hold times required by the X88C64.
The X88C64 has a feature called Block Protect Write where
you can write protect individual 1K blocks of the EEPROM. This
function makes sure this feature is disabled.
to the entire 8K bytes so I would have something to use to
test my final copy program (initial value of 0xFF and
decrement by one for every subsequent write).
Feeling satisfied that my design concept was sound, I
wired up my final version connecting the Mega to the two
Logic analyzer trace when troubleshooting the failure to
write the EEPROM. Can you spot the problem?
1µs / division
May 2010 45