SD card projects using the PIC microcontroller

SD Card Projects Using the
PIC Microcontroller
Dogan Ibrahim
!-34%2$!- s "/34/. s (%)$%,"%2' s ,/.$/.
.%7 9/2+ s /8&/2$ s 0!2)3 s 3!. $)%'/
3!. &2!.#)3#/ s 3).'!0/2% s 39$.%9 s 4/+9/
.EWNES IS AN IMPRINT OF %LSEVIER
.EWNES IS AN IMPRINT OF %LSEVIER
#ORPORATE $RIVE 3UITE "URLINGTON -! 53!
4HE "OULEVARD ,ANGFORD ,ANE +IDLINGTON /XFORD /8 '" 5+
© 2010 Elsevier Ltd. All rights reserved.
.O PART OF THIS PUBLICATION MAY BE REPRODUCED OR TRANSMITTED IN ANY FORM OR BY ANY MEANS ELECTRONIC OR
MECHANICAL INCLUDING PHOTOCOPYING RECORDING OR ANY INFORMATION STORAGE AND RETRIEVAL SYSTEM WITHOUT
PERMISSION IN WRITING FROM THE 0UBLISHER $ETAILS ON HOW TO SEEK PERMISSION FURTHER INFORMATION ABOUT THE
0UBLISHERS PERMISSIONS POLICIES AND OUR ARRANGEMENTS WITH ORGANIZATIONS SUCH AS THE #OPYRIGHT #LEARANCE #ENTER
AND THE #OPYRIGHT ,ICENSING !GENCY CAN BE FOUND AT OUR 7EB SITE WWWELSEVIERCOMPERMISSIONs
4HIS BOOK AND THE INDIVIDUAL CONTRIBUTIONS CONTAINED IN IT ARE PROTECTED UNDER COPYRIGHT BY THE 0UBLISHER OTHER
THAN AS MAY BE NOTED HEREIN
Notices
+NOWLEDGE AND BEST PRACTICE IN THIS lELD ARE CONSTANTLY CHANGING !S NEW RESEARCH AND EXPERIENCE BROADEN OUR
UNDERSTANDING CHANGES IN RESEARCH METHODS PROFESSIONAL PRACTICES OR MEDICAL TREATMENT MAY BECOME NECESSARY
0RACTITIONERS AND RESEARCHERS MUST ALWAYS RELY ON THEIR OWN EXPERIENCE AND KNOWLEDGE IN EVALUATING AND USING
ANY INFORMATION METHODS COMPOUNDS OR EXPERIMENTS DESCRIBED HEREIN )N USING SUCH INFORMATION OR METHODS
THEY SHOULD BE MINDFUL OF THEIR OWN SAFETY AND THE SAFETY OF OTHERS INCLUDING PARTIES FOR WHOM THEY HAVE A
PROFESSIONAL RESPONSIBILITY
4O THE FULLEST EXTENT OF THE LAW NEITHER THE 0UBLISHER NOR THE AUTHORS CONTRIBUTORS OR EDITORS ASSUME ANY LIABILITY
FOR ANY INJURY ANDOR DAMAGE TO PERSONS OR PROPERTY AS A MATTER OF PRODUCTS LIABILITY NEGLIGENCE OR OTHERWISE OR
FROM ANY USE OR OPERATION OF ANY METHODS PRODUCTS INSTRUCTIONS OR IDEAS CONTAINED IN THE MATERIAL HEREIN
Library of Congress Cataloging-in-Publication Data
)BRAHIM $OGAN
3$ CARD PROJECTS USING THE 0)# MICROCONTROLLER $OGAN )BRAHIM
P CM
)NCLUDES BIBLIOGRAPHICAL REFERENCES AND INDEX
)3". ALK PAPER
-ICROCONTROLLERSˆ0ROGRAMMING 0ROGRAMMABLE CONTROLLERS #OMPUTER STORAGE DEVICES ) 4ITLE
4*0) ˆDC
British Library Cataloguing-in-Publication Data
! CATALOGUE RECORD FOR THIS BOOK IS AVAILABLE FROM THE "RITISH ,IBRARY
&OR INFORMATION ON ALL .EWNES PUBLICATIONS
VISIT OUR 7EB SITE WWWELSEVIERDIRECTCOM
0RINTED IN THE 5NITED 3TATES OF !MERICA
Typeset by DIACRI4ECH #HENNAI )NDIA
Contents
Preface .............................................................................................................xix
About the Web Site.......................................................................................... xxiii
Chapter 1: Microcontroller Systems .......................................................................1
)NTRODUCTION -ICROCONTROLLER 3YSTEMS 2ANDOM !CCESS -EMORY 2EAD /NLY -EMORY 0ROGRAMMABLE 2EAD /NLY -EMORY %RASABLE 0ROGRAMMABLE 2EAD /NLY -EMORY %LECTRICALLY %RASABLE 0ROGRAMMABLE 2EAD /NLY -EMORY &LASH %%02/- -ICROCONTROLLER &EATURES "USES 3UPPLY 6OLTAGE 4HE #LOCK 4IMERS 7ATCHDOG 2ESET )NPUT )NTERRUPTS "ROWN/UT $ETECTOR !$ #ONVERTER 3ERIAL )/ %%02/- $ATA -EMORY ,#$ $RIVERS !NALOG #OMPARATOR 2EAL4IME #LOCK 3LEEP -ODE 0OWERON 2ESET ,OW0OWER /PERATION #URRENT 3INK3OURCE #APABILITY 53" )NTERFACE -OTOR #ONTROL )NTERFACE vii
viii
Contents
#ONTROLLER !REA .ETWORK )NTERFACE %THERNET )NTERFACE :IG"EE )NTERFACE -ICROCONTROLLER !RCHITECTURES 2EDUCED )NSTRUCTION 3ET #OMPUTER AND #OMPLEX )NSTRUCTION
3ET #OMPUTER #HOOSING A 0)# -ICROCONTROLLER .UMBER 3YSTEMS $ECIMAL .UMBER 3YSTEM "INARY .UMBER 3YSTEM /CTAL .UMBER 3YSTEM (EXADECIMAL .UMBER 3YSTEM #ONVERTING "INARY .UMBERS INTO $ECIMAL #ONVERTING $ECIMAL .UMBERS INTO "INARY #ONVERTING "INARY .UMBERS INTO (EXADECIMAL #ONVERTING (EXADECIMAL .UMBERS INTO "INARY #ONVERTING (EXADECIMAL .UMBERS INTO $ECIMAL #ONVERTING $ECIMAL .UMBERS INTO (EXADECIMAL #ONVERTING /CTAL .UMBERS INTO $ECIMAL #ONVERTING $ECIMAL .UMBERS INTO /CTAL #ONVERTING /CTAL .UMBERS INTO "INARY #ONVERTING "INARY .UMBERS INTO /CTAL .EGATIVE .UMBERS !DDING "INARY .UMBERS 3UBTRACTING "INARY .UMBERS -ULTIPLICATION OF "INARY .UMBERS $IVISION OF "INARY .UMBERS &LOATING 0OINT .UMBERS 30
#ONVERTING A &LOATING 0OINT .UMBER INTO $ECIMAL .ORMALIZING THE &LOATING 0OINT .UMBERS #ONVERTING A $ECIMAL .UMBER INTO &LOATING 0OINT 33
-ULTIPLICATION AND $IVISION OF &LOATING
0OINT .UMBERS !DDITION AND 3UBTRACTION OF &LOATING 0OINT .UMBERS "INARY#ODED $ECIMAL .UMBERS 3UMMARY %XERCISES Chapter 2: PIC18F Microcontroller Series ............................................................41
0)#&88 !RCHITECTURE 0ROGRAM -EMORY /RGANIZATION $ATA -EMORY /RGANIZATION 4HE #ONlGURATION 2EGISTERS 4HE 0OWER 3UPPLY 4HE 2ESET Contents
ix
4HE #LOCK 3OURCES 7ATCHDOG 4IMER 0ARALLEL )/ 0ORTS 4IMERS #APTURE#OMPARE07- -ODULES 0ULSE 7IDTH -ODULATION -ODULE !NALOGTO$IGITAL #ONVERTER -ODULE )NTERRUPTS 3UMMARY %XERCISES Chapter 3: Memory Cards ................................................................................107
-EMORY #ARD 4YPES 3MART -EDIA #ARD -ULTIMEDIA #ARD #OMPACT &LASH #ARD -EMORY 3TICK #ARD -ICRODRIVE X$ #ARD 3ECURE $IGITAL #ARD 3TANDARD 3$ #ARDS (IGH#APACITY 3$ #ARDS -EMORY #ARD 2EADERS -EMORY #ARD 0HYSICAL 0ROPERTIES -EMORY #ARD 4ECHNICAL 0ROPERTIES $ETAILED 3$ #ARD 3TRUCTURE 3$ #ARD 0IN #ONlGURATION 3$ #ARD )NTERFACE 3$ #ARD )NTERNAL 2EGISTERS /#2 2EGISTER #)$ 2EGISTER #3$ 2EGISTER 2#! 2EGISTER $32 2EGISTER 3#2 2EGISTER 3$ 3TATUS 2EGISTER #ALCULATING THE 3$ #ARD #APACITY 3$ #ARD 30) "US 0ROTOCOL $ATA 2EAD $ATA 7RITE 2ESPONSE 4OKENS $ATA 4OKENS #ARD 2ESET 3TATE 3UMMARY %XERCISES x Contents
Chapter 4: Programming with the MPLAB C18 Compiler ....................................137
# 0ROGRAMMING ,ANGUAGES FOR 0)# -ICROCONTROLLERS -0,!" # #OMPILER )NSTALLING THE -0,!" # #OMPILER !N %XAMPLE 0ROGRAM "UILDING THE 0ROJECT 3IMULATING THE 0ROJECT &LASHING ,ED %XAMPLE "UILDING AND 3IMULATING THE 0ROJECT 3TRUCTURE OF THE -0,!" # #OMPILER #OMMENTS 4ERMINATING 0ROGRAM 3TATEMENTS 7HITE 3PACES #ASE 3ENSITIVITY 6ARIABLE .AMES 6ARIABLE 4YPES #ONSTANTS %SCAPE 3EQUENCES 3TATIC 6ARIABLES %XTERNAL 6ARIABLES 6OLATILE 6ARIABLES %NUMERATED 6ARIABLES !RRAYS 0OINTERS 3TRUCTURES 5NIONS /PERATORS IN # -ODIFYING THE &LOW OF #ONTROL )TERATION 3TATEMENTS -IXING # WITH !SSEMBLY ,ANGUAGE 3TATEMENTS 0)# -ICROCONTROLLER )/ 0ORT 0ROGRAMMING 0ROGRAMMING %XAMPLES &UNCTIONS &UNCTION 0ROTOTYPES 0ASSING !RRAYS TO &UNCTIONS 0ASSING 6ARIABLES BY 2EFERENCE TO &UNCTIONS 3TATIC &UNCTION 6ARIABLES -0,!" # ,IBRARY &UNCTIONS $ELAY &UNCTIONS #HARACTER #LASSIlCATION &UNCTIONS $ATA #ONVERSION &UNCTIONS -EMORY AND 3TRING -ANIPULATION &UNCTIONS 2ESET &UNCTIONS #HARACTER /UTPUT &UNCTIONS Contents
xi
-ATH ,IBRARY &UNCTIONS ,#$ &UNCTIONS 3OFTWARE #!. &UNCTIONS 3OFTWARE )# "US &UNCTIONS 3OFTWARE 30) "US &UNCTIONS 3OFTWARE 5!24 &UNCTIONS (ARDWARE !NALOGTO$IGITAL !$ #ONVERTER &UNCTIONS (ARDWARE )NPUT #APTURE &UNCTIONS (ARDWARE )# &UNCTIONS (ARDWARE )/ 0ORT &UNCTIONS (ARDWARE -ICROWIRE &UNCTIONS (ARDWARE 0ULSE 7IDTH -ODULATION &UNCTIONS (ARDWARE 30) &UNCTIONS (ARDWARE 4IMER &UNCTIONS (ARDWARE 53!24 &UNCTIONS 3UMMARY %XERCISES Chapter 5: PIC18 Microcontroller Development Tools .........................................257
3OFTWARE $EVELOPMENT 4OOLS 4EXT %DITORS !SSEMBLERS AND #OMPILERS 3IMULATORS (IGH,EVEL ,ANGUAGE 3IMULATORS )NTEGRATED $EVELOPMENT %NVIRONMENTS (ARDWARE $EVELOPMENT 4OOLS $EVELOPMENT "OARDS $EVICE 0ROGRAMMERS )N#IRCUIT $EBUGGERS )N#IRCUIT %MULATORS "READBOARDS 5SING THE -0,!" )#$ )N#IRCUIT $EBUGGER 4HE $EBUGGING 0ROCESS 4HE -0,!" )#$ 4EST )NTERFACE "OARD 0ROGRAMMING WITH THE -0,!" )#$ $EBUGGER -0,!" )#$ $EBUGGING %XAMPLE ) -0,!" )#$ $EBUGGING %XAMPLE )) -0,!" )#$ $EBUGGING %XAMPLE ))) 3UMMARY %XERCISES Chapter 6: PIC18 Microcontroller MPLAB C18-Based Simple Projects .................299
0ROGRAM $ESCRIPTION ,ANGUAGE 34!24%.$ 300
3EQUENCING 300
xii
Contents
)&4(%.%,3%%.$)& $/%.$$/ 2%0%!45.4), 303
0ROJECT n #HASING ,%$S 0ROJECT $ESCRIPTION 0ROJECT (ARDWARE 0ROJECT 0$, 0ROJECT 0ROGRAM &URTHER $EVELOPMENT 0ROJECT n ,%$ $ICE 0ROJECT $ESCRIPTION 0ROJECT (ARDWARE 0ROJECT 0$, 0ROJECT 0ROGRAM 5SING A 0SEUDORANDOM .UMBER 'ENERATOR 0ROJECT n 4WO$ICE 0ROJECT 0ROJECT $ESCRIPTION 0ROJECT (ARDWARE 0ROJECT 0$, 0ROJECT 0ROGRAM 0ROJECT n 4WO $ICE 0ROJECT n &EWER )/ 0INS 0ROJECT $ESCRIPTION 0ROJECT (ARDWARE 0ROJECT 0$, 0ROJECT 0ROGRAM -ODIFYING THE 0ROGRAM 0ROJECT n 3EVEN3EGMENT ,%$ #OUNTER 0ROJECT $ESCRIPTION 0ROJECT (ARDWARE 0ROJECT 0$, 330
0ROJECT 0ROGRAM 330
-ODIlED 0ROGRAM 0ROJECT n 4WO$IGIT -ULTIPLEXED 3EVEN3EGMENT ,%$ 333
0ROJECT $ESCRIPTION 333
0ROJECT (ARDWARE 0ROJECT 0$, 0ROJECT 0ROGRAM 0ROJECT n 4WO$IGIT -ULTIPLEXED 3EVEN3EGMENT ,%$ #OUNTER 7ITH
4IMER )NTERRUPT 0ROJECT $ESCRIPTION 0ROJECT (ARDWARE 0ROJECT 0$, 0ROJECT 0ROGRAM -ODIFYING THE 0ROGRAM Contents xiii
0ROJECT n &OUR$IGIT -ULTIPLEXED 3EVEN3EGMENT ,%$ #OUNTER 7ITH
4IMER )NTERRUPT 0ROJECT $ESCRIPTION 0ROJECT (ARDWARE 0ROJECT 0$, 0ROJECT 0ROGRAM -ODIFYING THE 0ROGRAM 5SING -0,!" # #OMPILER 4IMER ,IBRARY 2OUTINES 3UMMARY %XERCISES Chapter 7: Serial Peripheral Interface Bus Operation ..........................................361
4HE -ASTER 3YNCHRONOUS 3ERIAL 0ORT -ODULE -330 IN 30) -ODE 30) -ODE 2EGISTERS 33034!4 330#/. /PERATION IN 30) -ODE #ONlGURATION OF -330 FOR 30) -ASTER -ODE 30) "US -0,!" # ,IBRARY &UNCTIONS #LOSE30) $ATA2DY30) GETC30) GETS30) /PEN30) PUTC30) PUTS30) 2EAD30) 7RITE30) %XAMPLE OF AN 30) "US 0ROJECT 4# 4EMPERATURE 3ENSOR 4HE #IRCUIT $IAGRAM 4HE 0ROGRAM $ISPLAYING .EGATIVE 4EMPERATURES $ISPLAYING THE &RACTIONAL 0ART 3UMMARY %XERCISES Chapter 8: MPLAB C18 SD Card Functions and Procedures ................................395
)NSTALLATION OF THE -$$ ,IBRARY -$$ ,IBRARY &UNCTIONS &ILE AND $ISK -ANIPULATION &UNCTIONS ,IBRARY /PTIONS -EMORY 5SAGE ,IBRARY 3ETUP xiv
Contents
3EQUENCE OF &UNCTION #ALLS 2EADING FROM AN %XISTING &ILE 7RITING /NTO AN %XISTING &ILE $ELETING AN %XISTING &ILE $ETAILED &UNCTION #ALLS &3)NIT &3FOPEN &3FOPENPGM &3FCLOSE &3FEOF &3FREAD &3FWRITE &3REMOVE &3REMOVEPGM &3REWIND &3MKDIR &3RMDIR &3CHDIR &3FORMAT &3RENAME &IND&IRST &IND&IRSTPGM &IND.EXT 3ET#LOCK6ARS &3FPRINTF 3UMMARY %XERCISES Chapter 9: Secure Digital Card Projects .............................................................413
#REATING AN -0,!" # 4EMPLATE 3ETTING THE #ONlGURATION &ILES 4HE -EMORY -ODEL 02/*%#4 n 7RITING A 3HORT 4EXT -ESSAGE TO AN 3$ #ARD $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n 4IME 3TAMPING A &ILE $ESCRIPTION !IM "LOCK $IAGRAM Contents
xv
#IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n &ORMATTING A #ARD $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n $ELETING A &ILE $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n 2ENAMING A &ILE $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n #REATING A $IRECTORY $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n #REATE A $IRECTORY AND A &ILE $ESCRIPTION !IM "LOCK $IAGRAM xvi
Contents
#IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n &ILE #OPYING $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n $ISPLAYING &ILE ON A 0# $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 4HE 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n 2EADING A &ILENAME FROM THE 0# AND $ISPLAYING THE &ILE $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n ,OOKING FOR A &ILE $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n ,OOKING FOR A .UMBER OF &ILES WITH A 'IVEN &ILE %XTENSION $ESCRIPTION !IM "LOCK $IAGRAM Contents xvii
#IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n $ISPLAYING THE !TTRIBUTES OF A &ILE $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n 3$ #ARD &ILE (ANDLING $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n -%.5"ASED 3$ #ARD &ILE (ANDLING $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n $IGITAL $ATA ,OGGING TO 3$ CARD $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n 4EMPERATURE $ATA ,OGGING $ESCRIPTION !IM "LOCK $IAGRAM xviii
Contents
#IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK 02/*%#4 n 4EMPERATURE AND 0RESSURE $ATA ,OGGING WITH
2EAL4IME #LOCK $ESCRIPTION !IM "LOCK $IAGRAM #IRCUIT $IAGRAM /PERATION OF THE 0ROJECT 0ROGRAM #ODE $ESCRIPTION OF THE 0ROGRAM #ODE 3UGGESTIONS FOR &UTURE 7ORK Appendix A–MC33269 Data Sheet ..................................................................531
Appendix B–MAX232 Data Sheet ....................................................................533
Appendix C–LM35 Data Sheet .........................................................................535
Appendix D–MPX4115A Data Sheet ................................................................537
Index ..............................................................................................................539
CHA PTE R 3
Memory Cards
3.1 Memory Card Types
! MEMORY CARD ALSO CALLED A mASH MEMORY CARD IS A SOLIDSTATE ELECTRONIC DATA STORAGE
DEVICE &IRST INVENTED BY 4OSHIBA IN THE S MEMORY CARDS SAVE THE STORED DATA EVEN AFTER
THE MEMORY DEVICE IS DISCONNECTED FROM ITS POWER SOURCE 4HIS ABILITY TO RETAIN DATA IS THE KEY
FOR mASH MEMORY CARD APPLICATIONS FOR EXAMPLE IN DIGITAL CAMERAS WHERE THE SAVED PICTURES
ARE NOT LOST AFTER THE MEMORY CARD IS REMOVED FROM THE CAMERA
.OWADAYS MEMORY CARDS ARE USED IN CONSUMER ELECTRONICS AND INDUSTRIAL APPLICATIONS
)N CONSUMER DEVICES WE SEE THE USE OF MEMORY CARDS IN APPLICATIONS LIKE
s
0ERSONAL COMPUTERS
s
$IGITAL CAMERAS
s
Mobile phones
s
6IDEO CAMERAS
s
.OTEBOOK COMPUTERS
s
'LOBAL POSITIONING SYSTEMS
s
-0 PLAYERS
s
0ERSONAL DIGITAL ASSISTANTS
)N INDUSTRIAL APPLICATIONS WE SEE THE USE OF MEMORY CARDS IN
s
%MBEDDED COMPUTERS
s
.ETWORKING PRODUCTS
s
-ILITARY SYSTEMS
s
#OMMUNICATION DEVICES
s
-EDICAL PRODUCTS
© 2010 Elsevier Ltd. All rights reserved.
D.O.I.: 10.1016/B978-1-85617-719-1.00007-5
107
108
Chapter 3
s
3ECURITY SYSTEMS
s
(ANDHELD SCANNERS
-EMORY CARDS ARE BASED ON TWO TECHNOLOGIES ./2 TECHNOLOGY AND .!.$ TECHNOLOGY
./2 TECHNOLOGY PROVIDES HIGHSPEED RANDOM ACCESS CAPABILITIES WHERE DATA AS
SMALL AS A SINGLE BYTE CAN BE RETRIEVED ./2 TECHNOLOGYBASED MEMORY CARDS ARE
OFTEN FOUND IN MOBILE PHONES PERSONAL DIGITAL ASSISTANTS AND COMPUTERS .!.$
TECHNOLOGY WAS INVENTED AFTER THE ./2 TECHNOLOGY AND IT ALLOWS SEQUENTIAL ACCESS TO
THE DATA IN SINGLE PAGES BUT CANNOT RETRIEVE SINGLE BYTES OF DATA LIKE ./2 FLASH .!.$
TECHNOLOGYBASED MEMORY CARDS ARE COMMONLY FOUND IN DIGITAL CAMERAS MOBILE
PHONES AUDIO AND VIDEO DEVICES AND OTHER DEVICES WHERE THE DATA IS WRITTEN AND READ
SEQUENTIALLY
4HERE ARE MANY DIFFERENT TYPES OF MEMORY CARDS AVAILABLE IN THE MARKET 3OME OF THE MOST
COMMONLY KNOWN MEMORY CARDS ARE
s
3MART MEDIA 3- CARD
s
-ULTIMEDIA CARD --#
s
#OMPACT mASH #& CARD
s
-EMORY STICK -3 CARD
s
-ICRODRIVE
s
X$ CARD
s
3ECURE DIGITAL 3$ CARD
4HE SPECIlCATIONS AND DETAILS OF EACH CARD ARE SUMMARIZED IN THE FOLLOWING SECTIONS
3.2 Smart Media Card
4HE 3- CARD WAS lRST DEVELOPED IN BY 4OSHIBA AND WAS ALSO CALLED THE 3OLID 3TATE
&LOPPY $ISC #ARD 33&$# 4HE 3- CARD CONSISTS OF A SINGLE .!.$ mASH CHIP EMBEDDED IN
A THIN PLASTIC CARD AND IT IS THE THINNEST CARD OF ALL &IGURE SHOWS A TYPICAL 3- CARD 4HE
DIMENSIONS OF THE CARD ARE s s MM AND IT WEIGHS ONLY G 4HE CARD CONSISTS
OF A mAT ELECTRODE TERMINAL WITH PINS
4HE 3- CARD WAS MAINLY USED IN &UJI AND /LYMPUS CAMERAS WHERE IT HAD APPROXIMATELY
OF THE MEMORY CARD SHARE IN 4HE CAPACITIES OF THESE CARDS RANGED FROM TO
-" AND THE DATA TRANSFER RATE WAS APPROXIMATELY -"S 3- CARDS STARTED HAVING
PROBLEMS AS CAMERA RESOLUTION INCREASED CONSIDERABLY AND CARDS GREATER THAN -" WERE
www.newnespress.com
Memory Card
109
Figure 3.1: Smart Media Card
Figure 3.2: Multimedia Card
NOT AVAILABLE 3- CARDS WERE DESIGNED TO OPERATE AT EITHER OR 6 AND A SMALL NOTCHED
CORNER WAS USED TO PROTECT 6 CARDS FROM BEING INSERTED INTO 6 READERS
3- CARDS INCORPORATED A COPY PROTECTION MECHANISM KNOWN AS THE h)$v WHICH GAVE EVERY
CARD A UNIQUE IDENTIlCATION NUMBER FOR USE WITH COPY PROTECTION SYSTEMS
3- CARDS ARE NO LONGER MANUFACTURED AND &UJIlLM AND /LYMPUS BOTH SWITCHED TO X$ CARDS
.OW NO DEVICES ARE DESIGNED TO USE 3- CARDS BUT -" CARDS FOR OLD DEVICES CAN STILL BE
OBTAINED FROM MEMORY CARD SUPPLIERS
3.3 Multimedia Card
--#S WERE lRST DEVELOPED IN THE LATE S BY )NTGENIX AND 3AN$ISK 4HESE CARDS WERE
INITIALLY USED IN MOBILE PHONE AND PAGER DEVICES BUT TODAY THEY ARE COMMONLY USED IN MANY
OTHER ELECTRONIC DEVICES --#S ARE BACKWARD COMPATIBLE WITH 3$ CARDS AND THEY CAN BE
PLUGGED INTO 3$ CARD SLOTS 4HE REVERSE IS NOT POSSIBLE BECAUSE 3$ CARDS ARE THICKER
MM AND WILL NOT lT INTO --# SLOTS &IGURE IS A PICTURE OF A TYPICAL --# 4HE CARD
DIMENSIONS ARE s s MM AND IT HAS PINS
4HE --# OPERATING VOLTAGE IS 6 AND THE DATA TRANSFER RATE IS APPROXIMATELY -"S
--#S ARE AVAILABLE WITH CAPACITIES UP TO '" 4HE OLDER --#S HAVE BEEN REPLACED BY
NEW MULTIMEDIA mobile CARDS 4HESE CARDS OFFER HIGHER PERFORMANCE THAN OLDER --#S AND
THEY OFFER LOWER WORKING VOLTAGES n 6 TO REDUCE POWER CONSUMPTION IN PORTABLE
DEVICES
www.newnespress.com
110
Chapter 3
3.4 Compact Flash Card
#& CARDS WERE lRST DEVELOPED IN BY 3AN$ISK 4HESE ARE THE CARDS OFFERING THE HIGHEST
CAPACITIES FROM -" TO '" 4ODAY #& CARDS ARE USED IN EXPENSIVE PROFESSIONAL DIGITAL
CAMERAS AND OTHER PROFESSIONAL MASS STORAGE DEVICES ,OWCAPACITY CARDS UP TO '" USE
THE &!4 lLING SYSTEM AND CARDS WITH CAPACITIES HIGHER THAN '" USE THE &!4 lLING
SYSTEM
4HERE ARE TWO VERSIONS OF #& CARDS 4YPE ) AND 4YPE )) 4HE ONLY PHYSICAL DIFFERENCE BETWEEN
THE TWO TYPES IS THAT 4YPE )) CARDS ARE THICKER THAN 4YPE ) CARDS 4YPE ) CARD DIMENSIONS ARE
s s MM AND 4YPE )) CARDS ARE s s MM "OTH CARDS HAVE PINS
4HE 4YPE ) INTERFACE CAN SUPPLY UP TO M! TO THE CARD AND THE 4YPE )) INTERFACE CAN SUPPLY
UP TO M! 4HE CARD OPERATING VOLTAGE IS OR 6 &IGURE SHOWS A TYPICAL #& CARD
4HERE ARE FOUR SPEEDS OF #& CARDS A 3TANDARD #& A #& (IGH 3PEED #& WITH A DATA
TRANSFER RATE OF -"S A FASTER #& WITH A DATA TRANSFER RATE OF -"S AND THE FASTEST
#& STANDARD WITH A DATA TRANSFER RATE OF -"S ! FUTURE VERSION OF THE #& CARDS
KNOWN AS #&AST WILL BE BASED ON THE 3ERIAL !4! BUS WITH AN EXPECTED SPEED OF -"S
4HE MEMORY CARD SPEED IS USUALLY SPECIlED USING THE hXv RATING 4HIS IS THE SPEED OF THE lRST
AUDIO #$2/- WHICH WAS +"S &OR EXAMPLE A CARD WITH A SPEED OF X CORRESPONDS
TO A DATA TRANSFER RATE OF s +"S -"S 4ABLE LISTS SOME OF THE COMMONLY
USED SPEED RATINGS IN MEMORY CARDS
4HE ADVANTAGES OF #& CARDS ARE AS FOLLOWS
s
#& CARDS ARE RUGGED AND MORE DURABLE THAN OTHER TYPES OF CARDS AND THEY CAN WITHSTAND
MORE PHYSICAL DAMAGE THAN OTHER CARDS
s
#& CARDS ARE AVAILABLE AT VERY HIGH STORAGE CAPACITIES
s
#& CARDS OPERATE AT HIGH SPEEDS
s
#& CARDS ARE COMPATIBLE WITH THE )$%!4! HARDDISK STANDARDS AND THUS THEY CAN BE
USED IN MANY EMBEDDED SYSTEMS TO REPLACE HARD DISKS
"ESIDES THE ADVANTAGES THE #& CARDS HAVE SOME DISADVANTAGES SUCH AS LACK OF A MECHANICAL
WRITE PROTECTION SWITCH OR NOTCH AND ITS LARGE DIMENSIONS IN COMPARISON WITH OTHER CARDS
LIMIT ITS USE IN SLIM DEVICES
Figure 3.3: Compact Flash Card
www.newnespress.com
Memory Card
111
Table 3.1: Memory Card Speed Ratings
Speed Rating
Speed (MB/s)
6x
32x
40x
66x
100x
133x
150x
200x
266x
300x
0.9
4.8
6.0
10.0
15.0
20.0
22.5
30.0
40.0
45.0
Figure 3.4: Memory Stick Card
3.5 Memory Stick Card
4HE -3 CARDS WERE lRST DEVELOPED BY 3ONY IN !LTHOUGH THE ORIGINAL -3 WAS ONLY
-" THE LARGEST CAPACITY CURRENTLY AVAILABLE IS '" &IGURE SHOWS A TYPICAL
-3 CARD
4HE ORIGINAL -3 ALTHOUGH IT IS NOT MANUFACTURED ANY MORE IS APPROXIMATELY THE SIZE AND
THICKNESS OF A STICK OF CHEWING GUM -3 HAS NOW BEEN REPLACED WITH -EMORY 3TICK 02/
-EMORY 3TICK $UO AND -EMORY 3TICK 02/('
-EMORY 3TICK 02/ WAS INTRODUCED IN AS A JOINT EFFORT BETWEEN 3ONY AND 3AN$ISK AND
IT ALLOWS A GREATER STORAGE CAPACITY AND FASTER lLE TRANSFER RATE THAN THE ORIGINAL -3
-EMORY 3TICK $UO WAS DEVELOPED AS A RESULT OF THE NEED FOR SMALLER AND FASTER MEMORY
CARDS )T IS SMALLER THAN THE STANDARD -3 CARD BUT AN ADAPTER ALLOWS IT TO BE USED IN ORIGINAL
-3 APPLICATIONS
-EMORY 3TICK 02/(' WAS DEVELOPED BY 3ONY AND 3AN$ISK TOGETHER IN 4HE DATA
TRANSFER SPEED OF THIS CARD IS -"S WHICH EXCEEDS THE SPEEDS OF ALL PREVIOUS MEMORY CARDS
AND IS APPROXIMATELY THREE TIMES FASTER THAN THE -EMORY 3TICK 02/ CARDS
www.newnespress.com
112
Chapter 3
3.6 Microdrive
-ICRODRIVE IS BASICALLY A HARD DISK DESIGNED TO lT INTO A 4YPE )) #& CARD SIZE ENCLOSURE
!LTHOUGH THE SIZE OF A MICRODRIVE IS SAME AS THAT OF A #& CARD ITS POWER CONSUMPTION IS
MUCH HIGHER THAN mASH MEMORIES AND THEREFORE CANNOT BE USED IN LOWPOWER APPLICATIONS
4HE CAPACITY OF MICRODRIVES IS '" OR MORE &IGURE SHOWS A TYPICAL MICRODRIVE
4HE PHYSICAL DIMENSIONS OF MICRODRIVES ARE s s MM AND THEY WEIGH
APPROXIMATELY G 4HE lRST MICRODRIVE WAS DEVELOPED BY )"- IN WITH A CAPACITY OF
AND -" 3OON AFTER THE CAPACITY WAS INCREASED TO GREATER THAN '" IN THE YEAR BY (ITACHI -ICRODRIVES WITH A CAPACITY OF '" WERE INTRODUCED IN BY (ITACHI AND
3EAGATE
4HE ADVANTAGE OF MICRODRIVES IS THAT THEY ALLOW MORE WRITE CYCLES THAN THE MEMORY CARDS
)N ADDITION MICRODRIVES ARE BETTER AT HANDLING POWER LOSS IN THE MIDDLE OF WRITING /NE OF THE
DISADVANTAGES OF MICRODRIVES IS THAT THEY DO NOT SURVIVE IF DROPPED FROM A HEIGHT OF M
)N ADDITION THEIR TRANSFER SPEEDS ARE AROUND -"S WHICH IS LOWER THAN MOST OF THE PRESENT
DAY HIGHEND MEMORY CARDS )N ADDITION THEY ARE NOT DESIGNED TO OPERATE AT HIGH ALTITUDES
AND THEIR POWER CONSUMPTION IS HIGH COMPARED WITH MEMORY CARDS
3.7 xD Card
X$ STANDS FOR ExTREME DIGITAL AND THESE CARDS ARE MAINLY USED IN DIGITAL CAMERAS DIGITAL
VOICE RECORDERS AND -0 PLAYERS X$ CARDS WERE DEVELOPED BY /LYMPUS AND &UJIlLM IN
AND THEN MANUFACTURED BY 4OSHIBA #ORPORATION AND 3AMSUNG %LECTRONICS &IGURE IS A PICTURE OF A TYPICAL X$ CARD X$ CARDS ARE AVAILABLE IN THREE TYPES 4YPE - 4YPE ( AND
Type M
Figure 3.5: Microdrive
Figure 3.6: xD Card
www.newnespress.com
Memory Card
113
4YPE - CARDS WERE DEVELOPED IN AND ARE AVAILABLE IN CAPACITIES UP TO '" 4HE READ
AND WRITE SPEEDS OF THESE CARDS ARE AND -"S RESPECTIVELY
4YPE ( X$ CARDS WERE lRST RELEASED IN HAVE THE ADVANTAGE OF A HIGHER DATA TRANSFER
SPEED 4HESE CARDS ARE ALSO AVAILABLE IN CAPACITIES UP TO '" WITH READ AND WRITE SPEEDS
OF AND -"S RESPECTIVELY 5NFORTUNATELY THE PRODUCTION OF 4YPE ( CARDS HAS NOW BEEN
DISCONTINUED DUE TO THEIR HIGH PRODUCTION COSTS
Type M X$ CARDS WERE lRST RELEASED IN AND THEIR CAPACITIES ARE UP TO '" 4HESE
CARDS ARE THE FASTEST X$ CARDS WITH READ AND WRITE SPEEDS OF AND -"S RESPECTIVELY
4HE ADVANTAGE OF X$ CARDS IS THAT THEY ARE FASTER THAN 3- CARDS --#S AND -3 CARDS )N
ADDITION THEIR SMALL SIZE MAKES THEM ATTRACTIVE IN PORTABLE LOWPOWER APPLICATIONS 3OME
OF THE DISADVANTAGES OF X$ CARDS ARE THEIR HIGHER COST BIGGER SIZE THAN SOME OTHER MEMORY
CARDS SUCH AS MICRO3$ AND THE FACT THAT THEY ARE PROPRIETARY TO &UJIlLM AND /LYMPUS 4HIS
MEANS THAT THERE IS NO PUBLICLY AVAILABLE DOCUMENTATION ON THEIR DESIGN AND IMPLEMENTATION
3.8 Secure Digital Card
3$ CARDS ARE PROBABLY THE MOST WIDELY USED MEMORY CARDS TODAY 4HE 3$ CARD WAS ORIGINALLY
DEVELOPED BY -ATSUSHITA 3AN$ISK AND 4OSHIBA IN 3$ CARDS NOWADAYS A USED IN MANY
PORTABLE DEVICES SUCH AS DIGITAL CAMERAS MOBILE PHONES 0$!S HANDHELD COMPUTERS VIDEO
RECORDERS '03 RECEIVERS VIDEO GAME CONSOLES AND SO ON
3TANDARD 3$ CARDS ARE AVAILABLE WITH CAPACITIES FROM -" TO '" 2ECENTLY A NEW TYPE
OF 3$ CARD CALLED THE HIGHCAPACITY 3$ CARD 3$(# HAS BEEN DEVELOPED WITH CAPACITIES
RANGING FROM TO '" )T HAS BEEN ANNOUNCED THAT A NEW SPECIlCATION CALLED E8TENDED
#APACITY 3$8# WILL ALLOW CAPACITIES TO REACH 4"
3$ CARDS ARE BASED ON --# BUT THEY HAVE A NUMBER OF DIFFERENCES 3$ CARDS ARE PHYSICALLY
THICKER THAN --#S AND WOULD NOT lT INTO --# SLOTS 4HE --# ON THE OTHER HAND CAN BE
EASILY INSERTED INTO 3$ CARD SLOTS )N ADDITION 3$ CARDS ARE SHAPED ASYMMETRICALLY TO PREVENT
THEM BEING INSERTED UPSIDE DOWN WHEREAS AN --# WOULD GO IN EITHER DIRECTION ALTHOUGH IT
WILL NOT MAKE CONTACT IF INSERTED UPSIDE DOWN )N ADDITION THE INTERNAL REGISTER STRUCTURES OF
THE TWO TYPES OF CARDS ARE NOT THE SAME
3.8.1 Standard SD Cards
3$ CARDS ARE AVAILABLE IN THREE DIFFERENT SIZES NORMAL 3$ MINI3$ AND MICRO3$ &IGURE SHOWS THE THREE TYPES OF 3$ CARDS
.ORMAL 3$ CARDS HAVE THE DIMENSIONS s s MM AND A WEIGHT OF G
! WRITEPROTECT SWITCH IS PROVIDED ON THE CARD TO STOP ACCIDENTAL DELETION OF THE CONTENTS OF
www.newnespress.com
Chapter 3
32.0 mm
114
21.5 mm
24.0 mm
11.0 mm
20.0 mm
15.0 mm
Figure 3.7: SD Cards
THE CARD 4HE DATA TRANSFER SPEED IS APPROXIMATELY n -"S .ORMAL 3$ CARDS OPERATE AT
n 6 AND HAVE PINS
MINI3$ CARDS WERE lRST RELEASED IN 4HEY HAVE THE DIMENSIONS s s MM
AND A WEIGHT OF G ! WRITEPROTECT SWITCH IS NOT PROVIDED ON THE CARD 4HE DATA TRANSFER
SPEED IS APPROXIMATELY -"S MINI3$ CARDS OPERATE AT n 6 AND HAVE PINS
MINI3$ CARDS ARE AVAILABLE IN CAPACITIES RANGING FROM -" TO '"
MICRO3$ CARDS WERE RELEASED IN AND THEY HAVE THE DIMENSIONS s s
MM AND A WEIGHT OF G !S IN THE MINI3$ CARDS NO WRITEPROTECT SWITCH IS PROVIDED
ON THE CARD 4HE DATA TRANSFER RATE AND THE CARD OPERATING VOLTAGES ARE SAME AS IN MINI3$
CARDS AND THEY HAVE PINS MICRO3$ CARDS ARE AVAILABLE IN CAPACITIES RANGING FROM -"
TO '"
3TANDARD 3$ CARDS ARE AVAILABLE UP TO A CAPACITY OF '" 4ABLE SHOWS A COMPARISON OF ALL
THREE STANDARD 3$ CARDS MINI3$ AND MICRO3$ CARDS CAN BE USED WITH ADAPTERS IN NORMAL 3$
CARD APPLICATIONS &IGURE SHOWS A TYPICAL MINI3$ CARD ADAPTER
www.newnespress.com
Memory Card
115
Table 3.2: Comparison of Standard SD Cards
Property
SD
miniSD
microSD
Width
Length
Thickness
Weight
Operating voltage
No. of pins
24 mm
32 mm
2.1 mm
2g
2.7–3.6 V
9
20 mm
21.5 mm
1.4 mm
1g
2.7–3.6 V
11
11 mm
15 mm
1 mm
0.5 g
2.7–3.6 V
8
Figure 3.8: miniSD Card Adapter
3TANDARD 3$ CARDS UP TO '" ARE USUALLY SHIPPED WITH THE &!4 lLE SYSTEM PRELOADED
ON THE CARD
3.8.2 High-Capacity SD Cards
3ECURE $IGITAL 3$(# WAS RELEASED IN AND IS AN EXTENSION OF THE STANDARD 3$ CARD
FORMAT 3$(# CARDS PROVIDE CAPACITIES F '" UP TO '" )T IS IMPORTANT TO REALIZE THAT
ALTHOUGH THE 3$(# CARDS HAVE THE SAME PHYSICAL DIMENSIONS AS THE STANDARD 3$ CARDS THEY
USE DIFFERENT PROTOCOLS AND AS SUCH WILL ONLY WORK IN 3$(#COMPATIBLE DEVICES AND NOT IN
STANDARD 3$ CARD APPLICATIONS 3$(# CARDS SHOULD NOT BE USED IN STANDARD 3$ COMPATIBLE
DEVICES 3TANDARD 3$ CARDS ARE HOWEVER FORWARD COMPATIBLE WITH 3$(# HOST DEVICES
MAKING STANDARD 3$ CARDS COMPATIBLE WITH BOTH 3$ AND 3$(# HOST DEVICES
3$(# CARDS OFFER
s
,ARGER DATA CAPACITIES
s
,ARGER NUMBER OF lLES
s
&!4 lLING SYSTEM INSTEAD OF THE &!4
s
(IGHER DATA TRANSFER RATES
s
#ONTENT PROTECTION FOR RECORDABLE MEDIA #02- COPYRIGHT PROTECTION
s
3TANDARD 3$ CARD PHYSICAL SIZE COMPATIBILITY
www.newnespress.com
116
Chapter 3
Figure 3.9: Class 6 SDHC Card
Figure 3.10: A Typical Memory Card Reader
3$(# CARDS HAVE 3PEED #LASS 2ATINGS DElNED BY THE 3$ !SSOCIATION 4HE DElNED CLASSES ARE
s
#LASS DATA TRANSFER RATE -"S
s
#LASS DATA TRANSFER RATE -"S
s
#LASS DATA TRANSFER RATE -"S
4HE 3PEED #LASS 2ATING OF A CARD IS LABELED ON THE CARD &IGURE SHOWS A TYPICAL #LASS 3$(# CARD 3$(# CARDS ARE IDENTIlED WITH THE LETTERS h(#v LABELED ON THE CARD AS A LOGO
3$(# CARDS ARE NORMALLY SHIPPED WITH THE &!4 lLING SYSTEM PRELOADED ON THE CARD 4HESE
CARDS ARE USED IN APPLICATIONS REQUIRING HIGH CAPACITIES SUCH AS VIDEO RECORDERS -0 PLAYERS
AND GENERAL LARGEVOLUME DATA STORAGE AND BY USERS IN GENERAL WHO WANT HIGHER PERFORMANCE
FROM THEIR HIGHEND DIGITAL DEVICES
,IKE STANDARD 3$ CARDS 3$(# CARDS COME IN THREE TYPES NORMAL 3$(# MINI3$(# AND
MICRO3$(#
3.9 Memory Card Readers
-EMORY CARD READERS ARE USUALLY IN THE FORM OF SMALL DEVICES WITH MANY DIFFERENT TYPES OF SOCKETS
COMPATIBLE WITH VARIOUS MEMORY CARDS &IGURE SHOWS A TYPICAL MEMORY CARD READER 4HE CARD
READER IS NORMALLY CONNECTED TO THE 53" PORT OF THE 0# AND MOST CARD READERS ACCEPT MOST OF THE
POPULAR CARDS AVAILABLE ON THE MARKET /LD CARD READERS ARE BASED ON THE 53" SPECIlCATION
WITH -BS WHEREAS NEW CARD READERS ARE BASED ON THE 53" SPECIlCATION WITH A MAXIMUM
DATA TRANSFER RATE OF -BS 7HEN A MEMORY CARD IS INSERTED INTO IT THE DEVICE AUTOMATICALLY
DETECTS THE CARD AND ASSIGNS A DRIVE LETTER TO THE SLOT WHERE THE CARD IS INSERTED $ATA ON THE CARD CAN
BE READ AS lLES OR lLES CAN BE COPIED TO THE CARD USING THE STANDARD 7INDOWS %XPLORER FUNCTIONS
www.newnespress.com
Memory Card
117
3.10 Memory Card Physical Properties
4ABLE GIVES A COMPARISON OF THE PHYSICAL PROPERTIES OF COMMONLY USED MEMORY CARDS
!S CAN BE SEEN FROM THE TABLE THE MICRO3$ CARD HAS THE SMALLEST FORM FACTOR
3.11 Memory Card Technical Properties
4ABLE GIVES A COMPARISON OF THE TECHNICAL PROPERTIES OF COMMONLY USED MEMORY CARDS
Table 3.3: Physical Properties of Memory Cards
Card
Width (mm)
Length (mm)
Thickness (mm)
Weight (g)
CF – Type I
CF – Type II
SM
MMC
RS-MMC
MMC-micro
MS
MS PRO Duo
SD
miniSD
microSD
xD
43.0
43.0
37.0
24.0
24.0
14.0
21.5
20.0
24.0
20.0
15.0
25.0
36.0
36.0
45.0
32.0
16.0
12.0
50.0
31.0
32.0
21.5
11.0
20.0
3.3
5.0
0.76
1.4
1.4
1.1
2.8
1.6
2.1
1.4
1.0
1.78
3.3
5.0
2.0
1.3
1.3
1.0
4.0
2.0
2.0
0.5
0.27
2.8
Table 3.4: Technical Properties of Memory Cards
Card
Max Capacity
(2009)
Max Write
Speed (MB/s)
Max Read
Speed (MB/s)
Operating
Voltage (V)
Pin Count
CF – Type I
CF – Type II
SM
MMC
RS-MMC
MMC micro
MS
MS PRO Duo
SD
miniSD
microSD
SDHC
32 GB
32 GB
128 MB
4 GB
2 GB
2 GB
128 MB
16 GB
4 GB
4 GB
4 GB
64 GB
133
133
20
52
52
40
160
160
150
100
100
48
133
133
20
52
52
40
160
160
150
100
100
48
3.5 and 5.0
3.3 and 5.0
3.3 and 5.0
3.3
3.3
3.3
3.3
3.3
3.3
3.3
3.3
3.3
50
50
22
7
7
13
10
10
9
11
8
9
www.newnespress.com
118
Chapter 3
3.12 Detailed SD Card Structure
!S THE TOPIC OF THIS BOOK IS 3$ CARDS THE INTERNAL STRUCTURE AND THE USE OF THESE CARDS IN 0)#
MICROCONTROLLERBASED SYSTEMS WILL BE DESCRIBED IN THIS SECTION
3.12.1 SD Card Pin Configuration
&IGURE SHOWS THE PIN CONlGURATION OF A STANDARD 3$ CARD 4HE CARD HAS NINE PINS AS
SHOWN IN THE lGURE AND A WRITEPROTECT SWITCH TO ENABLEDISABLE WRITING ONTO THE CARD
! STANDARD 3$ CARD CAN BE OPERATED IN TWO MODES THE SD Bus mode AND THE SPI Bus mode
3$ "US MODE IS THE NATIVE OPERATING MODE OF THE CARD AND ALL THE PINS ARE USED IN THIS MODE
$ATA IS TRANSFERRED USING FOUR PINS $n$ A CLOCK #,+ PIN AND A COMMAND LINE #-$
$ATA CAN BE TRANSFERRED FROM THE CARD TO THE HOST OR VICE VERSA OVER THE FOUR DATA LINES
&IGURE SHOWS THE 3$ CARD CONNECTION IN 3$ "US MODE
30) "US MODE IS THE MORE COMMONLY USED MODE AND IT ALLOWS DATA TO BE TRANSFERRED
ON TWO LINES $/ AND $) IN SERIAL FORMAT USING A CHIP SELECT #3 AND A #,+ LINE 4HE
30) MODE IS EASIER TO USE BUT IT HAS THE DISADVANTAGE OF REDUCED PERFORMANCE COMPARED
WITH THE 3$ MODE OF OPERATION &IGURE SHOWS THE 3$ CARD CONNECTIONS IN 30) MODE
3$ CARD PINS HAVE DIFFERENT MEANINGS DEPENDING UPON THE MODE OF OPERATION 4ABLE SHOWS
THE PIN ASSIGNMENTS WHEN THE CARD IS OPERATED IN 3$ "US AND 30) "US MODES
4HE PROJECTS IN THIS BOOK ARE BASED ON THE OPERATIONS IN THE 30) "US MODE 4HE FOLLOWING PINS
ARE USED IN 30) "US MODE
s
#HIP SELECT n 0IN s
$ATA IN
n 0IN s
#LOCK
n 0IN s
$ATA OUT
n 0IN 1 2 3 4 5 6 7 8
9
Figure 3.11: Standard SD Card Pin Configuration
www.newnespress.com
Memory Card
119
Vdd
CLK
D0-D3
SD card
CMD
D0-D3
SD card
Microcontroller
CMD
D0-D3
SD card
CMD
Vss
Figure 3.12: SD Card in SD Bus Mode
)N ADDITION PIN MUST BE CONNECTED TO THE SUPPLY VOLTAGE AND PINS AND MUST BE
CONNECTED TO THE SUPPLY GROUND
3.12.2 SD Card Interface
"EFORE WE CAN USE AN 3$ CARD IN AN ELECTRONIC CIRCUIT WE HAVE TO KNOW THE INTERFACE SIGNAL
LEVELS 4ABLE SHOWS THE INPUTnOUTPUT VOLTAGE LEVELS OF THE STANDARD 3$ CARDS
!CCORDING TO 4ABLE -INIMUM LOGIC OUTPUT VOLTAGE 6/( 6
www.newnespress.com
120
Chapter 3
Vdd
D0, D1, CLK
SD card
CS
D0, D1, CLK
SD card
Microcontroller
CS
D0, D1, CLK
SD card
CS
Vss
Figure 3.13: SD Card in SPI Bus Mode
Table 3.5: SD Card Pin Assignments
Pin No
Name
SD Mode
SPI Mode
1
2
3
4
5
6
7
8
9
CD/DAT3
CMD
Vss
Vdd
CLK
Vss
DAT0
DAT1
DAT2
Card detect/Data line
Command response
Ground
Supply voltage
Clock
Ground
Data line
Data line
Data line
Chip select
Data in
Ground
Supply voltage
Clock
Ground
Data out
Reserved
Reserved
www.newnespress.com
Memory Card
121
Table 3.6: SD Card Input–Output Voltage Levels
Symbol
Minimum
Logic 1 output voltage
VOH
Maximum
0.75 s Vdd
Logic 0 output voltage
VOL
Logic 1 input voltage
VIH
0.625 s Vdd
Vdd 0.3
Logic 0 input voltage
VIL
Vss 0.3
0.25 s Vdd
0.125 s Vdd
-AXIMUM LOGIC OUTPUT VOLTAGE 6/, 6
-INIMUM REQUIRED LOGIC INPUT VOLTAGE 6)( 6
-AXIMUM LOGIC INPUT VOLTAGE 6
-AXIMUM REQUIRED LOGIC INPUT VOLTAGE 6), 6
7HEN CONNECTED TO A 0)# MICROCONTROLLER THE OUTPUT VOLTAGE 6 OF THE
3$ CARD IS ENOUGH TO DRIVE THE INPUT CIRCUIT OF THE MICROCONTROLLER 4HE TYPICAL LOGIC
OUTPUT VOLTAGE OF A 0)# MICROCONTROLLER PIN IS 6 AND THIS IS TOO HIGH WHEN
APPLIED AS AN INPUT TO A MICROCONTROLLER PIN WHERE THE MAXIMUM VOLTAGE SHOULD NOT
EXCEED 6 !S A RESULT OF THIS IT IS REQUIRED TO USE RESISTORS AT THE INPUTS OF THE
3$ CARD TO LOWER THE INPUT VOLTAGE &IGURE SHOWS A TYPICAL 3$ CARD INTERFACE
TO A 0)# MICROCONTROLLER )N THIS FIGURE AND + RESISTORS ARE USED AS A
POTENTIAL DIVIDER CIRCUIT TO LOWER THE 3$ CARD INPUT VOLTAGE TO APPROXIMATELY 6
AS SHOWN BELOW
3$ CARD INPUT VOLTAGE 6 s + + + 6
)N &IGURE THE 3$ CARD IS CONNECTED TO 0/24# PINS OF THE MICROCONTROLLER AS
FOLLOWS
SD Card Pin
Microcontroller Pin
CS
RC2
CLK
RC3
DO
RC4
DI
RC5
4HIS IS THE RECOMMENDED CONNECTION BECAUSE IT USES THE 30) "US PORT PINS OF THE
MICROCONTROLLER 2# 2# AND 2#
www.newnespress.com
122
Chapter 3
PIC
Vdd
SD card
1 3.6 V 2.2 K
CS
5
CLK
7
DO
2.2 K
Vss DI 2
2.48 V
RC2
RC3
RC4
RC5
3,6
3.3 K
3.3 K
Figure 3.14: PIC Microcontroller SD Card Interface
3$ CARDS SUPPORT hHOTv INSERTION OF THE CARD IE THE CARD CAN BE INSERTED INTO THE CIRCUIT
WITHOUT POWERING DOWN THE HOST 4HIS IS USUALLY ACHIEVED THROUGH THE CARD CONNECTOR
#ONNECTOR MANUFACTURERS USUALLY PROVIDE SOCKETS THAT HAVE POWER PINS LONG ENOUGH TO POWER
THE CARD BEFORE ANY CONTACT IS MADE WITH THE OTHER PINS
! FEATURE OF MOST 3$ CARDS IS THE AUTOMATIC ENTRY AND EXIT FROM SLEEP MODE !FTER AN
OPERATION CARDS USUALLY ENTER A SLEEP MODE TO CONSERVE POWERIN IF NO MORE COMMANDS ARE
RECEIVED WITHIN MS !LTHOUGH THE HOST DOES NOT NEED TO DO ANYTHING FOR THIS TO HAPPEN IT
IS RECOMMENDED THAT THE HOST SHUT THE CLOCK GENERATION !NY COMMAND SENT TO THE CARD WILL
FORCE IT TO EXIT FROM THE SLEEP MODE
3$ CARDS CAN CONSUME UP TO n M! WHILE READING OR WRITING ONTO THE CARD 4HIS
IS USUALLY A HIGH CURRENT AND AN APPROPRIATE VOLTAGE REGULATOR CAPABLE OF SUPPLYING THE
REQUIRED CURRENT MUST BE USED IN THE DESIGN 4HE CARD CONSUMES APPROXIMATELY MA in
SLEEP MODE
3.13 SD Card Internal Registers
4HE OPERATIONS OF 3$ CARDS ARE CONTROLLED BY A NUMBER OF INTERNAL REGISTERS 3OME REGISTERS
ARE BITS WIDE SOME ARE BITS WIDE AND SOME ARE BITS WIDE 4ABLE GIVES A LIST OF
ALL THE REGISTERS
$ETAILED INFORMATION ON THE FUNCTIONS AND BIT DElNITIONS OF ALL THE REGISTERS CAN BE FOUND
IN THE PRODUCT MANUALS OF CARD MANUFACTURERS EG SanDisk Secure Digital Card, Product
Manual, Document no: 80-13-00169, 2003 4HE DETAILS OF THE IMPORTANT REGISTERS AND THEIR
BIT DElNITIONS ARE GIVEN IN THIS SECTION
www.newnespress.com
Memory Card
123
Table 3.7: SD Card Registers
Register
Width (Bits)
Description
OCR
CID
CSD
RCA
DSR
SCR
Status
32
128
128
16
16
64
512
Operation condition
Card information
Card specific information
Relative card address
Driver stage register
Special features
Status bits
3.13.1 OCR Register
4HE /#2 REGISTER IS BITS WIDE AND IT DESCRIBES THE OPERATING VOLTAGE RANGE AND STATUS BITS
IN THE POWER SUPPLY 4ABLE SHOWS THE BIT DElNITIONS OF THE /#2 REGISTER )N SUMMARY
s
"ITS n ARE RESERVED
s
"ITS n DESCRIBE THE 3$ CARD VOLTAGE
s
"ITS n ARE RESERVED
s
"IT IS THE POWERUP BUSY STATUS BIT 4HIS BIT IS SET TO hv AFTER THE POWERUP
INITIALIZATION OF THE CARD HAS BEEN COMPLETED
4HE INITIAL VALUE OF THE /#2 REGISTER IS USUALLY SET TO BINARY VALUE
h
v WHICH CORRESPONDS TO n 6 OPERATION /#2
BITS n ARE ALL LOGIC "IT h
v INDICATES THE BUSY STATUS OF THE CARD AT POWERUP
3.13.2 CID Register
4HIS IS A BIT REGISTER THAT CONTAINS THE CARD IDENTIlCATION INFORMATION SPECIlC TO CARD
MANUFACTURERS 4ABLE SHOWS THE BIT DElNITIONS OF THE #)$ REGISTER )N SUMMARY
s
"IT IS RESERVED AND IS ALWAYS hv
s
CRC: "ITS n ARE #2# BITS
s
MDT: "ITS n ARE THE MANUFACTURING DATE
s
s
"ITS n ARE THE -ONTH lELD H *ANUARY
s
"ITS n ARE THE 9EAR lELD H s
"ITS n ARE RESERVED ALL hvS
PSN: "ITS n ARE THE SERIAL NUMBER UNSIGNED INTEGER
www.newnespress.com
124
Chapter 3
Table 3.8: OCR Register Bit Definitions
OCR Bit
Card Voltage
Initial Value
31
Card busy bit
30–24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3–0
Reserved
3.6–3.5
3.5–3.4
3.4–3.3
3.3–3.2
3.2–3.1
3.1–3.0
3.0–2.9
2.9–2.8
2.8–2.7
2.7–2.6
2.6–2.5
2.5–2.4
2.4–2.3
2.3–2.2
2.2–2.1
2.1–2.2
2.0–1.9
1.9–1.8
1.8–1.7
1.7–1.6
Reserved
“0” busy, “1” ready
All “0”s
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
All “0”s
Table 3.9: CID Register Bit Definitions
Field
Width
Bit Position
Description
MID
OID
PNM
PRV
PSN
—
MDT
CRC
—
8
16
40
8
32
4
12
7
1
127–120
119–104
103–64
63–56
55–24
23–20
19–8
7–1
0
Manufacturer’s ID
Card OEM
Product code
Product revision
Serial number
0
Manufacturing date
Checksum
1
www.newnespress.com
Memory Card
s
PRV: "ITS n ARE THE 0RODUCT 2EVISION OF THE CARD
s
PNM: "ITS n ARE THE !3#))CHARACTER 0RODUCT #ODE FOR EXAMPLE
s
s
s
3$ IS -" CARD
s
3$ IS -" CARD
s
3$ IS -" CARD
125
OID: "ITS n ARE THE CARD /%- ALLOCATED BY THE 3$ #ARD !SSOCIATION FOR EXAMPLE
s
4- INDICATES 4OSHIBA
s
3$ INDICATES 3AN$ISK
MID: "ITS n ARE THE -ANUFACTURERS )$ FOR EXAMPLE
s
H INDICATES 4OSHIBA
s
H INDICATES 3AN$ISK
!S AN EXAMPLE THE 4OSHIBA -" CARD HAS THE FOLLOWING INITIAL VALUES IN ITS BIT #)$
REGISTER IN HEXADECIMAL h
v DEPENDS ON THE CARD AND hv DEPENDS ON VALUES ON THE CARD
MID: OID:
$
PNM: PRV:
PSN:
0
MDT: CRC: 3.13.3 CSD Register
#3$ IS THE BIT #ARD 3PECIlC $ATA REGISTER THAT CONTAINS INFORMATION REQUIRED TO ACCESS
THE DATA ON THE CARD 3OME lELDS OF THE #3$ REGISTER ARE READ ONLY WHEREAS SOME OTHER lELDS
ARE WRITEABLE 4ABLE SHOWS BIT DElNITIONS OF THE #3$ REGISTER )N SUMMARY
s
CSD_STRUCTURE: "ITS n ARE THE #3$ STRUCTURE VERSION NUMBER
s
"ITS n ARE RESERVED ALL hv
www.newnespress.com
126
Chapter 3
Table 3.10: CSD Register Bit Definitions
Field
Description
Width
Bits
*Value
Code
CSD_STRUCTURE
—
TAAC
NSAC
TRAN_SPEED
CCC
READ_BL_LEN
READ_BL_PARTIAL
WRITE_BLK_MISALIGN
READ_BLK_MISALIGN
DSR_IMP
—
C_SIZE
VDD_R_CURR_MIN
VDD_R_CURR_MAX
VDD_W_CURR_MIN
VDD_W_CURR_MAX
CSD structure
2
6
8
8
8
12
4
1
1
1
1
2
12
3
3
3
3
127–126
125–120
119–112
111–104
103–96
95–84
83–80
79–79
78–78
77–77
76–76
75–74
73–62
61–59
58–56
55–53
52–50
1.0
—
10 ms
0
25 MHz
All
512 bytes
Yes
No
No
No
—
899
100 mA
80 mA
100 mA
80 mA
00b
000000b
00001111b
00000000b
00110010b
1F5h
1001h
1b
0b
0b
0b
00b
383h
111b
110b
111b
110b
3
1
7
7
49–47
46–46
45–39
38–32
011b
1b
0011111b
1111111b
31–31
30–29
28–26
28–26
25–22
21–21
20–16
15–15
14–14
32
Yes
32 blocks
128
sectors
Yes
—
X16
X4
512 bytes
No
—
0
Not
original
Not
protected
Not
protected
HD w/
partition
—
C_SIZE_MULT
ERASE_BLK_EN
SECTOR_SIZE
WP_GRP_SIZE
Data read access time
Data read access time
Max data transfer rate
Command classes
Max read block length
Partial read blocks allowed
Write block misalignment
Read block misalignment
DSR implemented
Reserved
Device size
Max. Read current at Vdd min
Max. Read current at Vdd max
Max. Write current at Vdd min
Max. Write current at
Vdd max
Device size multiplier
Erase single block enable
Erase sector size
Write protect group size
WP_GRP_ENABLE
—
R2W_FACTOR
Write protect group enable
Reserved
Write speed factor
WRITE_BL_LEN
WRITE_BL_PARTIAL
—
FILE_FORMAT_GRP
COPY
Max write block length
Partial write allowed
Reserved
File format group
Copy flag
1
2
3
3
4
1
5
1
1
PERM_WRITE_PROTECT
Permanent write protection
1
13–13
TMP_WRITE_PROTECT
Temporary write protection
1
12–12
FILE_FORMAT
File format
2
11–10
—
Reserved
2
9–8
www.newnespress.com
1b
00b
100b
010b
1001b
0b
00000b
0b
0b
0b
0b
00b
00b
Memory Card
127
Table 3.10: CSD Register Bit Definitions —cont’d
Field
Description
Width
Bits
*Value
Code
CRC
—
CRC
Always 1
7
1
7–1
0–0
—
—
1b
*values are based on a 16 MB SanDisk card.
s
TAAC: "ITS n DElNE THE ASYNCHRONOUS PART OF THE READ ACCESS TIME OF THE CARD
4HE BITS ARE DECODED AS FOLLOWS
TAAC bit
n
n
Code
4IME UNIT
0 NS NS NS ±S ±S ±S
4IME VALUE
0 2ESERVED ! " # $ E & 2ESERVED
s
NSAC: "ITS n DElNE THE WORST CASE FOR THE CLOCKDEPENDENT FACTOR OF THE DATA
ACCESS TIME 4HE UNIT IS CLOCK CYCLES 4HE TOTAL ACCESS TIME IS EQUAL TO 4!!# PLUS
.3!#
s
TRAN_SPEED: "ITS n DElNE THE MAXIMUM DATA TRANSFER RATE 4HE BITS ARE
DECODED AS FOLLOWS
TRAN_SPEED bit
n
n
s
Code
4RANSFER 2ATE 5NIT
0 KBS -BS -BS -BS
n 2ESERVED
4IME 6ALUE
0 2ESERVED ! " # $ E & 2ESERVED
CCC: "ITS n DElNE THE COMMAND CLASSES THAT ARE SUPPORTED BY THE CARD 4HE BIT
DElNITIONS ARE AS FOLLOWS
CCC bit
Supported card command class
#LASS #LASS
www.newnespress.com
128
Chapter 3
…
s
…
#LASS READ_BL_LEN: "ITS n DElNE THE MAXIMUM READ DATA BLOCK LENGTH WHICH IS
EQUAL TO 2%!$?",?,%. 4HE DATA BLOCK LENGTH IS SPECIlED AS FOLLOWS
READ_BL_LEN
n
…
n
Block Length
2ESERVED
BYTES
…
BYTES
2ESERVED
s
"IT IS ALWAYS hv
s
WRITE_BLK_MISALIGN: "IT DElNES WHETHER THE DATA BLOCK TO BE WRITTEN BY ONE
COMMAND CAN BE SPREAD OVER MORE THAN ONE PHYSICAL BLOCK
WRITE_BLK_MISALIGN
s
Access Block boundary write
.OT ALLOWED
!LLOWED
READ_BLK_MISALIGN: "IT DElNES WHETHER THE DATA BLOCK TO BE READ BY ONE
COMMAND CAN BE SPREAD OVER MORE THAN ONE PHYSICAL BLOCK
READ_BLK_MISALIGN
Access Block boundary read
.OT ALLOWED
!LLOWED
s
DSR_IMP: "IT IF SET A DRIVER STAGE REGISTER $32 IS IMPLEMENTED
s
"ITS n ARE RESERVED
s
C_SIZE: "ITS n DElNE THE USERS DATA CARD CAPACITY AS FOLLOWS
-EMORY CAPACITY ",/#+.2 ",/#+?,%.
WHERE
",/#+.2 #?3):% -5,4
-5,4 #?3):?-5,4 IF #?3):%?-5,4 AND
",/#+?,%. 2%!$?",?,%.
s
IF 2%!$?",?,%. "ITS n DElNE THE MAXIMUM AND MINIMUM VALUES FOR READWRITE CURRENTS
www.newnespress.com
Memory Card
s
C_SIZE_MULT: "ITS n ARE USED TO COMPUTE THE USERS DATA CARD CAPACITY MULTIPLY
FACTOR
C_SIZE_MULT
s
129
MULT
3 ERASE_BLK_EN: "IT DElNES IF HOST CAN ERASE BY 72)4%?",?,%.
ERASE_BLK_EN
Description
(OST CANNOT ERASE BY 72)4%?",?,%.
(OST CAN ERASE BY 72)4%?",?,%.
s
SECTOR_SIZE: "ITS n DElNE THE MINIMUM ERASABLE SIZE AS THE NUMBER OF WRITE
BLOCKS
s
WP_GRP_SIZE: "ITS n DElNE THE MINIMUM NUMBER OF SECTORS THAT CAN BE SET FOR
THE WRITE PROTECT GROUP
s
WP_GRP_ENABLE: "IT DElNES THE WRITE PROTECT GROUP FUNCTIONS
WP_GRP_ENABLE
Description
.OT IMPLEMENTED
)MPLEMENTED
s
"ITS n ARE RESERVED
s
R2W_FACTOR: "ITS n DElNE A MULTIPLE NUMBER FOR A TYPICAL WRITE TIME AS A
MULTIPLE OF THE READ ACCESS TIME
s
WRITE_BL_LEN: "ITS n DElNE THE MAXIMUM WRITE BLOCK LENGTH WHICH IS
CALCULATED AS 72)4%?",?,%. 4HE DATA BLOCK LENGTH IS SPECIlED AS FOLLOWS
WRITE_BL_LEN
n
…
n
Block Length
2ESERVED
BYTES
…
BYTES
2ESERVED
www.newnespress.com
130
s
Chapter 3
WRITE_BL_PARTIAL: "IT DElNES WHETHER PARTIAL BLOCK WRITE IS AVAILABLE
WRITE_BL_PARTIAL
Write data size
/NLY 72)4%?",?,%. SIZE OF BYTES IS AVAILABLE
0ARTIAL SIZE WRITE AVAILABLE
s
"ITS n ARE RESERVED
s
FILE_FORMAT_GRP: "IT INDICATES THE SELECTED GROUP OF lLE FORMAT GROUP AND lLE
FORMAT
FILE_FORMAT_GRP FILE_FORMAT
s
Kinds
(ARD DISKLIKE lLE SYSTEM WITH PARTITION
table
$/3 &!4 WITH BOOT SECTOR ONLY NO
PARTITION TABLE
5NIVERSAL &ILE &ORMAT
/THERS
2ESERVED
COPY: "IT DElNES THE CONTENTS OF THE CARD AS ORIGINAL OR DUPLICATED 4HE BIT DElNITION IS
COPY
Description
/RIGINAL
#OPY
s
PERM_WRITE_PROTECT: "IT IF SET PERMANENTLY WRITE PROTECTS THE CARD
s
TMP_WRITE_PROTECT: "IT IF SET TEMPORARILY WRITE PROTECTS THE CARD
s
FILE_FORMAT: "ITS n DElNE THE lLE FORMAT ON THE CARD 4HIS lELD IS USED
TOGETHER WITH lELD &),%?&/2-!4?'20 AS IN THE ABOVE TABLE
s
"ITS n ARE RESERVED
s
CRC: "ITS n ARE THE #2# ERROR CHECKING BITS
s
"IT IS NOT USED AND IS ALWAYS hv
3.13.4 RCA Register
4HIS BIT REGISTER CARRIES THE CARD ADDRESSES IN 3$ CARD MODE
3.13.5 DSR Register
4HIS REGISTER IS NOT IMPLEMENTED IN MANY CARDS
www.newnespress.com
Memory Card
131
3.13.6 SCR Register
4HIS BIT REGISTER PROVIDES INFORMATION ON THE 3$ CARDS SPECIAL FEATURES SUCH AS THE STRUCTURE
VERSION NUMBER THE PHYSICAL LAYER SPECIlCATION THE SECURITY ALGORITHM USED AND THE BUS WIDTH
3.13.7 SD Status Register
4HIS BIT REGISTER DElNES THE CARD STATUS BITS AND CARD FEATURES
3.14 Calculating the SD Card Capacity
!N EXAMPLE IS GIVEN IN THIS SECTION TO SHOW HOW THE CAPACITY OF AN 3$ CARD CAN BE CALCULATED
N
Example 3.1
The following CSD register fields are given by a card manufacturer:
C_SIZE
E27h (or decimal 3623)
C_SIZE_MULT 3
READ_BL_LEN 9
Calculate the capacity of this card.
Solution
The card capacity is defined by two fields within the CSD register: C_SIZE and C_SIZE_
MULT. C_SIZE is a 12-bit value with an offset of 1 (1–4096), and C_SIZE_MULT is a
3-bit value with an offset of 2 (2–9).
The number of blocks on the card is given by
BLOCKNR (C_SIZE 1) s 2(C_SIZE_MULT 2),
where
C_SIZE_MULT 8.
The default block length is 512 bytes (but it can also be specified as 1024 or 2048
bytes). The block length is calculated from
BLOCK_LEN 2READ_BL_LEN,
where
READ_BL_LEN 9, 10, or 11.
Combining the two equations, we get the card capacity as
Card Capacity (in bytes) BLOCKNR s BLOCK_LEN
www.newnespress.com
132
Chapter 3
or
Card Capacity (in bytes) (C_SIZE 1) s 2 (C_SIZE_MULT + 2) s 2READ_BL_LEN.
The capacity is usually shown in MB and
Card Capacity (Megabyte) (C_SIZE 1) s 2(C_SIZE_MULT 2) s 2 READ_BL_LEN/(1024 s 1024)
Using the CSD parameters given in this example, we get
Card Capacity (Megabyte) 3624 s 32 s 512/(1024 s 1024) 56.525 Megabytes
It is interesting to note that when a block length of 1024 bytes is used (READ_BL_
LEN 10), cards up to 2 GB can be specified, and with a block length of 2048 bytes
(READ_BL_LEN 11), cards up to 4 GB can be specified.
3.15 SD Card SPI Bus Protocol
!LL COMMUNICATIONS BETWEEN THE HOST AND THE CARD ARE CONTROLLED BY THE HOST -ESSAGES
IN THE 30) BUS PROTOCOL CONSIST OF COMMANDS RESPONSES AND TOKENS 4HE CARD RETURNS
A RESPONSE TO EVERY COMMAND RECEIVED AND ALSO A DATA RESPONSE TOKEN FOR EVERY WRITE
COMMAND
4HE 3$ CARD WAKES UP IN 3$ CARD MODE AND IT WILL ENTER THE 30) MODE IF ITS #3 LINE IS HELD
LOW WHEN A RESET COMMAND IS SENT TO THE CARD 4HE CARD CAN ONLY BE RETURNED TO THE 3$ MODE
AFTER A POWERDOWN AND POWERUP SEQUENCE
7HEN THE 30) MODE IS ENTERED THE CARD IS IN THE NONPROTECTED MODE WHERE #2# CHECKING IS
NOT USED #2# CHECKING CAN BE TURNED ON AND OFF BY SENDING COMMAND #2#?/.?/&& COM
MAND NAME #-$ TO THE CARD
3.15.1 Data Read
$ATA CAN BE READ IN EITHER SINGLE OR MULTIPLE BLOCKS 4HE BASIC UNIT OF DATA SIZE IS BLOCKS
DElNED BY lELD 2%!$?",?,%. OF THE #3$ REGISTER )N THIS BOOK WE SHALL BE USING ONLY
SINGLEBLOCK READS 3INGLEBLOCK READS ARE INITIATED BY ISSUING THE COMMAND 2%!$?3).',%?
",/#+ #-$ TO THE CARD !NY VALID ADDRESS CAN BE USED AS THE STARTING ADDRESS
3.15.2 Data Write
$ATA CAN BE WRITTEN IN EITHER SINGLE OR MULTIPLE BLOCKS !FTER RECEIVING A VALID WRITE COMMAND
THE CARD SENDS A RESPONSE TOKEN AND THEN WAITS FOR THE DATA BLOCK TO BE SENT FROM THE HOST 4HE
STARTING ADDRESS CAN BE ANY VALID ADDRESS !FTER RECEIVING A DATA BLOCK FROM THE HOST THE CARD
RETURNS A DATA RESPONSE TOKEN AND WRITES THE DATA ON THE CARD IF THE DATA CONTAINS NO ERRORS
www.newnespress.com
Memory Card
133
Table 3.11: Some Important SD Card Commands
Command
Abbreviation
Argument
Response
Description
CMD0
CMD1
CMD9
CMD10
CMD17
CMD24
GO_IDLE_STATE
SEND_OP_COND
SEND_CSD
SEND_CID
READ_SINGLE_BLOCK
WRITE_BLOCK
None
None
None
None
Data address (0:31)
Data address (0:31)
R1
R1
R1
R1
R1
R1
Reset the SD card
Initialize card
Get CSD register data
Get CID register data
Read a block of data
Write a block of data
Table 3.12: Command Format
Byte 1
7
0
6
1
Bytes 2–5
543210
Command
31.........................................0
Command Argument
Byte 6
7654321
CRC
0
1
4HERE ARE A LARGE NUMBER OF COMMANDS AVAILABLE IN 30) MODE FOR READING THE CARD REGIS
TERS READING AND WRITING SINGLE AND MULTIPLE BLOCKS OF DATA ERASING BLOCKS ETC 4ABLE GIVES A LIST OF THE IMPORTANT 3$ CARD COMMANDS !LL 30) MODE COMMANDS ARE BYTES LONG
BITS !S SHOWN IN 4ABLE THE COMMANDS START WITH THE MOST SIGNIlCANT BIT -3"
AS LOGIC A TRANSMISSION BIT AS LOGIC BITS OF COMMAND INDEX BITS OF ARGUMENT NOT
ALL COMMANDS NEED ARGUMENTS BITS OF #2# AND AN ENDBIT LOGIC 4HE COMMANDS ARE
DIVIDED INTO CLASSES )F NO ARGUMENT IS REQUIRED IN A COMMAND THE VALUE OF THE ARGUMENT
lLED SHOULD BE ALL hvS 4HE COMMAND INDEX CONTAINS THE ACTUAL COMMAND NUMBER &OR
EXAMPLE THE COMMAND INDEX VALUE FOR COMMAND #-$ IS BINARY NUMBER IN BITS
IE hv
3.15.3 Response Tokens
4HERE ARE SEVERAL TYPES OF RESPONSE TOKENS THAT CAN BE SENT BY THE CARD ! TOKEN IS TRANSMITTED
WITH THE -3" BIT SENT lRST 4HE RESPONSE TOKENS ARE AS FOLLOWS
R1 Format: 4HIS RESPONSE TOKEN IS BYTE LONG AND IS SENT BY THE CARD AFTER EVERY
COMMAND EXCEPT THE 3%.$?34!453 COMMAND 4HE -3" BIT IS hv AND OTHER BITS
INDICATE AN ERROR hv BIT &OR EXAMPLE IF BIT hv IS SET IT INDICATES THAT THE CARD IS IN
)DLE 3TATE AND RUNNING INITIALIZATION SEQUENCE 4ABLE SHOWS BIT DElNITIONS OF THE
2 &ORMAT
R1b Format: 4HIS FORMAT IS SIMILAR TO 2 &ORMAT WITH THE ADDITION OF THE BUSY SIGNAL
www.newnespress.com
134
Chapter 3
Table 3.13: R1 Format bits
0
In idle state
Erase reset
Illegal command
CRC error
Erase_seq_error
Address error
Parameter error
R2 Format: 4HIS RESPONSE TOKEN IS BYTES LONG AND IS SENT AS A RESPONSE TO COMMAND
3%.$?34!453
R3 Format: 4HIS RESPONSE TOKEN IS BYTES LONG AND IS SENT IN RESPONSE TO COMMAND 2%!$?
/#2 4HE lRST BYTE IS IDENTICAL TO 2 FORMAT WHEREAS THE OTHER BYTES CONTAIN THE /#2
REGISTER DATA
Data Response Token: 7HENEVER A DATA BLOCK IS WRITTEN TO THE CARD THE CARD ACKNOWLEDGES
WITH A DATA RESPONSE 4HIS TOKEN IS BYTE LONG AND HAS THE FOLLOWING BIT DElNITIONS
"IT "ITS n
"IT "IT !LWAYS 3TATUS
!LWAYS 2ESERVED
4HE 3TATUS BITS ARE DElNED AS FOLLOWS
$ATA ACCEPTED
#2# ERROR DATA REJECTED
7RITE ERROR DATA REJECTED
3.16 Data Tokens
$ATA IS RECEIVED OR TRANSMITTED VIA DATA TOKENS WITH ALL DATA BYTES TRANSMITTED WITH THE -3" lRST
$ATA TOKENS ARE n BYTES LONG AND HAVE THE FOLLOWING FORMAT FOR SINGLEBLOCK OPERATIONS
s
&IRST "YTE 34!24 ",/#+
www.newnespress.com
Memory Card
135
4HIS BLOCK IS IDENTIlED BY DATA hv IE &%H
s
"YTES n 53%2 $!4!
s
,AST BYTES BYTE AND BYTE #2#
3.17 Card Reset State
!FTER POWERUP THE 3$ CARD IS IN THE )DLE 3TATE 3ENDING COMMAND #-$ ALSO PUTS THE CARD
IN THE )DLE 3TATE !T LEAST CLOCK CYCLES SHOULD BE SENT TO THE CARD WITH THE $ATA /UT AND #3
LINES SET TO LOGIC hv BEFORE STARTING TO COMMUNICATE WITH THE CARD
4HE 3$ CARD IS INITIALLY IN THE 3$ "US MODE )T WILL ENTER THE 30) MODE IF THE #3 LINE IS HELD
LOW WHILE SENDING THE #-$ COMMAND 7HEN THE CARD SWITCHES TO THE 30) MODE IT WILL
RESPOND WITH THE 30) MODE 2 RESPONSE FORMAT )N 30) MODE #2# CHECKING IS DISABLED BY
DEFAULT (OWEVER BECAUSE THE CARD POWERSUP IN THE 3$ "US MODE #-$ COMMAND MUST
BE SENT WITH A VALID #2# BYTE BEFORE THE CARD IS PUT INTO 30) MODE 7HEN SENDING THE #-$
COMMAND THE #2# BYTE IS lXED AND IS EQUAL TO H 4HE FOLLOWING HEXADECIMAL BYTE
COMMAND SEQUENCE CAN THEN BE USED TO SEND THE #-$ COMMAND AFTER A POWERUP SEE
4ABLE WITH THE COMMAND lELD SET TO hv FOR #-$
4HE STEPS TO SWITCH THE 3$ CARD INTO 30) MODE SHOULD THEREFORE BE AS FOLLOWS
s
0OWERUP
s
3END AT LEAST CLOCK PULSES TO THE CARD WITH #3 AND $ATA /UT LINES SET TO LOGIC hv
s
3ET #$ LINE LOW
s
3END BYTE #-$ COMMAND h v TO PUT THE CARD IN 30) MODE
s
#HECK 2 RESPONSE TO MAKE SURE THERE ARE NO ERROR BITS SET
s
3END COMMAND #-$ REPEATEDLY UNTIL THE hINIDLESTATEv BIT IN 2 RESPONSE IS SET TO hv
AND THERE ARE NO ERROR BITS SET
s
4HE CARD IS NOW READY FOR READWRITE OPERATIONS
$URING THE RESET STATE THE CARD CLOCK FREQUENCY SHOULD BE BETWEEN n +(Z !FTER THE RESET
STATE THE MAXIMUM CLOCK FREQUENCY CAN BE INCREASED TO -(Z -(Z FOR THE --#
3.18 Summary
4HE BRIEF DETAILS OF COMMONLY USED MEMORY CARDS ARE GIVEN IN THIS CHAPTER 3$ CARDS ARE
CURRENTLY THE MOST WIDELY USED MEMORY CARDS 4HE TECHNICAL DETAILS AND COMMUNICATION
METHODS OF THESE CARDS HAVE BEEN DESCRIBED IN DETAIL IN THE CHAPTER
www.newnespress.com
136
Chapter 3
3.19 Exercises
%XPLAIN THE MAIN DIFFERENCES BETWEEN THE STANDARD 3$ CARDS AND THE NEW 3$(# CARDS
7HICH CARD WOULD YOU CHOOSE IN A LONG VIDEO RECORDING APPLICATION
(OW MANY TYPES OF STANDARD 3$ CARDS ARE THERE %XPLAIN THEIR MAIN DIFFERENCES
7HICH MEMORY CARD WOULD YOU CHOOSE IN VERY HIGHSPEED DATA TRANSFER APPLICATIONS
%XPLAIN HOW YOU COULD READ THE DATA STORED ON A MEMORY CARD USING YOUR 0#
7HAT ARE THE NAMES OF THE INTERNAL REGISTERS OF A STANDARD 3$ CARD
%XPLAIN FUNCTIONS OF THE #)$ REGISTER OF AN 3$ CARD
%XPLAIN FUNCTIONS OF THE #3$ REGISTER OF AN 3$ CARD
4HE 4!!# lELD OF THE #3$ REGISTER OF AN 3$ CARD IS BINARY hv %XPLAIN WHAT
THIS MEANS
4HE 42!.?30%%$ lELD OF THE #3$ REGISTER OF AN 3$ CARD IS BINARY hv
%XPLAIN WHAT THIS MEANS
%XPLAIN THE TWO OPERATING MODES OF 3$ CARDS 7HICH MODE IS COMMONLY USED
7HAT IS THE OPERATING VOLTAGE RANGE OF AN 3$ CARD %XPLAIN HOW THIS VOLTAGE CAN BE
OBTAINED FROM A STANDARD 6 REGULATED SUPPLY
$RAW A CIRCUIT DIAGRAM TO SHOW HOW AN 3$ CARD CAN BE CONNECTED TO A 0)#
MICROCONTROLLER IN 30) MODE
%XPLAIN HOW AN 3$ CARD CAN BE PUT INTO THE 30) MODE AFTER POWERUP
%XPLAIN HOW AN 3$ CARD CAN BE PUT INTO 3$ CARD MODE AFTER OPERATING IN THE 30) MODE
(OW MANY TYPES OF RESPONSE TOKENS ARE THERE %XPLAIN WHERE EACH TOKEN IS USED AND ALSO
GIVE THEIR DIFFERENCES
www.newnespress.com