SD卡协议-中文_第1页
SD卡协议-中文_第2页
SD卡协议-中文_第3页
SD卡协议-中文_第4页
SD卡协议-中文_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、命令:是在 可以是广播的 响应:是在 数据:是在fwlRD to E无数据模式无响应模式?*orH 二 rdnoil幻MB胤and D-sy*一CMD'-command - responseDATa 的=data block crc-block write 0口白rationirnffl cardID hos t5:期 “remandstiizs :=rta 1-ms-f智commandresponse- data block crc.data stop Dpera.tian . .mWtipM blQQ.KwritQ 9P 更;OiQ 口一概述1. SD总线模式下CLK:时钟信号CM

2、D双向命令和响应信号DAT0-3:双向数据信号VDD,VSS:电源和地信号SD模式下允许有一个主机,多个从机(即多个卡),主机可以给从机分别地址.主机发 命令有些命令是发送给指定的从机,有些命令可以以广播形式发送 .SD模式下可以选择总线宽度,即选用几根DAT信号线,可以在主机初始化后设置2. SD总线协议SD模式下的命令和数据流都有一个开始位和结束位CMD 上传输的用于启动一个操作的比特流 .由主机发往从机,可以是点对点也CMD:传输的用于之前命令回答的比特流.由从机发往主机.DAT上传输的比特流,双向彳输.多块写操作模式RR3BRtranarr :二mp 二:rmr n:a .*.a>

3、;s 2olfmrd 二口L5 二 nn一三句 and azdsE iT d"- 5? nn j pa'flst&r.i t?r 7 二 L 二RC 匚、吕二自产mp bn:TCONTENTDtal l»OBtri=4.S bits命令格式响应格式5j5 :.g y HQ 至二MS= MECRC 1»rt M giWg'gr-hiock lEHngth一 cjg aSD卡上电后会自动初始化,通过给卡发送 CMD01可以复位卡二.SD卡命令描述.1 .广播命令:给所有卡都发送,某些命令需要响应.2 .点对点命令给指定地址的卡发送,需要响应.S

4、D卡系统有两种工作模式:1 .卡识别模式.主机上电复位后即处于此模式,它会在总线上等待卡.卡复位后也处于此模式,直到send_rca(cmd3H至U来.2 .数据传输模式.卡收到SEND_RCA(CMD3)令后即进入此模式.主机识别到卡后也进入此模式 .Card staleOperation mod&nactive Stateinactivedie State。曰d ide-"tificaLiDn modeReady StateIdentification StateStand-by Statedata transfer modeTransferSending-data St

5、ateRacaiye-data Stmt 9Prog ramrning StatDisconnect State-卡状态和工作模式对照表1 .卡识别模式.此模式下主机复位总线所有的卡,验证工作电压,询问卡的地址.这个模式下所有数据的传输都是只通过 CM啜来完成.1)卡的复位.当卡上电或收到 GO_IDLE_STATE (CMD净令后,卡即进入Idle State 状态.此时卡将 其RCA为0,相关寄存器设为传输稳定的最优模式.2)工作电压验证每个卡的最高和最低工作电压存储在OCR.只有当电压比配时,CID和CSD勺数据才能正常传输给主机.SD_SEND_OP_COND (ACMD4用来判断卡的

6、工作电压是否符合 ,如果不符合的话,卡 应该放弃总线操作,进入Inactive State 状态.在发送 SD_SEND_OP_COND (ACMDt前 记得要首先发送 APP_CMD (CMD55).Power onNo Response(Non valid commandMust be aMulti MediaCard、 cards with non compabbie voltage range f' Ready State '< (ready) JCMD2Start Muni MediaCard fnihalization process starting atC

7、MDlIdata-transfer modeCMD3卜口e all Etates incata*trBnsfei-riQcefoerttiStateCard responds With card-iEtentificshcn modenew RCAStanc-b ;(stby)CMJ3responds with new RCA卡的状态变换图.ACMD4命令响应中的BUSYi也用于卡表示其还没准备好,主机此时应重发 ACMD4命令,直到卡准备好.主机在这个阶段的ACMD41中不允许改变工作电压,如果确实想改变的话,应该先发送CMD0,然后再发送改变后的 ACMD41.GO_INACTIVE_ST

8、ATE (CMD1防令用于使指定地址的卡进入Inactive State 模式.3)卡识别过程.ALL_SEND_CID (CMD流令用于获取卡的 CID信息,如果卡处于 Ready State, 它就会在 CMD线上传送它的 CID信息,然后进入Identification State 模式.紧接着发送 CMD3 (SEND_RELATIVE_ADDR)令,用于设置卡新的地址.卡收到新的地址后进入Stand-by State模式.2.数据传输模式数据传输模式下卡的状态转变图进入数据传输模式后,主机先不停的发送 SEND_CSD (CMD聊令获取卡的CSD言息.SET_DSR (CMD4用于设

9、置卡的DSR寄存器,包括数据总线宽度,总线上卡的数目,总线 频率,当设置成功后,卡的工作频率也随之改变.此步操作是可选的.CMD7命令用于使指定地址的卡进入传输模式,任何指定时刻只能有一个卡处于传输模式.传输模式下所有的数据传输都是点对点的,并且所有有地址的命令都需要有响应.所有读命令都可以由 CMD1除令彳止,之后卡进入Transfer State.读命令包括单块读 (CMD17),多块读(CMD18),发送写保护(CMD30),发送scr(ACMD51)和读模式一般命令 (CMD56).所有写命令都可以由CMD12命令彳止.写命令包括单块读(CMD24),多块读(CMD25),写CID(C

10、MD26),写CSD(CMD27)锁和解锁命令(CMD42开口写模式一般命令(CMD56).当写命令传输完成后,卡进入Programming State( 传输成功)或Transfer State( 传输 失败).如果一个卡写操作被停止,但其前面数据的 CRCF口块长度正确,数据还是会被写入.卡要提供写缓冲,如果写缓冲已满并且卡处于Programming State, DAT0保持低BUSY.写CID,CSD,写保护,擦除命令没有缓冲,当这些命令没完时,不应发送其他的数据 传输命令.参数设置命令在卡被编程时是不允许发送的,这些命令包括设置块长度 (CMD16),擦除块起始(CMD32泡擦除块结

11、束(CMD33).当卡正编程时读命令是禁止的.用CMD硬另一个卡进入Transfer State不会终止当前卡白编程和擦除,当前卡会进入Disconnect State并且释放 DAT线.Disconnect State模式的卡可通过 CMD7B新被选中,此时卡进入 Programming State并且使能 busy 信号 .CMD0或CMD1会终止卡的编程操作,造成数据混乱,此操作应禁止.1) 总线宽度选择命令ACMD阶令用于选择总线宽度,此命令只有在 Transfer State 有效.应在CMD渝令后使用 .2) 块读命令块是数据传输的最小单位 ,在CSD (READ_BL_LEN定义

12、,SD卡为固定的512B.每个块传输的后面都跟着一个 CRC校验.CMD17(READ_SINGLE_BLOCK)于传输单个块, 传输完之后,卡进入Transfer State. CMD18(READ_MULTIPLE_BLOC用于多个块的传输,直到收到一个CMD1阶令.3) 块写命令与块读命令类似,每个块传输的后面都跟着一个CRC验.卡写数据时会进行 CRC验.多块写比重复的单块写更能提高效率.如果CSM的WRITE_BLK_MISALIGN:设置,并且发送的数据不是块对齐的,卡会设置状态寄存器中的 ADDRESS_ERROR并且进入Receive-data-State状态等待彳止命令.此时

13、写操作也会停止,并且卡会设置其的 WP_VIOLATIONfc.如果写缓冲满的话,卡会停止接受 WRITE_BLOC喻令.此时主机应发送 SEND_STATUS (CMD13)命令,卡返回数据的READY_FOR_DATA标志卡是否准备好接受新的数据.在多块写操作中通过事先发送ACMD2跄令可提高写速度.ACMD23用于定义接下来要写数据的块的数目 . 每次多块写操作后, 这个值又被设为默认的 1.ACMD2会使卡返回写成功的块数目.4) 擦除命令擦除命令的顺序是: ERASE_WR_BLK_START(CMD32),ERASE_WR_BLK_END(CMD33)and ERASE(CMD38

14、).如果(CMD3喊(CMD32, 33)接收到出错信息,卡会设置状态寄存器中的ERASE_SEQ_ERROR位并且重新等待新的命令时序 .如果接收到时序错误命令,卡会设置其ERASE_RESET并且重新等待新的命令时序.5) 写保护管理三种机制 :- . 写保护物理开关- . 卡内部写保护通 过设置 CSD 中 的 WP_GRP_ENABLE 和 WP_GRP_SIZE位,SET_WRITE_PRO下口 CLR_WRITE_PROT令用来设置和清除保护机制.- . 密码保护 .三 . 时钟控制如果主机要发送1K的数据,但是主机缓冲区只有512B,那么主机可以在发送完前512B后 , 可以先停

15、止时钟 , 然后把后 512B 填充入缓冲区, 再启动时钟 , 这样卡并不会检测要两次发送之间的间隔 , 认为其是一次完整的数据发送过程.四CRC校验1.CRC7CRC7用于所有的命令,除R3以外的响应,以及CID和CSM存器.2.CRC16CRC16用于数据块的校验五.错误类型.1 . CRC错误和命令非法错误命令的CR或验出错,卡设置其状态寄存器的 COM_CRC_ERROR非法命令错误,卡设置其状态寄存器的ILLEGAL_COMMAND.非法命令包括:不支持的命 令,未定义的命令以及当前状态不支持的命令.2 .读,写和擦除超时.卡应该在指定的时间内完成一个命令或返回移动的错误信息.如果在

16、指定的超时时间内主机收不到响应,应认为卡停止工作,应重新复位卡.六命令1 .命令类型:- bc不需要响应的广播命令.- bcr需要响应的广播命令.每个卡都会独立的接收命令和发送响应- ac点对点命令,DAT线上没数据- adtc点对点命令,DAT线上有数据Bit position474645 40pg: 8:cWidth ibits:1163271Valuep'1,JXXD«scrt|)tiorsisrt b tTfansTiiss onOilcominand indevwrguE宜川CC7end bit所有命令均遵守上图中的格式,总共48位.首先是1个起始位0,接着是1个方

17、向位(主机发送位1), 6个命令位(0-63 ), 32 位参数(有些命令需要),CRC7位校验,1个停止位.2.卡命令根据不同的类型分成了不同的Class,见下表,其中Class0,2,4,5,8 是每个卡都必须支持的命令,不同的卡所支持白命令保存在CSD中.Card Command Class (CCC)0123456789.11Support edcomma n dsclass descriptionbasicreserv edblock readreserv edblock z/nteerasewrite protectionlock cardapplication specificr

18、eserv edCMDOMandatoryCMD2Mandatory.CMD3Mandatory+CMD4MandatoryCMD7Mandatory+4CMD9Mandatory+CMD10MandatoryCMD12MandatoryCMD13Mandatory+CMD15MandatoryCMD16Mandatory+CMD17MandatoryCMD18MandatoryCMD24Mandatory+CMD25MandatoryCMD27Mandatory+CMD28Optional+CMD29OptionalCMD30Optional+Card Command Class (CCC)

19、0123456789.11Support ed comma n dsclass descriptionbasicreserv edblock readreserv edblock writeerasewrite protectionlock cardapplication specificreserv edCMD32MandatoryCMD33MandatoryCMD38Mandatory+CMD42OptionalCMD55Mandatory+CMD56Mandatory+ACMD6MandatoryACMD13Mandatory+ACMD22MandatoryACMD23Mandatory

20、+ .ACMD41Mandatory+ACMD42MandatoryACMD51Mandatory+3.命令详细描述1)基本命令Class。CMDINDEXtypeargumentrespab breviationcamiriand descriptionCMDDbe31 C sh/f bits-TGO IDLE STATEresets all cards to idle stateGMD1reservedCMD2bcr31 0 sti/f bitsR2ftLL_SEND_CiDasks any card to send IheC D num- Ders on tne Cml line (an

21、y caret that is connected to the host ?/ill responc)GMD3bcr3i o sW tutsR6SENL_RELATIVE_ ADDR-ask the cand to pubiisr a new reia:iwe address (RCA)CMD4DC31 I5J DSK 150 sti/f bits«SET_DSRprograms the DSR of all cansCMD5res ervenCMD6reservedCM口INDEXtypeargumentr白白pabbreviationcammand descriptionCMD

22、7ac31 16 RCA15:0 stuff bi:sRib 6"田依做LardSELECT/ DESELECT ORDornmand toggles a cand between tbs stand-by and transfer states or between the programTiimg and disconnect states in 6值h cases the card b selected by its own relative a(Cress and gets des&iecteo Dy any 0theaddress' address 0 de

23、selects all.CMDBreservedcmgac31 16 RCA 15:0 stkift bi:sR2SEND_CSDaddressed card sends its ca-spe- dfic data (CSD) on the CMD line.CMD10ac31 16 RCA15 0 stuff bhsR2SEND_CIDaddressed card sends ts ca”d identi- fcation (CjD) on CMD Ihe lineCMD11reservedCMD12ac31 0 stuff bi:sR1bSTOP_transm ssionfarces tM

24、 card tc stop transmissionCM口 13日G31 1GJRCA15.0 stuff bicsR1iSEND_STATUSeddlttlbeJ Cdl J 5HIKIS 15 stdtus registerCM。14reatsr vedCM015ac31 16 RCA15-0 stuff bi:s-GOJNACTJVE STATEsets the card to inactive state ir order b protect rhe card st a ex agan&t com- n unicat ion 口eaKdawns2)读命令Class2CMDIND

25、EXtypeargumentrespaobreviationcommand descriptionCMD 15ac31 0 block lengthR1ScT_BLOCKLENsets ihe Nack length (in bytes) for all lol lowing Dlcck cornmands read and write . Default block lergth 咯 specified In the CSD. SuppDried only If Partial block RD '岛" uptjimlon am dllo'tid in CSDFCM

26、D I7sdtc(31:0; data address卜1REAC_SlhGLE_SLOCK旧ads a bock of the size sdected by the SET_3LOCKUEM comnanc 1CMD 18adLc31.0 data addressR1REAO_MULTIPLESLOCKconlmuoLsly transfers data blocks Irom carato host until interrupted by a STOP_TRANSMISSION command.CMD 19CMD23reserved3)写命令Class4CMD INDEXtypearg

27、umentrespabbreviationcommand descriptionCMD24adtc31 0 data acdressRIVVRITE_BLOCKvoltes b blo:k of the size gelecled ty the SEl_t3LOCKLEH corrmarKl 1CMD25adc31 0 data acdre£sR1WRIT£_MULTIPL e_blockcontinuously mires blocks of data until a STO=_TRANSMISSiON followsCMD26Reserved For Manufactu

28、rarCMD27adtc31 0 stuff bitsR1PROGRAM_CSDprogramming of the programmable bi书 of theCSD3)擦除命令Class5CMDINDEXtypeargumentrespabbreviaiioncommand descriptionCMD32ac(31 0 data addressR1ERASE 胃 R BLKSTARTseis the address of the first virile- block to be erasedCMD33就131 0 data addressR1FASE_WR_BLKENDseis th

29、e address M the last write block a1 the coniirnjcijs raneto beCM 0 34CM 口 37reserved4)应用特定命令Class8CND INDEXtypeargumentraspabbreviationcommand d 白1script ionCND55ac31:16 RCA 15:0 stuff bitsR1APP_CMDIndicateo to the card that the next command is an application specific command ra:f er than a standard

30、 commandCMD56adtc(311 stuff bits Q RD/ WR1R1GEN_CMDUsed either to transfer a data block to the card or to get a data block from the card for general purpose! application tpacific commands The size of tte data block siiall be set by thu SET_BLOCK_L£M com ma nd.CMD57CMD59reservedCL1D60 63reserved

31、 for manyfactuner卜表中的所有命令使用前都应先跟一个APP_CMD(CMD斶令AC MD 出DEXtypeargumentespabbreviationcommand descriptionACMD6ac(31 2) stuff bits (1:0bus widthR1SET_BUS_WIDTHDefines the data bus width (Ws1bit or *10*=4 bits bus) to be used for data transfer. The slowed data bus widths are given in SCR register.ACMD13

32、adtc31:0 stuff bitsR1SD STATUSSend the SD Memory Cap status. The status fields are given in Table 24.XCMD17reservedMMD1B一.一Reserved fw SD security applicaticns'/CMD19 to心 MD21reservedACMD22adtc31:0 stuff bitsR1SEND_NUM_WR_BLOCKSSend the number cf the written (v/ithou: errors) write blocks. Respo

33、nds v/ith 32DH-CRC data block.MMD23ac31:23 stuff bits 22:0)Number of blocksR1SET_WR_BLK_ERASE-COUNTSet the number of write bocks to be pre-erased Defore writing (to be used for faster Multiple Block VVR com- mand) M 1-=d©fault (one v/r Hock)(21ACMD24resprvRdACMD25一, 一3Reserved for S3 security a

34、pplications"ACMD2SReserved for SD security applications"ACMD3B Reserved for SD security applications*ACMD3B to A2MD40reservedZCMD41bcr31 ©OCR wthout busyR3SD_APP_OP_CONDAsks the accessed card to send its operating condtion register (OCR) cor- leni h the response on the CMD line.ACMD42

35、acavilstu bitsR1SET CLR CARDDETECT -:Connect!iyDisconnect0 the 50KOnm pull-up resistor on CD/DAT3 (pin 1) of the card The pull-up may be used for card detection.MMD43MMD49一一一 一,Reserved for SD security applications'怔 MD51adtc(31:O| staff bitsASEND_SCRReads the SD Configurat on Register (SCR).七.卡

36、状态转换表current stateidlereadyidentstb/trandatarevprgdisinacommandchanges toclass independentGRC error-一-一-command nN supported-class。CMDDidleidleIdleIdleidleid &idleIdleidle-CMD2-ident-CMD3-st b yst by-CMD4-st by.CMD7, card is addressed-w-tranfl了二prgjCMD7, card is nol add ressed-.-stby rstbystby-d

37、is .-CM3.-油y-h-CMD10-st byw三-= Ji-CMD12-tranpg-CMD13,st bytrandatarevprgdis.CMD15-一inainainal_ ma Lmaina-Class 2CMD16-MF-tnan-CMD17-data-GMD18-data-class 4GMD16see class 2CMD24,-rev.GMD25-_rev-CMD27-rev-class 6CMD20-Ik-prg-,CMD25-一P9-CMD3Q-data-class 5current stateidlereadyidentstbyIrandatarevprgdis

38、in aCMD32-trail-CMD33.-tran-CMD38-prg-class 7-rev-class 8GMD55idle二4stbytrandatarevprgdis二CMD56: RDP/VR = 0-rev-*-CMD56. RDJWR = 1-data-q-ftCMDS-tran-/-W:MO13-.-tran-W:MDZ2-tran.-CMD23-tran一-NMD1426,26.3B4.4 5 46 *47 46 49Refer to SD Memorv1 Card Securib, SpBCihDatiOTi forfiiptanatiorr about tti&

39、; SD Security FeaturesA1CMD4-1. csrd “口口 range compatibleready-CMD41, eard ig busyIdle-ftCMD4l. card VDD rar not compatibleinaACM 口 42-tran-ACMD51-tiata-,-class 9-11CMD41;CMDd3L. CMD54CMD57-CMD59reservedCMD60.CMD63re&erved for manufacturer八.应答.所有的应答都是通过 CMDt送,不同的应答长度可能不同.总共有四种类型的应答1. R1:长度位48位.注

40、意每个块传输完成后有一个BUSY位.Bit posibon4746(45:40f39:80Width (bits1153271Value0HO,XXXr 丁Descriptionstart bittransmission bitcornmarni iixexcard statusCRC7end bit2.R1b:与R1类似,只是将BUSY#力口入响应中3.R2(CID CSD寄存器):长度为136位,CID 为CMDW口 CMD10勺应答,CSD为CMD9勺应答.Bit position135134口 33128|0Width (bits116127J1Value0,o'iiinrTD

41、escriptionStart bittransmissicn bitreservedCD OrCSD register incl. internal CRC?end bit4.R3(OCR寄存器):长度位48位.作为ACMD4的应答.Bit position474645403987R0Width (bite)1163271ValueO,0111111,X,iinnr1Descriptionstart bittransmission failreservedOCR registerreservedend bit5.R6(RCA地址应答):长度为48位Bit position474645 403

42、9 B) Arg urrient fieldR:10jWidth (bits11G131611ValueO'O'XXXXrDescriptionstart bittransmission blLcommand Index (W0C11-)New pj bl i s had FtA 31: IB Of the card15 0 card sts*us bits.23 22 19 12:0 (see Table 22CRC7and bit九.卡的状态SD卡支持两种状态:-卡状态:与MM球兼容.-SD卡状态:扩充到了 512位.1 .卡状态:R1应答包含一个32位的卡状态.见下表.其

43、中Type中的含义为:E:错误位.S:状态位.R:根据命令在响应中设置.X:根据在命令执行期间设置,必须再次读此位才能获得命令执行后的情况Clear Condition:A:与卡的当前状态有关B:总是与命令有关,无效的命令会清除此位C:通过读此位来清除BitsIdentifierTypeValueA DescriptionClear Cond ition J31OUT_OF_RANGEER*0- no error T errorThe coTimand*s argument was out of the 8 How ad rage for this card.C (30ADCRESS.ERRC

44、RERXno error T= errorA misaligned address which did not ma:ch the block length was used in the command.29BLOCK_LEN_ERRORER*0*= no error T errorThe transfeied block length is not allowed for this card. or the number of transferred bytes does not match ihe block eng tn.C28ERASE-SEQ-ERRORER'0= no e

45、rror T= errorQAn eror in the sequence of erase commands ccured.C27ERASE-PARAMEXno error'1、errorAn invalid selection of write blocks for erase occurred.4c26WP-VIOLATIONERX'O'= net protected 1= protectedAtterrpt to program a write protected olock.c25CARDJS.LOCKEDSXO' * card unlockedV 5

46、 card lockedWhen set signals that the card is locked by the hostA24LOCK UNLOOK-FAIL EDERXO' = no error*1* = errorSet when a sequence or password enor nas been detected in lock/ unlock card comnand or if there was ar attempt to access a locked cardC23COM-CRC-ERRORER*0,« no error'1、errorT

47、he CRC check of the pre/ious command failed.B22ILLEGAL-COVIMANDER*0- no error'1、errorComnand not legal for the card stateB21CARD-ECC.FAILED'O' success 了Card rtemal ECC was applied but failed to correct me dataC20CC.ERROR*0*= no error,1,s errorInterna card controller errorC19ERROR01no errorT= errorA general。 an unknown error occurred during the ooeration.cieUNDERRUNEX*0*= no error errorThe card could not sustain data transfer in stream read modeC17OVERRUNEX*0*= no error 'T= errorThe card could not sustain data programming in stream write modeC16CIDZCSD_OVERWR TEE RX'0'

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论