EEPROM Handling in Remote Control Devices Using the

Application Note
EEPROM Handling in Remote Control
Devices Using the Crimzon® MCU
AN026201-0707
Abstract
In many remote control applications, an EEPROM is
used to permanently store important data. Care must
be taken, however, to prevent data corruption caused
by incomplete WRITE cycles, power interruptions,
and external noise.
This application note focuses on proper use of the
Crimzon® MCU in remote control devices to ensure
data integrity in EEPROMs. Focus is on the operational flow of the Crimzon MCU.
Note: The source code associated with this
reference design is available under
Crimzon Applications Code Library
in Application Sample Libraries on
www.zilog.com.
Crimzon Microcontrollers
With one of the broadest device databases available
today, Zilog's Crimzon line of microcontrollers offers
the design flexibility required to create a wide variety
of infrared products. Our living database of infrared
remote control codes, ZBASE®, allows you to support the latest infrared applications on the market,
including universal remote controls, wireless keyboards, wireless mice, and game controllers. Zilog’s
advanced data compression algorithms squeeze more
device data into the available ROM. You get more
device support for your money because Crimzon
microcontrollers are simpler to integrate.
Zilog’s broad range of cost-effective, low-power
Crimzon microcontrollers provides the ability to
meet the requirements of a range of device footprints:
20-pin, 28-pin, 40-pin and 48-pin in DIP, SOIC and
SSOP. Memory is available in sizes from 4 K to 64 K
ROM and up to 128 K OTP, giving you greater
AN026201-0707
choice when selecting the right device for your application. At Zilog, we are continually evolving our
Crimzon microcontroller roadmap so that you can
expect new, smaller packages and added-feature silicon that will further enhance your product offerings.
Discussion
An EEPROM is commonly used in remote control
applications to save data when the power is off.
There are numerous EEPROM suppliers in the market. Most use the standard I2C communication for the
communication interface. (Refer to the EEPROM
specification for details on using the I2C interface.)
Table 1 provides a sample of the Atmel serial
EEPROM product list.
In remote control devices, EEPROMs are used for
two primary purposes:
•
One is to store the basic code numbers for userprogrammed data and for factory-loaded data.
A 1K EEPROM is usually adequate for this
purpose.
•
The other is to store the learning signal data in
a learning remote control. For such purposes,
EEPROMs from 4 K to 32 K are used depending on the number of keys to be learned.
Different EEPROMs can have different page sizes
(from 4 bytes to 256 bytes) and address pins (A0 A2). Designers must take care to study the device’s
interface method and select the appropriate page
read/write method.
Page 1 of 8
EEPROM Handling in Remote Control Devices Using the Crimzon® MCU
Table 1. Atmel's 2-Wire Serial EEPROM Family
Device
Size
(Bytes)
Page Size
(Bytes)
Maximum
Per Bus
Addresses
Used
AT24C11
1K
4
1
None
AT24C01A
1K
8
8
A0, A1, A2
AT24C02
1K
8
8
A0, A1, A2
AT24C04
4K
16
4
A1, A2
AT24C08A
8K
16
2
A2
AT24C16A
16 K
16
1
None
AT24C164
16 K
16
8
A0, A1, A2
AT24C32A
32 K
32
8
A0, A1, A2
AT24C64A
64 K
32
8
A0, A1, A2
AT24C128
128 K
64
4
A0, A1
AT24C128B
128 K
64
8
A0, A1, A2
AT24C256
256 K
64
4
A0, A1
AT24C256B
256 K
64
8
A0, A1, A2
AT24C512
512 K
128
4
A0, A1
AT24C512B
512 K
128
8
A0, A1, A2
AT24C1024
1M
256
2
A1
Hardware Architecture
•
SCL: Serial Clock Input
The Crimzon MCU 8-pin small package is shown in
Figure 1.
•
SDA: Serial Data
Figure 1. Crimzon MCU, 8-Pin Small Package
The pins provide access to the following functions:
•
A0 - A2: Address Inputs
•
WP: Write Protect
AN026201-0707
The SCL is driven either directly by an MCU output
pin with push-pull, or by an open-drain output using
a 2 KΩ pull-up resistor. Ports P34 or P37 are pushpull outputs that can be used for that purpose. Any
pin of ports P20-P27 can also be used as push-pull
output or open-drain with 2 KΩ pull-up resistor.
The SDA must be driven by an open-drain output
with 2 KΩ pull-up resistor. The EEPROM sends an
ACK signal by pulling the SDA pin down at the 9th
bit period. The SDA pin must therefore be a bidirectional pin that supports the open-drain output configuration. Any pin of Crimzon MCU ports P20-P27 can
be used to drive the SDA pin. Configure the port as
open-drain with a 2 KΩ pull-up resistor during data
pulses. After sending 8 clocks, the MCU pin must be
Page 2 of 8
EEPROM Handling in Remote Control Devices Using the Crimzon® MCU
configured as input pin to read the ACK at the 9th
clock. See Figure 2.
Figure 2. Output Acknowledge Timing Diagram
Software Implementation for Read/
Write Operations
interfacing the Crimzon MCU to an EEPROM via
I2C.
An EEPROM supports random access, sequential
access, and page access. (Refer to your EEPROM
specification for further information.) Zilog application note AN0036 also provides example code for
Figure 3 illustrates the byte write operation. Figure 4
illustrates the page write operation. A flowchart for
EEPROM handling is provided in Appendix A –
Flowcharts.
Figure 3. Byte Write Operation
Figure 4. Page Write Operation
AN026201-0707
Page 3 of 8
EEPROM Handling in Remote Control Devices Using the Crimzon® MCU
Prevention of Data Corruption
An EEPROM is designed for permanent data storage.
The data is preserved even though the power is
removed during battery replacement in remote control. However, there is still a risk of corrupting the
EEPROM data during a write operation.
Causes of data corruption in EEPROMs include:
1. Incomplete Write Cycle
The I2C interface is a static bus, and the MCU
can control the speed of that bus while performing other activities. However, if the MCU
is interrupted and loses track of the EEPROM
writing procedure, the EEPROM data may get
corrupted.
2. Power Interrupt
An EEPROM needs between 5 ms and 10 ms
to write data into its permanent storage area. If
the power is interrupted prior to the WRITE
completion, the new data will be lost. Existing
data may also be corrupted. It is important to
ensure that the power is stable during the
EEPROM WRITE cycle.
3. External Noises/Pulses
Other events may inject extra pulses into the
I2C bus. For example, if the I2C bus is multiplexed with a key scanning matrix, pulses can
be injected into the bus when a user presses a
key on the keypad.
Prevention of EEPROM Corruption During
WRITE Operations
There are simple rules to follow that will help you
avoid EEPROM data corruption.
The EEPROM should be written only when the program modifies the data. For example, if the
EEPROM contains the user-programmed code number of each device, perform a WRITE to the
EEPROM only when the programmed code number
is modified, or upon power-up initialization.
AN026201-0707
1. Eliminate single-key-triggered WRITE processes.
In some applications, a manufacturer may want
the remote to remember the device mode (TV,
VCR, DVD, Satellite, Cable, Audio, etc.). The
device mode is usually modified when a device
key is pressed. In that case, store the device
mode status in RAM only. Avoid an EEPROM
WRITE after a single key press and you will
avoid data corruption if the device suddenly
loses Vcc power.
For example, the user can easily press a device
key by accident while removing the battery.
With a single-key-triggered WRITE procedure,
the accidental key press triggers a WRITE of
device mode data into EEPROM. Since the
battery is being removed, however, the Vcc
power naturally drops below the RESET voltage for the Crimzon MCU. The MCU then
stops operation. As Vcc drops below the
EEPROM operating voltage, data integrity is
jeopardized. Data will likely be corrupted.
Trigger an EEPROM WRITE process by a
multiple key press sequence and such accidental data loss can be almost completely avoided.
2. Low Voltage Detection
The Low Voltage Detection flag (bit 1 of LVD
register 0x0C in bank 0x0D) will be set when
the voltage is lower than the VLVD (typically
2.4 V) when low voltage detection is enabled.
Write only to the EEPROM when voltage is
high.
Quality Check on EEPROM data
The chance of EEPROM data corruption can be minimized by a WRITE at the right time.
When the EEPROM is read, you must still verify that
the data is totally reliable. Different EEPROM sizes
have different page sizes for WRITE and READ
operations. If the PAGE WRITE process stops before
it has completed, the whole page of data will be corPage 4 of 8
EEPROM Handling in Remote Control Devices Using the Crimzon® MCU
rupted. If the power is lost before the required 5 ms to
10 ms WRITE cycle, some data (pages or bytes) will
be lost.
1. Checksum and Signature Byte
A checksum byte and a signature byte can be
inserted into a page of data (e.g. 16 byte). If the
firmware writes a page each time, then do not
read the EEPROM as a single byte. Instead,
read a page and verify the checksum and signature byte to ensure that the data is valid.
If the corrupted data are all 0x00, the test will
also match the checksum of 0x00. Therefore,
use a signature byte (e.g. 0xA5) to ensure that
the checksum won't be the same as the corrupted data. These checksum and signature
bytes are applicable for both EEPROM data
and RAM data verification.
2. Software Check on Validity of Data
The firmware should check whether the data is
valid. For example, if there are only 200 TVs
listed in the codeset, any code number that is
higher than the known maximum should be
treated as invalid data.
3. Minimize the Number of EEPROM READs
After the Crimzon MCU reads the EEPROM,
data is stored in internal RAM. The MCU can
obtain all the subsequent information it needs
from the data stored in RAM. You can therefore minimize the number of EEPROM
accesses. Doing so reduces the time required to
access data, and minimizes the possibility of
reading the wrong data from external memory.
Power Up Initialization and Operation
Upon power-up or reset, the MCU should check
internal RAM data to see whether it is valid. The
internal RAM data check should consist of the checksum (checksum of all useful data including code
number, critical status, user/factory selection from
jumper of user interface) and a signature byte (e.g.
AN026201-0707
0x5A). If the RAM data is valid, there is no need to
read the EEPROM. Proceed with normal operation.
Such situations occur during, Stop Mode Recovery,
Watchdog timeout reset, and when the RESET pin
goes LOW.
If the RAM data is not valid, the MCU should read
the EEPROM by page. Verify the checksum and signature byte for the data validity. If the EEPROM data
is valid, copy the EEPROM data into RAM and treat
it as valid data. Such situations occur after battery
replacement.
If neither the RAM nor EEPROM data are valid, perform a complete initialization for the RAM and
EEPROM. This situation happens on the first power
up of the remote. It is also applicable in the first
power-up if the manufacturer uses a pre-programmed
EEPROM.
When the jumper selection state is needed, read the
jumper from time to time instead of storing the data
into RAM or the EEPROM. The exception is that
when the jumper is multiplexing with other peripherals, it can only be read at the power-up stage. In that
instance, the MCU must store the jumper data into
RAM or EEPROM. The chance of reading a wrong
jumper is much lower than the potential for corrupting data in RAM or in the EEPROM.
Summary
You can simplify remote control design and operation by using the techniques described in this application note. By applying the principles described, the
Crimzon MCU will ensure that data integrity is maintained. When the MCU needs to read data from the
EEPROM, check the validity of that data. Take
appropriate precautions when the MCU must write
data to the EEPROM. By ensuring data integrity, the
remote control will operate as it should, and the end
user will be a satisfied customer.
Page 5 of 8
EEPROM Handling in Remote Control Devices Using the Crimzon® MCU
Reference Documentation
The documents associated with the Crimzon MCU
MCU available on www.zilog.com are provided
below:
•
•
Using the Z8 MCU as an I2C Bus Master,
AN0036
Z8 CPU User Manual (UM0016)
AN026201-0707
Page 6 of 8
EEPROM Handling in Remote Control Devices Using the Crimzon® MCU
Appendix A – Flowcharts
A flowchart illustrating program flow for EEPROM handling in a remote control is provided in Figure 5.
Start
Yes
RAM Valid?
No
EEPROM
valid?
Yes
Load EEPROM data to
RAM
No
Initialize RAM
Normal operation
End
Figure 5. EEPROM Handling Routine for a Remote Control Application
AN026201-0707
Page 7 of 8
EEPROM Handling in Remote Control Devices Using the Crimzon® MCU
Warning: DO NOT USE IN LIFE SUPPORT
LIFE SUPPORT POLICY
ZILOG'S PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE
SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS PRIOR WRITTEN APPROVAL OF
THE PRESIDENT AND GENERAL COUNSEL OF ZILOG CORPORATION.
As used herein
Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b)
support or sustain life and whose failure to perform when properly used in accordance with instructions for
use provided in the labeling can be reasonably expected to result in a significant injury to the user. A
critical component is any component in a life support device or system whose failure to perform can be
reasonably expected to cause the failure of the life support device or system or to affect its safety or
effectiveness.
Document Disclaimer
©2007 by Zilog, Inc. All rights reserved. Information in this publication concerning the devices,
applications, or technology described is intended to suggest possible uses and may be superseded. ZILOG,
INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY
OF THE INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT.
Z I L O G A L S O D O E S N O T A S S U M E L I A B I L I T Y F O R I N T E L L E C T U A L P R O P E RT Y
INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR
TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. The information contained within this
document has been verified according to the general principles of electrical and mechanical engineering.
Crimzon is a registered trademarks of Zilog, Inc. All other product or service names are the property of
their respective owners.
AN026201-0707
8
Page 8 of 8
Download PDF