Serial EEPROMs provide secure data storage for embedded systems
Parameters, constants and configuration are the banes of an embedded
system. Even though a system measures properly, if it forgets its user's preprogrammed
information, the system is nothing but an endless source of frustration. The preponderance
of "smart software" in such embedded systems has made a number of parameters
critical components, and among them are calibration information for a sensor, correction
information for the measurement system, customizing the system's printer/display, and
data/failure logging. In the past, to save this data system designers have turned to
various techniques including fusible links, PROMs, UVEPROMs, battery-backed RAM, DIP
switches and even floppy disks.
Unfortunately, each of these methods has its drawbacks. The different
types of ROMs are difficult to change, DIP switches can save only a limited amount of
information, and floppy disks are physically large and prone to mechanical failure. Even
EEPROMs (electrically erasable programmable read only memories), which seem the ideal
semipermanent memory due to long data retention and easy programming, suffer from several
drawbacks including high cost and parallel access. I've come upon one storage medium,
though, that seems ideal for caching configuration data: serial EEPROMs.
Before introducing that device, the topic of parallel access deserves a
few comments. To begin with, what's wrong with parallel access? In a word, security.
Because parallel memory devices sit directly on the address and data buses, it's easy for
a processor to access them. Unfortunately, this simple interface makes it just as easy for
the processor to destroy data inadvertently. How? Does your PC start properly every time
you switch it on? Does it ever lock up? Occasionally, all computer systems run amuck, and
when they do they can destroy data in memory. In the old days when an 8085- based system
went berserk, it commonly wrote a pattern of 39H, 00H to all available RAM---including
battery-backed memories and EEPROMs. A more insidious problem, though, occurs when an
error corrupts only a few bytes. This type of data corruption can go undetected for weeks
or months, invisibly compromising the device's operational integrity. Therefore, the
following saying should be the credo of every embedded system's designer: "The
sanctity of the data must not be violated."
The most obvious way to prevent a processor from overwriting configuration
data is to move the memory to a location where the processor can't write to it directly.
One interesting approach to such protection is inherent in a type of memory device called
a serial EEPROM, which functions similar to conventional EEPROMs except it uses a serial
link to move data to/from memory and the processor. This interface imposes a strict
protocol on data transfers that practically eliminates the possibility that the processor
can destroy data accidentally.
A good example of this type of device is National Semi's NM93Cx6 series.
These CMOS devices cost less than $4 per chip (depending upon size and quantity) and come
in sizes from 256 to 4096 bits organized in 16-bit words, although other manufacturers
supply 8-bit configured devices. NM93Cx6 devices retain data for 40 years and are capable
of 100,000 write cycles. Once you've written a starting address to the device, you can
read either one word or the rest of the memory; when writing to the device, you can
program single words or fill the entire device with a set pattern. You also can erase a
chip as a block or one word at a time. Another advantage of these chips is that they all
have the same pinout. Thus, to use a higher-density part requires only a software change.
In addition, their small size (eight pins) and 4-wire interface mean you can include them
in designs where other methods aren't practical (see figure).
Wiring a serial EEPROM into a system is straightforward. A simple way to
interface to the device is to connect it to port C of an Intel 8255 (or a derivative). An
8255 is particularly effective as an I/O port because in Mode O it allows you to set or
reset individual bits.
Once you've established the physical connection, you send commands to the
chip to read and write data. These commands implement another level of security because
unless you send the proper sequence of bits to the device, the chip denies access to its
memory. For example, to read data from the serial EEPROM, simply send it a Read command
and clock in the bits. Writing data, on the other hand, is more complicated. Because the
chip powers up in Write Disable (EWDS) state, you must first send a write-enable (EWEN)
command. Next, transmit a Write command followed by the 16 data bits. Finally send an EWDS
command to lock the serial EEPROM.
A 256-pole DIP switch?
Until now, we've concentrated on how to access serial EEPROMs, but what
can these memories do for you in an embedded application? Fortunately, only your
imagination limits the answer. You can store floating-point and integer numbers, character
strings and bit representations. A few examples should help demonstrate these parts
The simplest use for serial EEPROM is to replace the ubiquitous DIP
switch. These chips provide tremendous flexibility in this type of application because
even the smallest EEPROM has 256 switches! You can use these bits to represent a
communication data rate, unit selection (such as metric or English) or the number of
decimal places to display. Another potential application would record button presses so
that when an operator turns the system Off, the EEPROM saves the instrument's last state.
A simple example would be a switch that toggles between Fahrenheit and Centigrade.
Alternatively, bits can enable various instrument options, thus allowing one set of
hardware/software to appear as several different products.
Another use of serial EEPROMs is to save numbers. The two basic types of
numbers are integers and floating-point values. You can store integers in one or two words
of memory, the number of words depending on the required resolution. Obviously these
memories can store integer constants, but other integer numeric quantities are also
candidates. For example, I once had a prototype instrument at a user site that the
customer claimed often failed. Thinking I understood what the problem might be, I
surreptitiously built into the software a diagnostic function that incremented a number in
the serial EEPROM each time the failure occurred. In this manner I could capture an
accurate record of the failure frequency. When the instrument returned from testing, I
read out of its memory how many failures had occurred. As it turned out, the instrument
was failing, but not at the frequency that the customer felt it was. Other examples
include counting the number of times a replaceable widget has been used, the time since
the last service call, or the period between measurements.
Another powerful application for a serial EEPROM is to store
floating-point value such as calibration data for measurement hardware. For instance, I
don't like to use potentiometers in instruments for several reasons. First, I believe that
if the computer can control a function, it should control it---but potentiometers preclude
automatic control. Second, you must adjust them during manufacturing, and the alignment
process opens the door to human error. Third, their long-term stability is poor. In
addition, the more the embedded system can do for itself, the easier the instrument is to
produce and operate. Therefore, instead of adding pots to correct the linearization errors
in a barometric-pressure sensing circuit, I have the computer do the correction using
offset and slope terms from the serial EEPROM. The results is an instrument that you don't
have to open to adjust, can't set up wrong and can't jar into misalignment during
shipping. To allow you to align it during manufacturing, the instrument has a diagnostic
mode that automatically calculates the correct values and stores them into the serial
An important point to remember when working with floating-point numbers is
that you can represent them in one of three formats: double precision, single precision,
and reduced precision. IEEE-754 describes the former two formats as 64-bits and 32-bits
respectively. Although few applications need the resolution and range of double-precision
values, most C compilers default to double-precision floating-point math. Therefore it's
easy to store double-precision numbers unknowingly. This fact is significant because you
can store two single-precision numbers in the same space as one double-precision number.
Unfortunately, at times you want to cram so much data into the chip that
even single-precision won't help. One solution to this problem is the reduced-precision
floating-point number. I've occasionally saved floating-point numbers in only two or three
bytes per number. Obviously this approach sacrifices some resolution, but the ability to
represent vastly different magnitudes of numbers was more important. Also, if the numbers
are generally about the same magnitude (like thermistor constants), another way to get
more data into the chip is to scale the values and save them as integers. Then when you
retrieve them, simply scale the values in reverse to get the original constant.
There's no free lunch
Until now, the discussion has centered on a serial EEPROMs
advantages and uses. However, note that they have two potential disadvantages. First,
because they require several processor instructions to read a single word, serial EEPROMs
are slow. A simple solution to this problem is to keep a memory image of the serial EEPROM
in RAM. With this technique you read the serial EEPROM only when the embedded system first
powers up. Any subsequent reads come from the RAM table. Likewise, when you must write to
the memory, the software checks the RAM table and verifies the value has changed. If it
has, the software writes the new value to both memories.
The second problem is how do you get all that information into the memory
device in the first place? The answer is tricky because you can store so many different
types of data in these memories. Some techniques that work well include using a PC to
program devices before installing them in a board, using a "calibration station"
that programs the chip on the board, or using a special diagnostic program in the embedded
system that accesses the memory. The diagnostic program can take several different forms.
If the embedded system has a display of some sort and a keypad, they can directly access
the serial EEPROM. Alternately, if the system sports an RS232 interface, you can write a
monitor program that accesses it to communicate with a dumb terminal or PC. These types of
programs don't take much space, are easy to code, and allow easy access to a serial