Elektor - CompactFlash Interface For Microcontroller Systems.pdf

(350 KB) Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
MICRO CONTROLLER
CompactFlash
Interface for
Microcontroller
Systems
including our 89S8252 Flash board
Design by P. Goossens
CompactFlash (CF) cards are ideal for storage of large amounts of data,
which is retained for years without the need for a backup supply voltage.
In the wake of our
CompactFlash Drive
on IDE Bus (April
2002), we now
present a similar
circuit for
microcontroller
boards. Specific
attention is given to
the popular 89S8252
Flash Micro board
which forms the
hardware basis of
our Microcontroller
Basics course.
78
Elektor Electronics
12/2002
855731462.121.png
 
MICRO CONTROLLER
The present CF interface was ini-
tially designed as an extension for
the 89S8252 Flash Micro board pub-
lished in the December 2001 issue of
Elektor Electronics . The circuit may
also be used in combination with
other microcontroller systems pro-
vided you are able to make a suit-
able adapter between the CF inter-
face and the extension connector on
the system you have available.
The CF interface enables the
processor to read and write data
from/to a CompactFlash card. In this
way, the memory capacity of the
microcontroller circuit is consider-
ably extended. CompactFlash cards
are widely available these days at
very competitive prices and the lat-
est ones have a capacity of 1 GByte!
Apart from their ease of use, the
greatest thing about these cards is
their ability to retain data without a
backup supply voltage.
Applications of this interface are
only limited by your imagination and
could include a data logger, voice
recording/playback, and so on.
+5V
K1
1
2
A15
IC1.A
1
2
K2
3
4
A14
6
1
2
3
4
5
6
7
8
9
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
&
4
5
5
6
A13
D3
D4
D5
D6
D7
+5V
7
8
A12
9
10
CE1
11
12
+5V
RD
IC1.B
WR
13
14
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
13
12
WR
RD
15
16
8
&
R1
10
9
D1
17
18
D7
19
20
RESET
IC1 = 74HCT20
1N4148
C3
D6
21
22
A2
A1
A0
10
µ
16V
D5
23
24
D0
D1
D2
D4
25
26
D3
27
28
+5V
D2
29
30
A2
A1
D1
31
32
14
C1
C2
CompactFlash Card
D0
33
34
A0
IC1
100n
100n
7
Circuit diagram
The circuit diagram of the CF inter-
face is very simple indeed, see Fig-
ure 1 . The ‘electronics’ is down to
an address decoder made from 1
(yes one) logic gate (IC1a). This will
decode A12-A15 and select the Com-
pactFlash card if all of these address
lines are at logic High. Consequently
the CompactFlash card will occupy
the address range F000 H – FFFF H .
The rest of the circuit connects
the relevant CF card terminals to
those of the processor and provides
a supply voltage for the CF card.
Capacitors C1 and C2 provide the
necessary supply decoupling. C3, R1
and D1 produce a reset signal when
the supply is switched on.
That concludes our discussion of
the circuit. For more information on
the size and connection data of the
CF you are referred to the article on
the CompactFlash Drive in the April
2002 issue.
The artwork for the double-sided
PCB is shown in Figure 2 . Most
board space is taken up by the 50-
way connector for the CF card and
the 34-way boxheader for the CF-to-
micro links.
Although the circuit is not difficult
µ
C Board
Hardwired Address: 0xFxxx
020133 - 11
Figure 1. The circuit diagram of the CompactFlash interface consists of little more than two
connectors.
to build, care should be taken in the
soldering of the pinheader for the CF
card. The reason is obvious — the
pins are very close together!
The connection between the
interface (K1) and the Flash Micro
board (K8) consists of a short length
of 24-way flatcable with two IDCs
(insulation displacement connec-
tors). The introductory photograph
shows how the interface board may
be placed next to the Flash Micro
board. The CF card is fitted onto K2
in such a way that the side with the
print on it is at the top (see photo-
graph). Note that this extension does
not work if an LCD is connected to
the Flash Micro board.
mer’s task to instruct the processor to read
from, or write to, this memory area, and tell
the processor how to do just that!
The full specification of a CompactFlash
card is of a hefty size and could deter you
from writing your own software. To remove
this ‘CF fear’ to some extent we developed a
small demonstration program intended to
demonstrate the essential and useful func-
tions of the interface. The functions actually
used are listed in Table 1 . This little program,
or pieces of it, may be used as a template for
Tabel 1.
Main functions of
CompactFlash interface
Software
Without appropriate software, a
processor will ignore the presence of
a CompactFlash card within the
memory range. It is the program-
Command Name
Command code
READ SECTORS(S)
0x20
WRITE SECTOR(S)
0x30
IDENTIFY DRIVE
0xEC
12/2002
Elektor Electronics
79
855731462.141.png 855731462.152.png 855731462.001.png 855731462.012.png 855731462.023.png 855731462.034.png 855731462.045.png 855731462.056.png 855731462.067.png 855731462.077.png 855731462.079.png 855731462.080.png 855731462.081.png 855731462.082.png 855731462.083.png 855731462.084.png 855731462.085.png 855731462.086.png 855731462.087.png 855731462.088.png 855731462.089.png 855731462.090.png 855731462.091.png 855731462.092.png 855731462.093.png 855731462.094.png 855731462.095.png 855731462.096.png 855731462.097.png 855731462.098.png 855731462.099.png 855731462.100.png 855731462.101.png 855731462.102.png 855731462.103.png 855731462.104.png 855731462.105.png 855731462.106.png 855731462.107.png 855731462.108.png 855731462.109.png 855731462.110.png 855731462.111.png 855731462.112.png 855731462.113.png 855731462.114.png 855731462.115.png 855731462.116.png 855731462.117.png 855731462.118.png 855731462.119.png 855731462.120.png 855731462.122.png 855731462.123.png 855731462.124.png 855731462.125.png 855731462.126.png 855731462.127.png 855731462.128.png 855731462.129.png 855731462.130.png
 
MICRO CONTROLLER
your own programs, and should avoid
recourse to the ‘indigestible’ documentation
describing all the intricacies of a CF card. The
not so faint hearted will find these at the
CompactFlash Association website:
www.compactflash.org
The source code files for the CF
interface demo program, as well as
the program itself, may be obtained
free of charge from the Free Down-
loads page on Publishers’ website at
www.elektor-electronics.co.uk . For
IC1
Table 2.
CompactFlash Interface registers
Address
Read
Write
F000h (atrDATMSB)
D8 - D15
D8 - D15
F006h (atrALTERN) (atrDEVCTRL)
Alternate Status
Device control
Figure 2. Double-sided printed circuit board for
the CompactFlash interface board (board
available ready-made).
F007h (atrDRIVEAD)
Drive Address
F008h (atrDATLSB)
Data
Data
F009h (atrERROR) (atrFEATURE)
Error
Feature
F00Ah (atrSECCNT)
Sector Count
Sector Count
COMPONENTS LIST
F00Bh (atrSECNR)
Sector Number
Sector Number
F00Ch (atrCYLLOW)
Cylinder Low
Cylinder Low
Resistors:
R1 = 10k
F00Dh (atrCYLHIG)
Cylinder High
Cylinder High
F00Eh (atrDRHEAD)
Drive/Head
Drive/Head
F00Fh (atrSTATUS) (atrCOMMAND)
Status
Command
Capacitors:
C1,C2 = 100nF
C3 = 10 µ F 16V radial
Table 3.
Commands in example program
Semiconductors:
D1 = 1N4148
IC1 = 74HCT20
?
Help
Supply brief descriptions of all program functions
D
Display
Display buffer contents in hexadecimal as well as ASCII notation
Miscellaneous:
K1 = 34-way boxheader
K2 = 50-way 0.05”-grid pinheader, angled
(e.g., Farnell # 307-8127)
PCB, order code 020133-1 (see Readers
Services page)
Disk, source code file of demo program
order code 020133-11 or Free Download
I
Info
Display main data of CompactFlash card
R
Read
Read sector on CompactFlash card and copy contents into buffer
W
Write
Write buffer contents to sector on CompactFlash card
C
Cylinder
Modify currently selected cylinder
H
Head
Modify currently selected head
S
Sector
Modify currently selected sector
80
Elektor Electronics
12/2002
855731462.131.png 855731462.132.png 855731462.133.png 855731462.134.png 855731462.135.png 855731462.136.png 855731462.137.png 855731462.138.png 855731462.139.png 855731462.140.png 855731462.142.png 855731462.143.png 855731462.144.png 855731462.145.png 855731462.146.png 855731462.147.png 855731462.148.png 855731462.149.png 855731462.150.png 855731462.151.png 855731462.153.png 855731462.154.png 855731462.155.png 855731462.156.png 855731462.157.png 855731462.158.png 855731462.159.png 855731462.160.png 855731462.161.png 855731462.162.png 855731462.002.png 855731462.003.png 855731462.004.png 855731462.005.png 855731462.006.png 855731462.007.png 855731462.008.png 855731462.009.png 855731462.010.png 855731462.011.png 855731462.013.png 855731462.014.png 855731462.015.png 855731462.016.png 855731462.017.png 855731462.018.png 855731462.019.png 855731462.020.png 855731462.021.png 855731462.022.png 855731462.024.png 855731462.025.png 855731462.026.png 855731462.027.png 855731462.028.png 855731462.029.png 855731462.030.png 855731462.031.png 855731462.032.png 855731462.033.png 855731462.035.png 855731462.036.png 855731462.037.png 855731462.038.png 855731462.039.png 855731462.040.png 855731462.041.png 855731462.042.png 855731462.043.png 855731462.044.png 855731462.046.png 855731462.047.png 855731462.048.png 855731462.049.png 855731462.050.png 855731462.051.png 855731462.052.png 855731462.053.png 855731462.054.png 855731462.055.png 855731462.057.png 855731462.058.png 855731462.059.png 855731462.060.png 855731462.061.png 855731462.062.png 855731462.063.png 855731462.064.png 855731462.065.png 855731462.066.png 855731462.068.png 855731462.069.png 855731462.070.png 855731462.071.png 855731462.072.png 855731462.073.png
 
MICRO CONTROLLER
those without access to the Internet,
there’s floppy disk number 020133-
11 which may be ordered through
our Readers Services. The program
was written using the Tasking ‘C’
compiler, and some details may need
patching to run it on other compilers.
This may include the declarations of
the CF registers. Using the well-
known ‘MicroFlash’ utility, the pro-
gram may be downloaded directly
into the 89C8252 chip. Next, you may
use HyperTerminal or a similar ter-
minal emulation program to test the
different functions of the interface.
Use these communications settings:
9,600 bits/s, 1 start bit, 8 data bits
and no parity (9600N81).
When the program is started, the
CF card is first reset and some
salient data is retrieved from it. This
includes the sector at address CYL
1, HEAD 1, SECTOR 1, whose data
is copied into the buffer. Next, the
program expects the user to supply
a command.
files. File fragments may be ‘scattered’ all
over the memory area, hence the filing sys-
tem holds data that indicates the order in
which certain sectors have to be read to
‘assemble’ a file from the fragments stored on
the CF.
A full description of the structure of the
various filing systems employed for CF cards
would easily fill this entire magazine so it is
well beyond the scope of this article. The
demo program purposely avoids the use of a
filing system so it can remain simple while
getting the point across: demonstrate how
sectors on a CF card can be read and written.
If you want to know all the ins and outs of
the filing system used in Windows, you
should know that Microsoft have published
the full specification at
www.microsoft.com/hwdev/download/hard
ware/FATGEN103.doc
Finally
Before using a CompactFlash card, it
is recommended to make a backup
of its contents.
It should be noted that reformat-
ting for a specific system (digital
camera, PC) may be required once a
microcontroller has performed a
write action on a CompactFlash
card. This is caused by PCs and dig-
ital cameras employing a filing sys-
tem to enable data on the CF card to
be organised in folders and files.
This filing system employs a part of
the CF card’s memory to keep track
of the start of individual folders and
(020133-1)
Figure 3. Connecting-up the CF interface to the Flash Micro board.
12/2002
Elektor Electronics
81
855731462.074.png 855731462.075.png 855731462.076.png 855731462.078.png
 
Zgłoś jeśli naruszono regulamin