You are on page 1of 4

Programming Atmel’s Family

Of Flash Memories

Flash
Introduction The AT89C51, a member of Atmel’s
growing family of Flash microcontroller
Atmel offers a diverse family of Flash
devices, features 4K bytes of in-system
Memory devices ranging in density from
256 K to 4M-bits. These devices read
reprogrammable Flash memory (see Application
Atmel application note “AT89C51 In-Cir-
and program with a single voltage sup-
ply. The nominal supply voltage is 5V for
cuit Programming” for additional informa- Note
tion). Current and future versions of
the AT29Cxxx, 3.3V for the “low voltage”
Atmel’s microcontroller family incorpo-
AT29LVxxx, and 3V for the “Battery-Volt-
rate from as little as 1K bytes of Flash
age ™” AT29BVxxx Flash family. The
memory to as much as 128K bytes, pro-
entire Flash family is designed to allow
viding many density options for different
users to have one common program-
applications. Other versions will also
ming algorithm for all three Flash voltage
include special architectures such as a
families. Therefore, upgrading from one
c om b i na t io n of F l a s h a n d p ar al l e l
density to another and from a higher
EEPROM memory on board.
voltage to a lower voltage device is sim-
plified.
This application note describes the Programming Flash
design benefits of Atmel’s Flash archi- Devices
tecture as well as how the device ID fea- Unlike Atmel’s Flash Memories, previous
ture is used to adjust for varying densi- generations of Flash memories had
ties and supply voltages. In addition, large kilobyte sectors and required that
Atmel’s Software Data Protection (SDP) an entire sector be erased prior to pro-
feature, which prevents inadvertent gramming. Generally, the sector erase
writes, is described. An example is given cycle time was hundreds or thousands of
to illustrate the ease with which the pro- milliseconds and could be as long as 30
gramming software can be written to seconds for the entire memory array. In
accommodate four different 4M-bit Flash addition, a separate high voltage supply
devices, the AT29C040, AT29LV040, was required for a write and erase oper-
AT29C040A, and AT29LV040A. ation. Atmel’s Flash family has simplified
Hardware and software have been usage by having only one supply volt-
developed to demonstrate the relevant age, reducing the sector size, having the
de s i gn i s s u es . Th e d em o u s es an programming similar to an SRAM write
AT89C51 Flash-based microcontroller operation, and decreasing significantly
(which has the same pinout and instruc- the total programming time.
tion set as an 80C51) as the host pro- Small sector sizes reduce the amount of
cessor and a “C” language program for system resources necessary for pro-
the software. The software automatically gramming. When only a few bytes in a
adjusts the amount of time required for Flash memory need to be altered, a
programming the varying voltage ver- RAM image of the Flash sector must be
sions of the 4M-bit Flash devices in addi- created. The RAM must then be altered
tion to accommodating for their different with the new data, and the image trans-
sector sizes. fer red bac k in to th e Fla sh dev ic e. 0510A-B–12/97
Because Atmel’s Flash devices have

5-31
small sector sizes (from 64 to 512 bytes, depending on the Software Data Protection (SDP)
memory density), the RAM requirements are much less
One concern of systems designers when using nonvolatile
than those of large sector Flash devices. The latter gener-
programmable memories is the possibility of inadvertent
ally have 4 K to 128K byte sector sizes.
write operations that can be caused by noise or by power-
A second advantage of Atmel’s Flash is that an entire sec- up and power-down sequences. Atmel’s Flash memories
tor can be updated during a single program operation, provide a feature called Software Data Protection (SDP)
instead of the byte-by-byte programming of previous gener- that addresses this issue. The user can enable SDP upon
ation Flash memories. This saves significant programming receipt of the device from Atmel, and its usage is highly
time when updating an entire sector, especially when com- recommended. Data can be written into a sector with or
paring Atmel’s small sector devices with large sector without SDP enabled. However, once SDP has been
devices. In addition, Atmel’s devices do not require a sector enabled, the device requires that all subsequent write oper-
erase prior to writing, thus saving additional programming ations perform a series of “dummy” write operations before
time. The maximum sector program time is 10 ms and 20 loading the chosen sector with data. The “dummy” writes
ms for the AT29Cxxx and AT29LVxxx/AT29BVxxx families consist of loading three known data values into three pre-
respectively. defined addresses. This three-byte sequence preceding a
write operation virtually eliminates the chance of inadvert-
AT29C040 and AT29C040A Architecture ent write operations. The sequence is described below.
The AT29C040 provides operation similar to a byte-wide 1. Load Data AAH into Address 05555H
SRAM. The device has eight data lines and 19 address 2. Load Data 55H into Address 02AAAH
lines. The familiar three input control lines are also present 3. Load Data A0H into Address 05555H
(CE, OE, WE). Read operations are identical to an SRAM,
4. Load desired sector with data
but write operations are somewhat different due to the write
cycle time (tWC) requirements of all Flash memories. Flash 5. Pause tWC (device write cycle time)
write operations take several milliseconds to complete, 6. The device is returned to standard operating mode
compared to the nanosecond writes of SRAM devices. It If SDP is enabled, any attempt to write to the device without
should be noted that Atmel’s Flash Memories require only a the three-byte command sequence will start a write cycle.
write operation; the erase operation is automatically per- However, no data will actually be written to the device, and
formed internally in the device. during this “write” cycle time (t WC), valid data cannot be
Data is loaded into the AT29C040 one sector at a time, with read from the Flash.
each sector consisting of 512 bytes. The sector chosen for
modification is defined by the upper order address bits (A9-
A18). The entire sector must be loaded during the write
Product and Manufacturer ID
operation. Any byte not loaded during the sector load will Atmel’s Flash memory devices allow the user to access
contain FFH after the write operation has completed. both device and manufacturer information. This feature
Address lines A0 through A8 define the location of the allows a system to determine exactly which Flash memory
bytes within a sector. All data must be loaded into the same is being used. Once this is known, the host system can
sector (A9 through A18 must remain constant) and can be choose different algorithms for write operations in order to
randomly loaded within that sector. accommodate for differences in device density, V CC
requirements, sector size, and required write cycle time.
The AT29C040A is identical to the AT29C040 except for
the sector size and the Device ID Code (the Device ID Product and manufacturer ID information is determined
Code is described later). The AT29C040A has a 256 byte with the Software Product Identification procedure, which is
sector (instead of a 512 byte sector) which is defined by similar to the Software Data Protection sequence. The
address lines A8 through A18; the bytes within the sector sequence is described below.
are determined by address lines A0 through A7. 1. Load Data AAH into Address 05555H
2. Load Data 55H into Address 02AAAH
3. Load Data 90H into Address 05555H
4. Pause tWC (device write cycle time)
5. Read Address 00000H
Data read is the Manufacturer Code

5-32 Microcontroller
Microcontroller

6. Read Address 00001H Software Description


Data read is the Device ID Code
The software (available from Atmel’s BBS 408-436-4309)
7. Load Data AAH into Address 05555H demonstrates how the Device ID Code can be used to
8. Load Data 55H into Address 02AAAH allow a single program to work with different Atmel Flash
9. Load Data F0H into Address 05555H memories. The program uses Atmel’s 4M-bit Flash
(AT29C040, AT29LV040, AT29C040A, and AT29LV040A)
10. Pause tWC (device write cycle time)
as an example, but the software can be easily adapted to
11. The device is returned to standard operating mode accommodate other device densities.
The following table uses the 4M-bit Flash as an example to In order to program the Flash memory, the software must
illustrate the pertinent device information than can be first determine which Flash device is being used. This is
determined once the Device ID Code is known. accomplished by first putting the device into the Software
Product Identification mode by executing a three-byte com-
mand sequence (described in the “Product and Manufac-
Device ID VCC Sector Size tWC
turer ID” section of this application note). The program sub-
AT29C040 5B 5.0V ± 10% 512 bytes 10 ms sequently reads the Device ID Code and executes another
AT29C040A A4 5.0V ± 10% 256 bytes 10 ms three-byte command sequence to return the Flash to the
standard operating mode. Using the Device ID Code, the
AT29LV040 3B 3.3V ± 0.3V 512 bytes 20 ms program then determines the appropriate sector size and
AT29LV040A C4 3.3V ± 0.3V 256 bytes 20 ms write cycle time (tWC) for the particular 4M-bit Flash being
used.
AT29BV040 3B 3.0V ± 10% 512 bytes 20 ms
To demonstrate a sector write, the program proceeds to
AT29BV040A C4 3.0V ± 10% 256 bytes 20 ms load the SRAM with “dummy” data. After the data has been
loaded, the program transfers the data from the SRAM to a
predefined sector (within one of the mapped 8K byte
Hardware Description blocks) of the 4M-bit Flash. After pausing the required write
The demo hardware consists of a 12 MHz AT89C51 Flash- cycle time (tWC), the sector that was just written is trans-
based microcontroller with 4K bytes of on-board Flash ferred back to the SRAM buffer.
memory. The internal AT89C51 Flash memory is used for
boot code, and the external 8K x 8 SRAM and the
AT29C040 are mapped as data memory. The AT29C040 is Summary
also mapped as program memory to facilitate off-chip pro- Atmel’s Flash Memories are designed to allow all densities
gram execution. The AT89C51 can only access a maxi- and device configurations to be programmed using the
mum of 64K bytes of data memory space, while the same programming algorithm. The user has to simply
AT29C040 has 512K bytes of storage capacity. To solve determine the Device ID Code and set the appropriate sec-
this size mismatch, the AT29C040 is bank switched into the tor size and write cycle time. This operation need only be
AT89C51 data memory map in 8K byte blocks. The bank performed once provided the sector size and write cycle
switching is performed with six general purpose I/O port information is saved. If only one density or configuration will
bits on the AT89C51. The system address map is shown ever be used, then reading of the Device ID Code can be
below. eliminated, and the sector size and write cycle information
can be predefined in the software.
System Address Map
As demonstrated, programming Atmel’s Flash is a simple
AT89C51 Microcontroller 0000-1FFF Internal program process, similar to loading an SRAM. Architectural and cir-
memory cuit features within the devices minimize software and sys-
8K x 8 Static RAM 2000-3FFF Data memory tem overhead while simplifying programming procedures.
Atmel’s Flash Memories require only about one-tenth of the
AT29C040 Flash 4000-5FFF Program and typical software, buffer memory, and performance over-
data memory head of previous generation Flash, thus providing substan-
tial system cost savings.

5-33
5-34
Microcontroller

Figure 1. Atmel AT29C040DA Demo Circuit

OOOOOOOO
0 1 2 3 4 5 6 7 A0 10 11 D0 A0 12 13 D0
A1 9 A0 D0 12 D1 A1 11 A0 D0 14 D1
A2 8 A1 D1 13 D2 A2 10 A1 D1 15 D2
A3 7 A2 D2 15 D3 A3 9 A2 D2 17 D3
A4 6 A3 D3 16 D4 A4 8 A3 D3 18 D4
A5 5 A4 D4 17 D5 A5 7 A4 D4 19 D5
VCC 11 A6 4 A5 D5 18 D6 A6 6 A5 D5 20 D6
1 G A6 D6 A6 D6
A7 3 A7 D7 19 D7 A7 5 A7 D7 21 D7
OC A8 25 A8 27
Q7 A8 A8
VCC 31 39 18 19 A9 24 A9 A9 26 A9
EA / VP P 0.0 38 D7 Q6 A 10 21 A 10 23
P 0.1 17 D6 16 A 10 A 10
19 37 14 Q5 15 A 11 23 A 11 25
XTAL1 P 0.2 D5 Q4 A 11 A 11
CLK 36 13 12 A 12 2 A 12 A 12 4 A 12
1µ P 0.3
35 8
D4 Q3 9 A 13 28
P 0.4 D3 Q2 A 13
18 34 7 6 20 CE 1 26 A 14 29 A 14
12 MHz XTAL2 P 0.5 D2 Q1 CE 2 VCC
P 0.6 33 4 D1 Q0 5 22 OE A 15 3 A 15
P 0.7 32 3 D0 2 27 WE A 16 2 A 16
9 RESET A 17 30 A 17
P 2.0 21 74HCT373 8K x 8 SRAM A 18 1 A 18
P 2.1 22
12 P 2.2 23 1 22 CE
INT 0
10K 13 INT 1 P 2.3 24 24 OE
14 P 2.4 25 2 31 WE
T0
15 T1 P 2.5 26 AAAAAAAAAAAAA
P 2.6 27 74HCT08 AT29C040
1 P 2.7 28 1 1 1 9 8 7 6 5 4 3 2 1 0
P 1.0
2 P 1.1 2 1 0
3 P 1.2 RD 17
4 P 1.3 WR 16
5 P 1.4 PSEN 29 AAAAAA
6 P 1.5 ALE / P 30
7 P 1.6 TXD 11 1 1 1 1 1 1
8 P 1.7 RXD 10 8 7 6 5 4 3

AT89C51

1 15
2 A Y0 14
3 B Y1 13
C Y2 12
Y3 11
6 Y4 10
VCC Y5
4 G1 Y6
9
5 G2A Y7 7
G2B

74HCT138

Note: If the Flash is to be used as external program memory, then


pin 31 (EA/ VPP) of the AT89C51 should be connected to ground.

You might also like