sd卡引脚定义及命令

合集下载

SD,DDR,DDR2引脚定义

SD,DDR,DDR2引脚定义

SD内存插槽及测试点一、实物图上图中,黑色插槽就是SD内存插槽二、测试点SD内存插槽测试点:1个供电、4个时钟、6个信号测试点VCC:供电测试点,正常电压3.3V,由场管或橙色线提供CLK0、CLK1、CLK2、CLK3:时钟测试点,频率66/100/133MHZ,电压1.1V-1.6V,由北桥或时钟芯片提供6个信号测试点:CAS#:列选信号RAS#:行选信号/WE#:允许信号(高电平允许读,低电平允许写)/CS#:片选信号SCL:串行时钟,SDA:串行数据,由南桥提供3.3V电压DDR内存插槽及测试点一、实物图上图就是DDR内存插槽实物图二、测试点DDR内存插槽测试点:2个供电、6个时钟、6个信号测试点VCC=2.5V,1.25V:供电测试点CLK0、CLK1、CLK2、CLK3、CLK4、CLK5:时钟测试点,频率266/333/400MHZ,电压1.1V-1. 6V,如果主板有两块时钟芯片,内存时钟由靠近内存的时钟芯片提供;如果只有一个时钟芯片,内存的时钟由北桥提供6个信号测试点:CAS:列选信号RAS:行选信号WE:允许信号(高电平允许读,低电平允许写)CS:片选信号SCL:串行时钟,SDA:串行数据,由南桥提供3.3V电压D58、D56、D18等:是数据线,对地打阻值正常值300-800DDR2内存插槽测试点2009-10-2 10:37:43文/xiaowang 出处:电脑维修家园DDR2内存插槽实物图如下:1、时钟信号点,共有8个时钟信号点,分别位于52、137、138、171、185、186、220、221针脚,正常进,时钟信号点工作电压为1.1V。

2、电压信号点,DDR2内存插槽有2种电压,其中238针脚为3.3V供电脚,51、53、56、59、62、64、69、72、75、78、170、172、175、1 78、181、187、189、191、194针脚为1.8V供电脚。

最新SD卡在单片机上的应用以及SD卡引脚 电路图及工作原理介绍

最新SD卡在单片机上的应用以及SD卡引脚 电路图及工作原理介绍

SD卡在现在的日常生活与工作中使用非常广泛,时下已经成为最为通用的数据存储卡。

在诸如MP3、数码相机等设备上也都采用SD卡作为其存储设备。

SD 卡之所以得到如此广泛的使用,是因为它价格低廉、存储容量大、使用方便、通用性与安全性强等优点。

既然它有着这么多优点,那么如果将它加入到单片机应用开发系统中来,将使系统变得更加出色。

这就要求对SD卡的硬件与读写时序进行研究。

对于SD卡的硬件结构,在官方的文档上有很详细的介绍,如SD卡内的存储器结构、存储单元组织方式等内容。

要实现对它的读写,最核心的是它的时序,笔者在经过了实际的测试后,使用51单片机成功实现了对SD卡的扇区读写,并对其读写速度进行了评估。

下面先来讲解SD卡的读写时序。

1)SD卡的引脚定义:SD卡引脚功能详述:引脚编号SD模式SPI模式名称类型描述名称类型描述1 CD/DAT3 IO或PP 卡检测/数据3 #CS I 片选2 CMD PP 命令/回应DI I 数据输入3 VSS1 S 电源地VSS S 电源地4 VDD S 电源VDD S 电源5 CLK I 时钟SCLK I 时钟6 VSS2 S 电源地VSS2 S 电源地7 DAT0 IO或PP 数据线0 DO O或PP 数据输出8 DAT1 IO或PP 数据线1 RSV9 DAT2 IO或PP 数据线2 RSV注:S:电源供给I:输入O:采用推拉驱动的输出PP:采用推拉驱动的输入输出SD卡SPI模式下与单片机的连接图:SD卡支持两种总线方式:SD方式与SPI方式。

其中SD方式采用6线制,使用CLK、CMD、DAT0~DAT3进行数据通信。

而SPI方式采用4线制,使用CS、CLK、DataIn、DataOut进行数据通信。

SD方式时的数据传输速度与SPI方式要快,采用单片机对SD卡进行读写时一般都采用SPI模式。

采用不同的初始化方式可以使SD卡工作于SD方式或SPI方式。

这里只对其SPI方式进行介绍。

SD卡引脚及spi模式基本操作过程

SD卡引脚及spi模式基本操作过程

SD卡引脚及spi模式基本操作过程(摘自网络)对于SD卡的硬件结构,在官方的文档上有很详细的介绍,如SD卡内的存储器结构、存储单元组织方式等内容。

要实现对它的读写,最核心的是它的时序,笔者在经过了实际的测试后,使用51单片机成功实现了对SD卡的扇区读写,并对其读写速度进行了评估。

下面先来讲解SD卡的读写时序。

SD卡的引脚定义SD卡引脚功能详述:引脚编号SD模式SPI模式名称类型描述名称类型描述1 CD/DAT3 IO或PP 卡检测/数据线3#CS I 片选2 CMD PP 命令/回应DI I 数据输入3 VSS1 S 电源地VSS S 电源地4 VDD S 电源VDD S 电源5 CLK I 时钟SCLK I 时钟6 VSS2 S 电源地VSS2 S 电源地7 DAT0 IO或PP 数据线0 DO O或PP 数据输出8 DAT1 IO或PP 数据线1 RSV9 DAT2 IO或PP 数据线2 RSV注:S:电源供给I:输入O:采用推拉驱动的输出PP:采用推拉驱动的输入输出SD卡SPI模式下与单片机的连接图:SD卡支持两种总线方式:SD方式与SPI方式。

其中SD方式采用6线制,使用CLK、CMD、DAT0~DAT3进行数据通信。

而SPI方式采用4线制,使用CS、CLK、DataIn、DataOut进行数据通信。

SD方式时的数据传输速度与SPI方式要快,采用单片机对SD卡进行读写时一般都采用SPI模式。

采用不同的初始化方式可以使SD卡工作于SD方式或SPI 方式。

这里只对其SPI方式进行介绍。

SPI方式驱动SD卡的方法SD卡的SPI通信接口使其可以通过SPI通道进行数据读写。

从应用的角度来看,采用SPI接口的好处在于,很多单片机内部自带SPI控制器,不光给开发上带来方便,同时也见降低了开发成本。

然而,它也有不好的地方,如失去了SD卡的性能优势,要解决这一问题,就要用SD方式,因为它提供更大的总线数据带宽。

SD卡-4

SD卡-4

CS: Host to card Chip Select signal. CLK: Host to card clock signal DataIn: Host to card data signal. DataOut: Card to host data signal
软件设计时, 为了程序的可移 植性和易用性, 将程序分为三 个层次。第一个层次是硬件 抽象层, 第二层是实现访问SD 卡的命令层, 第三层是应用层, 提供给用户或文件系统的接口函数。 硬件抽象层包括访问SD 卡的硬件环境配置、SPI 接口实现通讯 的基本函数以及SPI 中断的处理。 硬件环境配置包括硬件初始化、以及内存变量初始化等。如将单 片机的I/O 端口配置、SD 卡的上电与断开、SD 卡插入是否到 位检测、SD 卡内部寄存器特定参数设置等等。 SPI 接口实现通讯的基本函数, 包括主控制器向SD卡发送一字节 和从SD 卡读取一字节的基本函数, 这是所有SPI通讯的基础。
SD卡的接口可以支持两种操作模式: SD卡模式 SPI模式 主机可以选择其中任一模式,SD卡模式允许4线的高速数 据传输。 SPI模式允许简单通用的SPI通道接口, 这种 模式相对于SD模式的不足之处是丧失了速度。
SD卡模式针脚定义 针脚 名称 1 CD DAT3 2 CMD 3 Vss 4 Vcc 5 CLK 6 Css2 7 DAT0 8 DAT1 9 DAT2
{
SdWriteByte(command|0x40); SdWriteByte(((unsigned char *) & argument)[0]); SdWriteByte(((unsigned char *) & argument)[1]); SdWriteByte(((unsigned char *) & argument)[2]); SdWriteByte(((unsigned char *) & argument)[3]); SdWriteByte(CRC); }

SD卡引脚及spi模式基本操作过程精编版

SD卡引脚及spi模式基本操作过程精编版

SD卡引脚及spi模式基本操作过程(摘自网络)对于SD卡的硬件结构,在官方的文档上有很详细的介绍,如SD卡内的存储器结构、存储单元组织方式等内容。

要实现对它的读写,最核心的是它的时序,笔者在经过了实际的测试后,使用51单片机成功实现了对SD卡的扇区读写,并对其读写速度进行了评估。

下面先来讲解SD卡的读写时序。

SD卡的引脚定义SD卡引脚功能详述:引脚编号SD模式SPI模式名称类型描述名称类型描述1 CD/DAT3 IO或PP 卡检测/数据线3#CS I 片选2 CMD PP 命令/回应DI I 数据输入3 VSS1 S 电源地VSS S 电源地4 VDD S 电源VDD S 电源5 CLK I 时钟SCLK I 时钟6 VSS2 S 电源地VSS2 S 电源地7 DAT0 IO或PP 数据线0 DO O或PP 数据输出8 DAT1 IO或PP 数据线1 RSV9 DAT2 IO或PP 数据线2 RSV注:S:电源供给I:输入O:采用推拉驱动的输出PP:采用推拉驱动的输入输出SD卡SPI模式下与单片机的连接图:SD卡支持两种总线方式:SD方式与SPI方式。

其中SD方式采用6线制,使用CLK、CMD、DAT0~DAT3进行数据通信。

而SPI方式采用4线制,使用CS、CLK、DataIn、DataOut进行数据通信。

SD方式时的数据传输速度与SPI方式要快,采用单片机对SD卡进行读写时一般都采用SPI模式。

采用不同的初始化方式可以使SD卡工作于SD方式或SPI 方式。

这里只对其SPI方式进行介绍。

SPI方式驱动SD卡的方法SD卡的SPI通信接口使其可以通过SPI通道进行数据读写。

从应用的角度来看,采用SPI接口的好处在于,很多单片机内部自带SPI控制器,不光给开发上带来方便,同时也见降低了开发成本。

然而,它也有不好的地方,如失去了SD卡的性能优势,要解决这一问题,就要用SD方式,因为它提供更大的总线数据带宽。

tf卡底层引脚定义

tf卡底层引脚定义

tf卡底层引脚定义TF卡底层引脚定义:TF卡,又称为Micro SD卡,是一种常见的存储设备,广泛应用于移动设备、数码相机等领域。

TF卡底层引脚定义了TF卡与外部设备之间的连接方式和通信规则。

本文将从TF卡底层引脚定义的角度,探讨TF卡的工作原理和应用场景。

一、TF卡底层引脚定义TF卡底层引脚一般包括以下几个引脚:1. VCC:供电引脚,用于提供电源给TF卡,一般连接到3.3V或5V 电源。

2. GND:地引脚,用于连接地线,与外部设备共享地。

3. CLK:时钟引脚,用于传输时钟信号,控制数据的读写。

4. CMD:命令引脚,用于发送读写命令给TF卡。

5. DAT0-DAT3:数据引脚,用于传输数据。

二、TF卡工作原理TF卡是一种闪存存储设备,采用了SPI(Serial Peripheral Interface)或SD(Secure Digital)接口协议。

TF卡通过底层引脚与外部设备进行通信,实现数据的读写和存储。

在TF卡的工作过程中,外部设备首先通过时钟引脚(CLK)发送时钟信号给TF卡,TF卡根据时钟信号进行同步。

然后,外部设备通过命令引脚(CMD)发送读写命令给TF卡,TF卡根据命令进行相应的操作。

同时,外部设备通过数据引脚(DAT0-DAT3)与TF卡进行数据的传输。

TF卡根据命令和数据进行存储或读取操作,并将结果返回给外部设备。

三、TF卡的应用场景TF卡由于其小巧、便携的特点,在各种移动设备和数码产品中得到了广泛应用。

以下是TF卡的几个主要应用场景:1. 手机存储扩展:由于手机内置存储容量有限,用户可以通过插入TF卡来扩展手机的存储空间,方便存储大量的照片、音乐和视频等文件。

2. 数码相机存储:数码相机通常使用TF卡作为存储介质,用户可以将拍摄的照片和视频保存在TF卡中,并通过TF卡读卡器将数据传输到电脑进行编辑和存储。

3. 智能穿戴设备:智能手表、智能眼镜等智能穿戴设备中,也常常使用TF卡作为存储介质,用于存储用户的健康数据、运动轨迹等信息。

SD卡接口定义

SD卡接口定义

特性:◎兼容规范版本1.01 ◎卡上错误校正◎支持CPRM◎两个可选的通信协议:SD模式和SPI模式◎可变时钟频率0-25MHz◎通信电压范围:2.0-3.6V工作电压范围:2.0-3.6V◎低电压消耗:自动断电及自动睡醒,智能电源管理◎无需额外编程电压 ◎卡片带电插拔保护◎正向兼容MMC卡 ◎高速串行接口带随即存取---支持双通道闪存交叉存取---快写技术:一个低成本的方案,能够超高速闪存访问和高可靠数据存储---最大读写速率:10Mbyte/s◎最大10个堆叠的卡(20MHz,Vcc=2.7-3.6V)◎数据寿命:10万次编程/擦除◎CE和FCC认证 ◎PIP封装技术◎尺寸:24mm宽×32mm长×1.44mm厚说明:本SD卡高度集成闪存,具备串行和随机存取能力。

可以通过专用优化速度的串行接口访问,数据传输可靠。

接口允许几个卡垛叠,通过他们的外部连接。

接口完全符合最新的消费者标准,叫做SD卡系统标准,由SD卡系统规范定义。

SD卡系统是一个新的大容量存储系统,基于半导体技术的变革。

它的出现,提供了一个便宜的、结实的卡片式的存储媒介,为了消费多媒体应用。

SD卡可以设计出便宜的播放器和驱动器而没有可移动的部分。

一个低耗电和广供电电压的可以满足移动电话、电池应用比如音乐播放器、个人管理器、掌上电脑、电子书、电子百科全书、电子词典等等。

使用非常有效的数据压缩比如MPEG,SD卡可以提供足够的容量来应付多媒体数据。

框图:SD卡上所有单元由内部时钟发生器提供时钟。

接口驱动单元同步外部时钟的DAT和CMD信号到内部所用时钟。

本卡由6线SD卡接口控制,包括:CMD,CLK,DAT0-DAT3。

在多SD卡垛叠中为了标识SD卡,一个卡标识寄存器(CID)和一个相应地址寄存器(RCA)预先准备好。

一个附加的寄存器包括不同类型操作参数。

这个寄存器叫做CSD。

使用SD卡线访问存储器还是寄存器的通信由SD卡标准定义。

SD卡原理及内部结构

SD卡原理及内部结构

1、简介:SD卡(Secure Digital Memory Card)是一种为满足安全性、容量、性能和使用环境等各方面的需求而设计的一种新型存储器件,SD卡允许在两种模式下工作,即SD模式和SPI模式,本系统采用SPI模式。

本小节仅简要介绍在SPI模式下,STM32处理器如何读写SD卡,如果读者如希望详细了解SD卡,可以参考相关资料。

SD 卡内部结构及引脚如下图所示:SD卡内部图.JPG2、SD卡管脚图:SD卡图.JPG3、SPI模式下SD各管脚名称为:sd 卡:SPI模式下SD各管脚名称为.JPG注:一般SD有两种模式:SD模式和SPI模式,管脚定义如下:(A)、SD MODE 1、CD/DATA3 2、CMD 3、VSS1 4、VDD 5、CLK 6、VSS2 7、DATA0 8、DATA1 9、DATA2(B)、SPI MODE 1、CS 2、DI 3、VSS 4、VDD 5、SCLK 6、VSS2 7、DO 8、RSV 9、RSVSD 卡主要引脚和功能为:CLK:时钟信号,每个时钟周期传输一个命令或数据位,频率可在0~25MHz之间变化,SD卡的总线管理器可以不受任何限制的自由产生0~25MHz 的频率;CMD:双向命令和回复线,命令是一次主机到从卡操作的开始,命令可以是从主机到单卡寻址,也可以是到所有卡;回复是对之前命令的回答,回复可以来自单卡或所有卡;DAT0~3:数据线,数据可以从卡传向主机也可以从主机传向卡。

SD卡以命令形式来控制SD卡的读写等操作。

可根据命令对多块或单块进行读写操作。

在SPI 模式下其命令由6个字节构成,其中高位在前。

SD卡命令的格式如表1所示,其中相关参数可以查阅SD卡规范。

4、MicroSD卡管脚图:MicroSD卡管脚图.JPG5、MicroSD卡管脚名称:MicroSD卡管脚名称.JPGSD 卡与MicroSD卡仅仅是封装上的不同,MicroSD卡更小,大小上和一个SIM卡差不多,但是协议与SD卡相同。

SD卡与TF卡的引脚定义

SD卡与TF卡的引脚定义

December 2007 Rev 31/61512 MByte and 1 GByte, 3.3V Supply Secure Digital™ CardFeatures■SD Memory Card Specification Version 1.01-compliant■Up to 1 Gbyte of Formatted Data Storage ■Bus Mode–SD Protocol (1 to 4 Data Lines)–SPI Protocol■Operating Voltage Range:–Basic Communication (CMD0, CMD15, CMD55 and ACMD41): 2.0V to 3.6V–Other C ommands a nd M emory A ccess: 2.7V to 3.6V ■Variable Clock Rate: 0 to 25 MHz ■Read Access (using 4 Data Lines)–Sustained Multiple Block: 6.3 Mb/s ■Write Access (using 4 Data Lines)–Sustained Multiple Block: 3.0 Mb/s ■Maximum Data Rate with up to 10 Cards ■Aimed at Portable and Stationary Applications ■Communication Channel Protocol Attributes:–Six-wire communication channel (clock, command, 4 data lines)–Error-proof data transfer–Single or Multiple block oriented data transfer■Memory Field Error Correction ■Safe Card Removal during Read■Write Protect Feature using Mechanical Switch ■Built-in Write Protection Features (Permanent and Temporary)■SD, MiniSD and MicroSD Packages –ECOPACK ® compliant –Halogen free –Antimony freeMicroSDTable 1.Device summaryPart Number Package Form Factor Operating Voltage RangeSMS128AF SD (full size)2.7V to3.6VSMS256AF SMS512AF SMS01GAF SMS064BF MiniSD SMS128BF SMS064FF MicroSDSMS128FF SMS256FF SMS512FFDescription SMSxxxAF, SMSxxxFF, SMSxxxBF1 DescriptionThe Secure Digital Memory Card (SD Memory Card) is a Flash-Based Memory Card. It is specifically designed to meet the security, capacity, performance and environmentalrequirements of the latest-generation audio and video consumer electronic devices, that is mobile phones, digital cameras, digital recorders, PDAs, organizers, electronic toys, etc. The Secure Digital Memory Card is a high-mobility, high-performance, low-cost and low-power consumption device that features high data throughput at the memory card interface. It includes a copyright protection mechanism that complies with the security of the SDMI (Secure Digital Music Initiative) standard. The Secure Digital Memory Card security system uses mutual authentication and a “cipher algorithm” that protects the card from illegal use. Unsecured access to the user's personal content is also available.The Secure Digital Memory Cards have an advanced communication interface designed to operate in a low voltage range. The full-size Secure Digital Memory Card has a 9-pin interface whereas the Mini Secure Digital Memory Card has a 11-pin interface but can be fitted with a 9-pin adapter. Only the 9-pin interface is described in this document. The MicroSD Memory Card has an 8-pin interface, and can also be fitted with a 9-pin adapter.Table 2,T able 3,Table 4,Table 5, and Table 6 give an overview of the Secure Digital Memory Card features.In order to meet environmental requirements, the devices are offered in ECOPACK ®packages. ECOPACK packages are Lead-free. The category of second Level Interconnect is marked on the package and on the inner box label, in compliance with JEDEC Standard JESD97. The maximum ratings related to soldering conditions are also marked on the inner box label.The SD, MiniSD and MicroSD packages are also Halogen free and Antimony free.Related documentation●Secure Digital Memory Card Specifications: Part 1 Physical Layer Specification, Version 1.01●MiniSd Memory Card Specifications: Addendum to SD Memory Card Specifications Part 1 Physical layer Specification, Version 1.02●MicroSD Memory Card Specifications: Addendum to SD Memory Card Specifications Part 1, Physical Layer Specification, Version 1.00Table 2.System performanceSystem performanceMax.Typ.Unit Sleep to Ready30µs Sustained Multiple Block Read (1)1.43X, 20X, 12X and 5X Speed grade markings where 1X = 150 KBytes/s.6.3 (43X)MBytes/s Burst Single Block Read (1) 1.8 (12X)MBytes/s Sustained Multiple Block Write (1) 3.0 (20X)MBytes/s Burst Single Block Write (1)0.8 (5X)MBytes/s Power-up to Ready150msSMSxxxAF, SMSxxxFF, SMSxxxBFDescriptionTable 3.Power consumption (1)1.T A = 25°C, V DD = 3.6V.ModeMax. Current ConsumptionStandby 200 µA Read 30 mA Write30 mATable 4.Environmental specifications (1)1.NA = Not Applicable; RH = Relative Humidity; ESD = ElectroStatic DischargeEnvironmental specifications Operating Non-Operating T emperature− 25°C to 85°C − 40°C to 85°C Humidity (non- condensing)NA 85°C - 85%RHESDProtectionContact PadsNA±4kV , Human body model according to ANSI EOS/ESD-S5.1-1998Other±8kV (coupling plane discharge)±15kV (air discharge) Human body model perIEC61000-4-2Salt Water Spray NA T A = 35 °C 3% NaCl (MIL Std Method 1009)Vibration (peak-to-peak)NA 15 Gmax ShockNA1,000G Drop NA2000GBending20N (middle of the card)20N (border of the card)UV light exposure254nm, 15Ws/cm2Table 5.Physical dimensionsParameter SD MiniSD MicroSD Unit Width 2420 11mmHeight3221.515 mm Thickness 2.1 1.4Inter Connect Area 0.7±0.1mmMax. Card Thickness 0.95 Max. Pull Area1.0±0.1Weight Approx. 2Approx. 1<1g Number of Pins9118N/ADescriptionSMSxxxAF, SMSxxxFF, SMSxxxBFTable 6.System reliability and maintenanceMTBF (1)1.MTBF = Mean Time Between Failures.>1,000,000hrsPreventive Maintenance NoneData Reliability 1 non-recoverable bit in 1014 bit read Endurance>2,000,000 Program/Erase CyclesSMSxxxAF, SMSxxxFF, SMSxxxBF Memory array partitioning2 Memory array partitioningThe basic unit of data transfer to/from the SD Memory Card is the Byte. The memory array is divided into several structures as described below and summarized in Table 17.BlockThe Block is the unit structure related to block-oriented read and write commands. Its size is the number of Bytes that are transferred when a block-oriented read or write command is sent by the host. The SD Memory Card Block size is either programmable or fixed. The information about allowed block sizes and programmability is stored in the CSD Register. The details of the Memory Array Structure and the number of addressable Blocks are shown in T able 17.SectorThe sector is the unit structure related to the erase commands. Its size is the number of blocks that are erased at any one time. The sector size is fixed for each device. The information about the sector size (in blocks) is stored in the CSD register.Write Protect Group (WP-Group)The WP-Group is the smallest structure that may be individually protected. Its size is the number of Sectors that are Write Protected with one bit. The information about the Write Protect Group size is stored in the CSD Register.Table 7.Memory array structuresType of Structure Number of structures in deviceUnit 32 MByte Devices 64 MByte Devices 128 MByte Devices 256 MByte Devices 512 MByte Devices 1 GByte Devices Blocks 512 Bytes 5977612262424832049971210024961999872Sector Block 128128128128128128WP-GroupsSector12481632Memory array partitioning SMSxxxAF, SMSxxxFF, SMSxxxBFSMSxxxAF, SMSxxxFF, SMSxxxBF Secure digital memory card interface3 Secure digital memory card interfaceThis section applies to the full-size SD Memory Card only, or to the MiniSD and MicroSD card when used with an adapter.Details on the 11-pin communication interface of the MiniSD card used without an adapter are still to be announced. Figure 3: MicroSD pin assignment shows the MicroSD pinout.The Secure Digital Memory Card has an advanced 9-pin communication interface (Clock, Command, 4 Data pins and 3 Power Supply pins) designed to operate in a low voltage range. The Secure Digital Card has its nine pins exposed on one side (see Figure 2). The signal/pin assignments are listed in Table 8 The pin types are Power Supply, Input, Output and Push-Pull. The signals include six communication lines CMD, DAT0, DAT1, DAT2, DAT3, CLK and three supply lines V DD , V SS1 and V SS2.Table 8.Full-size SD Memory Card pin assignmentPin #SD modeSPI modeNameType (1)1.S: power supply; I: input; O: output using push-pull drivers; PP: I/O using push-pull drivers.DescriptionName Type Description1CD/DA T3(2)2.The extended DAT lines (DAT1-DAT3) are input on power-up. They start to operate as DAT lines after SET_BUS_WIDTHcommand.I/O/PP (3)3.After power-up this line is input with 50kW pull-up (can be used for card detection or SPI mode selection). The pull-upshould be disconnected by the user, during regular data transfer, with SET_CLR_CARD_DETECT (ACMD42) command.Card Detect / Data Line [Bit 3]CS I Chip Select (active Low)2CMD PP Command/Response DI I Data In3V SS1S Supply voltage ground V SS S Supply voltage ground 4V DD S Supply voltage V DD S Supply voltage 5CLK I ClockSCLK I Clock6V SS2S Supply voltage ground V SS2SSupply voltage ground7DA T0I/O/PP Data Line [Bit 0]DOO/PP Data Out8DA T1(2)I/O/PP Data Line [Bit 1]Reserved 9DA T2(2)I/O/PPData Line [Bit 2]ReservedSecure digital memory card interfaceSMSxxxAF, SMSxxxFF, SMSxxxBFTable 9.MicroSD Contact Pad AssignmentPin SD ModeSPI ModeName Type (1)1.S: power supply; I: input; O: output using push-pull drivers; PP: I/O using push-pull drivers.Description Name TypeDescription1 DA T2 I/O/PP Data Line [Bit 2] RSV Reserved2CD/DA T3(2)2.The extended DAT lines (DAT1-DAT3) are input on power up. They start to operate as DAT lines after SET_BUS_WIDTH command. The Host shall keep its own DAT1-DAT3 lines in input mode, as well, while they are not used. It is defined so, in order to keep compatibility to MultiMediaCards.I/O/PP (3)3.After power up this line is input with 50KOhm pull-up (can be used for card detection or SPI modeselection). The pull-up should be disconnected by the user, during regular data transfer, with SET_CLR_CARD_DETECT (ACMD42) command.Card Detect / Data Line[Bit 3]CSIChip Select (neg true)3 CMD PP Command/Response DI I Data In4 V DDS Supply voltageV DD S Supply voltage 5 CLK I Clock SCLK I Clock 6 V SSSSupply voltage groundV SS SSupply voltage ground7 DA T0 I/O/PP Data Line [B it 0] DOO/PP Data Out8 DA T1RSVReservedSMSxxxAF, SMSxxxFF, SMSxxxBF Secure digital memory card interface3.1 Secure digital memory card bus topologyThe Secure Digital Memory Card system defines two alternative communications protocols:SD and SPI that correspond to two operating modes.Either mode can be selected in the application, mode selection is transparent to the host.The host automatically detects the operating mode of the card by issuing the Resetcommand (refer to Section7.2.1: Mode Selection) and will expect all furthercommunications to use the same mode. Therefore, applications that use only onecommunication mode do not have to be aware of the other.The SD bus includes the following signals:●CLK: Host to card clock signal●CMD: Bi-directional Command/Response signal●DAT0 - DAT3: 4 Bi-directional data signals.●V DD, V SS1, V SS2: Power and ground signals.The SD Memory Card bus has a synchronous star topology (refer to Figure4: Secure DigitalMemory Card system bus topology) with a single master (the application) and multipleslaves (the cards). The Clock, power and ground signals are common to all cards. Thecommand (CMD) and data (DAT0 - DAT3) signals are dedicated to the cards, they providecontinuous point-to-point connection to all the cards.During the initialization process, commands are sent to each card individually, allowing theapplication to detect the cards and assign logical addresses to the physical slots. Data isalways sent (received) to (from) each card individually. However, in order to simplify thehandling of the card stack, after the initialization process, all commands may be sentconcurrently to all cards. Addressing information is provided in the command packet.The SD bus allows dynamic configuration of the number of data lines. After power-up the SDMemory Card defaults to using only DAT0 for data transfer. After initialization the host canchange the bus width (number of active data lines). This feature is an easy trade off betweenhardware cost and system performance.Secure digital memory card interfaceSMSxxxAF, SMSxxxFF, SMSxxxBF1.DAT1 and DAT2 not connected.3.2 SD bus protocolCommunication over the SD bus is based on command and data bit streams which areinitiated by a start bit and terminated by a stop bit.●Command: a command is a token which starts an operation. A command is sent from the host either to a single card (addressed command) or to all connected cards (broadcast command). Commands are transferred serially on the CMD line. See Figure 5: "No Response" and "No Data" operations .The Command token format is shown in Figure 8●Response: a response is a token which is sent from an addressed card, or(simultaneously) from all connected cards, to the host, as an answer to a previously received command. Responses are transferred serially on the CMD line. A response is illustrated in Figure 5: "No Response" and "No Data" operations .The Response token format is shown in Figure 9●Data: data can be transferred from the card to the host or from the host to the card. Data is transferred via the data lines. See Figure 6: (Multiple) Block Read operation for an illustration.The Data Packet format is shown in Figure 10Card addressing is implemented using a session address assigned to the card during the initialization phase (See SD Memory Card Specification, Chapter 4). The basic transaction on the SD bus is the command/response transaction. In this type of bus transactions, the information is directly transferred within the command or response structure. In addition, some operations have a data token. Data transfers to/from the SD Memory Card are done in blocks. Data blocks are always followed by CRC bits.Single and Multiple Block operations are supported. Note that the Multiple Block operation mode improves the speed of write operations. A Multiple Block transmission is terminated by issuing a STOP_TRANSMISSION command on the CMD line (See Figure 6 and Figure 7).Data transfer can be configured by the host to use single or multiple data lines (provided that the card supports this feature).A busy signal on DAT0 is used to indicate that a Block Write operation is ongoing (see Figure7). The same busy signaling is used regardless of the number of data lines used to transfer the data.Response tokens (see Figure9) have four coding schemes depending on their content. The token length is either 48 or 136 bits (See SD Memory Card Specification, Chapter 4.5 for detailed definitions of the commands and responses). The CRC protection algorithm for data block is a 16-bit CCITT polynomial (see SD Memory Card Specification, chapter 4.5). On the CMD line, the MSB bit is transmitted first and the LSB bit last. When the wide bus option is used, the data is transferred 4 bits at a time (refer to Figure10). Start bits, End bits and CRC bits, are transmitted on all the DAT lines used. CRC bits are calculated and checked for every DAT line individually. The CRC status response and Busy indication are sent by the card to the host on DAT0 only (DAT1-DAT3 are Don’t Care).3.3 SD Memory Card Functional DescriptionAll communications between the host and the cards are controlled by the host (master).The host sends commands of two types:●Broadcast commands which are intended for all cards. Some of these commandsrequire a response.●Addressed (point-to-point) commands that are sent to the addressed card and arefollowed by a response from the card.Modes3.4 OperationFigure11 and Figure12 show an overview of the command flow for the Card Identificationmode and the Data Transfer mode, respectively.Table10 shows the relationship between operation modes and card states. Each state in theSD Memory Card state diagram (see Figure16 and Figure17) is associated with oneoperation mode.Table 10.Card States vs. Operation ModesCard state Operation modeInactive State InactiveIdle StateReady StateCard Identification ModeIdentification State3.4.1 Card Identification ModeThe host enters the Card Identification mode after reset and remains in this mode until it hasfinished searching for new cards on the bus.Cards enter the Card Identification mode after reset and remain in this mode until they receive the SEND_RCA command (CMD3) (or the SET_RCA command for MultiMediaCards).While in Card Identification mode the host resets all the cards that are in Card Identification mode, validates the operation voltage range, identifies every card and asks them to publish their Relative Card Addresses (RCA). This operation is done separately for each card on its own CMD line. In this mode, all data communications use the command line (CMD) only.The host starts the card identification process at the identification clock rate f OD . The SD Memory Card has push-pull CMD line output drives.Once the bus has been activated the host asks each card to send their valid operation conditions (ACMD41 preceded by APP_CMD - CMD55 with RCA=0000h).The response to ACMD41 is the Operation Condition Register of the card. The same command is sent to all the new cards in the system. Incompatible cards are switched to Inactive State.The host then issues the ALL_SEND_CID command (CMD2), to every card to get their unique card identification (CID) numbers. All unidentified cards (which are in Ready State) answer by sending their CID numbers (on the CMD line) and switch to the Identification State. Then the host issues a CMD3 (SEND_RELATIVE_ADDR) command to ask the cards to publish a relative card address (RCA). The RCA is shorter than the CID, and will be used to address the card (typically at a clock rate higher than f OD ) once this is in Data Transfer mode. Once the RCA is received the card state changes to Standby. At this point, the host may ask the card to publish another RCA number by sending anotherSEND_RELATIVE_ADDR command to the card. The last published RCA is the actual RCA of the card.The host repeats the identification process, that is the cycles with CMD2 and CMD3, for each card in the system. Once all the SD Memory Cards have been initialized, the host initializes the MultiMediaCards that are in the system (if any) by issuing CMD2 and CMD3 as explained in the MultiMediaCard specification. Note that in the SD system all the cards are connected separately so each MultiMediaCard has to be initialized individually.Stand-by State Data Transfer ModeT ransfer State Sending-data State Receive-data State Programming State Disconnect StateTable 10.Card States vs. Operation Modes (continued)Card stateOperation mode3.4.2 Data Transfer ModeCards enter the Data Transfer mode once their Relative Card Addresses (RCA) have beenpublished.The host enters the Data Transfer mode after identifying all the cards on the bus.The host issues SEND_CSD (CMD9) to obtain the contents of the Card Specific Data (CSD)Register for each card. The CSD Register contains information like the block length and thecard storage.Until the host knows the contents of all the CSD Registers, the f PP clock rate must remain atf OD because some cards may have operating frequency limitations.The broadcast command SET_DSR (CMD4) configures the driver stages of all identifiedcards. It programs their Driver Stage Registers (DSR) according to the application buslayout (length), the number of cards on the bus and the data transfer frequency. The clockrate is changed from f OD to f PP at that point. The SET_DSR command is an option for thecard and the host.CMD7 is used to select one card and switch it to the Transfer State. Only one card can be inTransfer State at a given time. If a previously selected card is still in Transfer State when thehost uses CMD7 to switch another card to the Transfer state, then the connection betweenthe previously selected card and the host is released and the card reverts to the StandbyState.When CMD7 is issued with the reserved relative card address "0000h", all cards revert to the Standby State. This function may be used before identifying new cards, to avoid resetting already registered cards. When in Standby state the cards that already have an RCA do not respond to identification commands (CMD41, CMD2, CMD3).Note that a card is deselected when it receives a CMD7 with an RCA that does not match. Card deselection is automatic if another card in a system is selected and the cards share the same CMD lines.So, in an SD Memory Card system, the host may either have a common CMD line for all SD Memory Cards (in which case card deselection is automatic just like in a MultiMediaCard system) or the host may have separate CMD lines, in which case it must be aware of the necessity of deselecting cards.All data communications in the Data Transfer Mode are point-to point between the host and the selected card (using addressed commands). All addressed commands are acknowledged by a response on the CMD line.The relationships between the various states in the Data Transfer mode are summarized below (see Figure12):●All Data Read commands (CMD17, CMD18, CMD30, CMD56, ACMD51) can beaborted at any time using the Stop command (CMD12). The data transfer will terminate and the card will return to the T ransfer State.●All Data Write commands (CMD24,CMD25, CMD26, CMD27, CMD42, CMD56) can beaborted at any time using the Stop command (CMD12). The write commands must be stopped prior to deselecting the card using CMD7.●As soon as the data transfer has completed, the card switches from the Data Writestate to either the Programming state (if the transfer was successful) or the T ransfer state (if the transfer failed).●If a Block Write operation is stopped and the block length and CRC of the last block arevalid, the data will be programmed.●The card can provide buffering during Block Write. This means that the data to beprogrammed to the next block can be sent to the card while the previous block is being programmed.If all write buffers are full, the DAT0 line will remain Low (BUSY) as long as the card is in the Programming state (see Figure12).●There is no buffering option for Write CSD, Write CID, Write Protection and erase. Thismeans that while the card is busy with any one of these commands, no other Data Transfer command will be accepted. The DAT0 line will remain Low as long as the card is busy and in the Programming state.●Parameter Set commands (CMD16, CMD32, CMD33) are not allowed while the card isprogramming.●Read commands are not allowed while the card is programming.●Switching another card from the Standby to the Transfer state (using CMD7) will notterminate erase and programming operations. The card will switch to the Disconnect state and release the DAT line.● A card in the Disconnect state can be reselected using CMD7. The card will then revertto the Programming state and reactivate the busy signaling.●Resetting a card (using CMD0 or CMD15) will terminate any pending or ongoingprogramming operation. This may result in the loss of card contents. It is up to the host to prevent possible data loss.3.5 CommandsFour types of commands are used to control the SD Memory Card:1.Broadcast commands (bc), no response: The broadcast feature is available only ifall the CMD lines are interconnected at the level of the host. If they are notinterconnected then each individual card will accept the command in turn.2. Broadcast commands with response (bcr): Since there is no Open Drain mode inSD Memory Cards, this type of command is used only if the host does not use acommon CMD line. The command is accepted by every individual Card and theresponses from all cards are sent simultaneously.3. addressed (point-to-point) commands (ac): There is no data transfer on DAT.4. addressed (point-to-point) data transfer commands (adtc): There is a data transferon DAT.All commands have a fixed code length of 48 bits for a transmission time of 2.4µs at 20MHz.All commands and responses are sent over the CMD line of the SD Memory Card.Command transmission always starts with the most significant bit (MSB) of the commandcodeword. All commands are protected by a CRC. All Command codewords are terminatedby the end bit (always '1'). T able11 shows the command format. All commands and theirarguments are specified in the SD Memory Card Specification.Table 11.SD Card Command Format3.6 ResponsesAll responses are sent via the command line CMD. Response transmission always starts with the leftmost bit of the response codeword. The code length depends on the response type. A response always starts with a start bit (always '0'), followed by the bit indicating the direction of transmission (from card = '0').A value denoted by 'X' in T able 12,Table 13,T able 14 and Table 15 indicates a variable entry.All responses (except for R3 Responses) are protected by a CRC. All response codewords are terminated by the end bit (always '1').There are five types of responses. Their formats are defined as follows:1.R1 (normal response command): the code length is 48 bits. Bits 45 to 40 indicate the index of the command to respond to. The index is a binary coded number (between 0 and 63). The status of the card is coded in 32 bits (see Table 12).Note that if data transfer to the card takes place, then a busy signal may appear on the data line after the transmission of each block of data. The host has to check for busy after data block transmission. 2.R1b is identical to R1 with an optional busy signal transmitted on the data line. The card may become busy after receiving these commands, depending on the state it was in prior to receiving the command. The Host has to check for busy in the response.3.R2 (CID, CSD Register): the code length is 136 bits. The contents of the CID Register are sent as a response to the CMD2 and CMD10 commands. The contents of the CSD Register are sent as a response to CMD9. Only the bits [127...1] of the CID and CSD Registers are transferred, the reserved bit [0] of these registers is replaced by the end bit of the response (see Table 13).4. R3 (OCR register): the code length is 48 bits. The contents of the OCR register are sent as a response to ACMD41 (see Section Table 14. on page 25).5.R6 (Published RCA response): the code length is 48 bits. Bits 45 to 40 indicate the index of the command to respond to. In this case it is '000011' (together with bit 5 in the status bits it means = CMD3) as shown in Table 15 The 16 MSB bits of the argument field are used for the Published RCA number.For more details about Response formats, please refer to the SD Memory Card Specification.Bit position 474645:4039:87:10Width 1163271Value '0''1'x x x '1'DescriptionStart bitT ransmissionbitCommand indexArgumentCRC7End bitTable 12.Response R1Table 13.Response R2Table 14.Response R3Table 15.Response R6Bit Position 4746[45:40][39:8][7:1]0Width (bits)1163271Value ‘0’‘0’X X X ‘1’DescriptionStart BitTransmissionBitCommand IndexCard StatusCRC7End BitBit Position 135134[133:128][127:1]0Width (bits)1161271Value ‘0’‘0’‘111111’X ‘1’DescriptionStart BitTransmission BitReservedCID or CSD register incl. internal CRC7End BitBit Position 4746[45:40][39:8][7:1]0Width (bits)1163271Value ‘0’‘0’‘111111’X ‘111111’‘1’DescriptionStart BitTransmissionBitReservedOCR RegisterReservedEnd BitBit Position 4746[45:40][39:8] Argument Field [7:1]0Width (bits)116161671Value ‘0’‘0’X X X X ‘1’DescriptionStart BitT ransmission BitCommand Index (‘000011’)New published RCA [31:16] of the card[15:0] Card Status Bits: 23, 22, 19 and 12 to 0CRC7end bit。

SD卡引脚定义及命令

SD卡引脚定义及命令

SD卡引脚定义针脚名称类型描述1.C D DAT3 I/O/PP 卡监测数据位32.C MD PP 命令/回复3.Vss S 地4.V cc S 供电电压5.C LK I 时钟6.C ss2 S 地7.D AT0 I/O/PP 数据位08.D AT1 I/O/PP 数据位19.D AT2 I/O/PP 数据位2SD卡接口标准规范SD卡上所有单元由内部时钟发生器提供时钟。

接口驱动单元同步外部时钟的DAT和CMD信号到内部所用时钟。

本卡由6线SD卡接口控制,包括:CMD,CLK,DAT0-DAT3。

在多SD卡垛叠中为了标识SD卡,一个卡标识寄存器(CID)和一个相应地址寄存器(RCA)预先准备好。

一个附加的寄存器包括不同类型操作参数。

这个寄存器叫做CSD。

使用SD卡线访问存储器还是寄存器的通信由SD卡标准定义。

卡有自己的电源开通检测单元。

无需附加的主复位信号来在电源开启后安装卡。

它防短路,在带电插入或移出卡时。

无需外部编程电压。

编程电压卡内生成。

SD卡支持第二接口工作模式SPI。

如果接到复位命令(CMD0)时,CS信号有效(低电平),SPI 模式启用。

SD卡接口规范(完整规范标准)特性:◎容量:32MB/64MB/128MB/256MB/512MB/1GByte◎兼容规范版本1.01◎卡上错误校正◎支持CPRM◎两个可选的通信协议:SD模式和SPI模式◎可变时钟频率0-25MHz◎通信电压范围:2.0-3.6V工作电压范围:2.0-3.6V◎低电压消耗:自动断电及自动睡醒,智能电源管理◎无需额外编程电压◎卡片带电插拔保护◎正向兼容MMC卡◎高速串行接口带随即存取---支持双通道闪存交叉存取---快写技术:一个低成本的方案,能够超高速闪存访问和高可靠数据存储---最大读写速率:10Mbyte/s◎最大10个堆叠的卡(20MHz,Vcc=2.7-3.6V)◎数据寿命:10万次编程/擦除◎CE和FCC认证◎PIP封装技术◎尺寸:24mm宽×32mm长×1.44mm厚本SD卡高度集成闪存,具备串行和随机存取能力。

SD卡与TF卡的引脚定义

SD卡与TF卡的引脚定义

December 2007 Rev 31/61512 MByte and 1 GByte, 3.3V Supply Secure Digital™ CardFeatures■SD Memory Card Specification Version 1.01-compliant■Up to 1 Gbyte of Formatted Data Storage ■Bus Mode–SD Protocol (1 to 4 Data Lines)–SPI Protocol■Operating Voltage Range:–Basic Communication (CMD0, CMD15, CMD55 and ACMD41): 2.0V to 3.6V–Other C ommands a nd M emory A ccess: 2.7V to 3.6V ■Variable Clock Rate: 0 to 25 MHz ■Read Access (using 4 Data Lines)–Sustained Multiple Block: 6.3 Mb/s ■Write Access (using 4 Data Lines)–Sustained Multiple Block: 3.0 Mb/s ■Maximum Data Rate with up to 10 Cards ■Aimed at Portable and Stationary Applications ■Communication Channel Protocol Attributes:–Six-wire communication channel (clock, command, 4 data lines)–Error-proof data transfer–Single or Multiple block oriented data transfer■Memory Field Error Correction ■Safe Card Removal during Read■Write Protect Feature using Mechanical Switch ■Built-in Write Protection Features (Permanent and Temporary)■SD, MiniSD and MicroSD Packages –ECOPACK ® compliant –Halogen free –Antimony freeMicroSDTable 1.Device summaryPart Number Package Form Factor Operating Voltage RangeSMS128AF SD (full size)2.7V to3.6VSMS256AF SMS512AF SMS01GAF SMS064BF MiniSD SMS128BF SMS064FF MicroSDSMS128FF SMS256FF SMS512FFDescription SMSxxxAF, SMSxxxFF, SMSxxxBF1 DescriptionThe Secure Digital Memory Card (SD Memory Card) is a Flash-Based Memory Card. It is specifically designed to meet the security, capacity, performance and environmentalrequirements of the latest-generation audio and video consumer electronic devices, that is mobile phones, digital cameras, digital recorders, PDAs, organizers, electronic toys, etc. The Secure Digital Memory Card is a high-mobility, high-performance, low-cost and low-power consumption device that features high data throughput at the memory card interface. It includes a copyright protection mechanism that complies with the security of the SDMI (Secure Digital Music Initiative) standard. The Secure Digital Memory Card security system uses mutual authentication and a “cipher algorithm” that protects the card from illegal use. Unsecured access to the user's personal content is also available.The Secure Digital Memory Cards have an advanced communication interface designed to operate in a low voltage range. The full-size Secure Digital Memory Card has a 9-pin interface whereas the Mini Secure Digital Memory Card has a 11-pin interface but can be fitted with a 9-pin adapter. Only the 9-pin interface is described in this document. The MicroSD Memory Card has an 8-pin interface, and can also be fitted with a 9-pin adapter.Table 2,T able 3,Table 4,Table 5, and Table 6 give an overview of the Secure Digital Memory Card features.In order to meet environmental requirements, the devices are offered in ECOPACK ®packages. ECOPACK packages are Lead-free. The category of second Level Interconnect is marked on the package and on the inner box label, in compliance with JEDEC Standard JESD97. The maximum ratings related to soldering conditions are also marked on the inner box label.The SD, MiniSD and MicroSD packages are also Halogen free and Antimony free.Related documentation●Secure Digital Memory Card Specifications: Part 1 Physical Layer Specification, Version 1.01●MiniSd Memory Card Specifications: Addendum to SD Memory Card Specifications Part 1 Physical layer Specification, Version 1.02●MicroSD Memory Card Specifications: Addendum to SD Memory Card Specifications Part 1, Physical Layer Specification, Version 1.00Table 2.System performanceSystem performanceMax.Typ.Unit Sleep to Ready30µs Sustained Multiple Block Read (1)1.43X, 20X, 12X and 5X Speed grade markings where 1X = 150 KBytes/s.6.3 (43X)MBytes/s Burst Single Block Read (1) 1.8 (12X)MBytes/s Sustained Multiple Block Write (1) 3.0 (20X)MBytes/s Burst Single Block Write (1)0.8 (5X)MBytes/s Power-up to Ready150msSMSxxxAF, SMSxxxFF, SMSxxxBFDescriptionTable 3.Power consumption (1)1.T A = 25°C, V DD = 3.6V.ModeMax. Current ConsumptionStandby 200 µA Read 30 mA Write30 mATable 4.Environmental specifications (1)1.NA = Not Applicable; RH = Relative Humidity; ESD = ElectroStatic DischargeEnvironmental specifications Operating Non-Operating T emperature− 25°C to 85°C − 40°C to 85°C Humidity (non- condensing)NA 85°C - 85%RHESDProtectionContact PadsNA±4kV , Human body model according to ANSI EOS/ESD-S5.1-1998Other±8kV (coupling plane discharge)±15kV (air discharge) Human body model perIEC61000-4-2Salt Water Spray NA T A = 35 °C 3% NaCl (MIL Std Method 1009)Vibration (peak-to-peak)NA 15 Gmax ShockNA1,000G Drop NA2000GBending20N (middle of the card)20N (border of the card)UV light exposure254nm, 15Ws/cm2Table 5.Physical dimensionsParameter SD MiniSD MicroSD Unit Width 2420 11mmHeight3221.515 mm Thickness 2.1 1.4Inter Connect Area 0.7±0.1mmMax. Card Thickness 0.95 Max. Pull Area1.0±0.1Weight Approx. 2Approx. 1<1g Number of Pins9118N/ADescriptionSMSxxxAF, SMSxxxFF, SMSxxxBFTable 6.System reliability and maintenanceMTBF (1)1.MTBF = Mean Time Between Failures.>1,000,000hrsPreventive Maintenance NoneData Reliability 1 non-recoverable bit in 1014 bit read Endurance>2,000,000 Program/Erase CyclesSMSxxxAF, SMSxxxFF, SMSxxxBF Memory array partitioning2 Memory array partitioningThe basic unit of data transfer to/from the SD Memory Card is the Byte. The memory array is divided into several structures as described below and summarized in Table 17.BlockThe Block is the unit structure related to block-oriented read and write commands. Its size is the number of Bytes that are transferred when a block-oriented read or write command is sent by the host. The SD Memory Card Block size is either programmable or fixed. The information about allowed block sizes and programmability is stored in the CSD Register. The details of the Memory Array Structure and the number of addressable Blocks are shown in T able 17.SectorThe sector is the unit structure related to the erase commands. Its size is the number of blocks that are erased at any one time. The sector size is fixed for each device. The information about the sector size (in blocks) is stored in the CSD register.Write Protect Group (WP-Group)The WP-Group is the smallest structure that may be individually protected. Its size is the number of Sectors that are Write Protected with one bit. The information about the Write Protect Group size is stored in the CSD Register.Table 7.Memory array structuresType of Structure Number of structures in deviceUnit 32 MByte Devices 64 MByte Devices 128 MByte Devices 256 MByte Devices 512 MByte Devices 1 GByte Devices Blocks 512 Bytes 5977612262424832049971210024961999872Sector Block 128128128128128128WP-GroupsSector12481632。

SD卡的读写和加解密

SD卡的读写和加解密

查看文章SD卡的读写和加解密2007-06-13 07:04SD卡的读写和加解密一、概述SD卡全称为Secrue Digital Memory Card,具有轻巧、可加密、传输速度高、适用于手持设备使用等优点。

二、总线接口SD需要高速读写,同时也要使手持等嵌入式设备能方便使用,特设有两个访问接口中:SD 模式接口和SPI接口。

SD卡在上电初期,卡主控通过检测引脚1(DA T3)来决定使用SD 模式还是SPI模式。

当此脚接50KOhm上拉电阻时,卡进入SD模式;当此脚为低电平,卡则工作于SPI模式。

SD引脚SD模式SPI模式1 DA T3 CS2 CMD DI3 VSS VSS4 VDD VDD5 CLK SCLK6 VSS VSS7 DA T0 DO8 DA T1 Resvered9 DA T2 Resvered表1:SD卡接口定义1、SPI接口SPI接口是为嵌入式和手持设备准备的,只使用普通的三线制SPI总线,即可对卡进行一般的慢速的读写等操作。

图一:SPI总线如上图,由读卡器到卡的数据,在每个时种的上升沿把DO的数据锁存到卡主控,而卡的数据则在每个CLK的上升沿把DI的数据读入读卡器。

2、SD接口SD接口是为高速专有设备而设计,使设备能对卡进行高速可靠的传输而设计,因SD模式在每个命令及数据转输时,都必须具有正确的CRC校验。

因此,此模式下主机一般需要专门设计的硬件模块以产生CRC校验。

在此模式下,SD卡具有四根数据线,且时种速度最大可达50MHz,所以此模式下数据传输速率比SPI模式快得多。

三、总线协议SD卡命令共分为12类,分别为class0到class11,不同的卡主控根据其功能,支持不同的命令集。

主要如下:class0:卡的识别、初始化命令集。

class2:读卡命令集class4:写卡命令集class7:卡的锁定,解锁功能命令集SD卡只有唯一的主机,所有命令是由主机发出。

总线上可传输三种类型数据,分别是命令帧、响应、数据。

SD卡引脚及spi模式基本操作过程

SD卡引脚及spi模式基本操作过程

SD卡引脚及spi模式基本操作过程注:S:电源供给I:输入O:采用推拉驱动的输出PP:采用推拉驱动的输入输出SD卡SPI模式下与单片机的连接图:SD卡支持两种总线方式:SD方式与SPI方式。

其中SD方式采用6线制,使用CLK、CMD、DAT0~DAT3进行数据通信。

而SPI方式采用4线制,使用CS、CLK、DataIn、DataOut进行数据通信。

SD 方式时的数据传输速度与SPI方式要快,采用单片机对SD卡进行读写时一般都采用SPI模式。

采用不同的初始化方式可以使SD卡工作于SD方式或SPI方式。

这里只对其SPI方式进行介绍。

SPI方式驱动SD卡的方法SD卡的SPI通信接口使其可以通过SPI通道进行数据读写。

从应用的角度来看,采用SPI接口的好处在于,很多单片机内部自带SPI控制器,不光给开发上带来方便,同时也见降低了开发成本。

然而,它也有不好的地方,如失去了SD卡的性能优势,要解决这一问题,就要用SD方式,因为它提供更大的总线数据带宽。

SPI接口的选用是在上电初始时向其写入第一个命令时进行的。

以下介绍SD卡的驱动方法,只实现简单的扇区读写。

1)命令与数据传输写命令的例程:C程序//-------------------------------------------------------------------------向SD卡中写入命令,并返回回应的第二个字节//-------------------------------------------------------------------------unsignedchar Write_Command_SD(unsignedchar*CMD){unsignedchar tmp;unsignedchar retry=0;unsignedchar i;//禁止SD卡片选SPI_CS=1;//发送8个时钟信号Write_Byte_SD(0xFF);//使能SD卡片选SPI_CS=0;//向SD卡发送6字节命令for(i=0;i<0x06;i++){Write_Byte_SD(*CMD++);}//获得16位的回应Read_Byte_SD();//readthefirstbyte,ignoreit.do{//读取后8位tmp=Read_Byte_SD();retry++;}while((tmp==0xff)&&(retry<100));return(tmp);}初始化SD卡的初始化是非常重要的,只有进行了正确的初始化,才能进行后面的各项操作。

SD卡接口的完整规范(二)

SD卡接口的完整规范(二)

SD卡接口的完整规范(二)
回复从该CMD 线上串行传输。

一个命令是对之前命令的回答。

回复可以
来自单机或所有卡。

DAT0~3:数据可以从卡传向主机或副versa。

数据通过数据线传输。

SD 卡总线拓扑SPI 模式针脚定义针脚名称类型描述1CSI 片选(负
有效)2DII 数据输入3VssS 地4VccS 供电电压5CLKI 时钟6Vss2S 地7DOO 数据输出8RSV--9RSV--1:S:电源供电,I:输入O:输出I/O:双向PP:I/O 使
用推挽驱动注意:SPI 模式时,这些信号需要在主机端用10~100K 欧的电阻上拉。

SPI 总线概念SPI 总线允许通过2 通道(数据入和出)传输比特数据。

SPI 兼容模式使得MMC 主机系统通过很小的改动就可以使用SD卡。

SPI 模式使用字
节传输。

所有的数据被融合到一些字节中并aligned to the CS signal(可能是:同过CS 信号来校正)。

SPI 模式的优点就是简化主机的设计。

特别的,MMC 主
机需要小的改动。

SPI 模式相对于SD 模式的不足之处是丧失了速度性能。

SD
卡的电特性tips:感谢大家的阅读,本文由我司收集整编。

仅供参阅!。

sdio引脚定义

sdio引脚定义

sdio引脚定义SDIO引脚定义是指SDIO(Secure DigitalInput/Output)接口的引脚定义,主要用于SD存储卡和其他SDIO设备的通信。

SDIO接口通过引脚对数据进行传输和交换,因此SDIO引脚定义对于SDIO接口的正常工作非常重要。

本文将对SDIO引脚定义进行具体介绍,包括引脚的功能、命名规则和电气特性等方面。

一、SDIO引脚定义SDIO引脚定义一般分为两部分:主机端(Host)和设备端(Device)。

其中,主机端一般指SD存储卡读卡器或主机设备,设备端一般指SDIO设备,如无线网卡、数码相机、移动电话等。

下面是SDIO引脚定义的详细内容:1.主机端引脚定义主机端引脚定义包括以下几个方面:(1)SD_CLK(时钟):传输速率的时钟,用于同步数据传输。

(2)SD_CMD(命令):主机对SDIO设备发送的命令。

(3)SD_D0~D3(数据线):SDIO设备和主机之间传输的数据线,其中SD_D0为主要数据线。

(4)SDIO_Voltage_Select(电压选择):电源电压选择引脚,用于选择SDIO设备的工作电压,通常为3.3V 或1.8V。

2.设备端引脚定义设备端引脚定义包括以下几个方面:(1)SD_CLK(时钟):传输速率的时钟,用于同步数据传输。

(2)SD_CMD(命令):主机对SDIO设备发送的命令。

(3)SD_D0~D3(数据线):SDIO设备和主机之间传输的数据线,其中SD_D0为主要数据线。

(4)SDIO_Voltage_Select(电压选择):电源电压选择引脚,用于选择SDIO设备的工作电压,通常为3.3V 或1.8V。

(5)SDIO_IRQ(中断请求):SDIO设备向主机发送中断请求的引脚,用于通知主机设备状态的变化等。

(6)SDIO_CD(卡检测):SDIO设备的卡检测引脚,用于检测SDIO设备是否插入主机。

以上是SDIO引脚定义的具体内容,下面将对SDIO引脚定义的一些特性进行介绍。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

sd卡引脚定义及命令2011-05-12 15:32 682人阅读评论(0) 收藏举报SD卡引脚定义:针脚名称类型描述1 CD DAT3 I/O/PP 卡监测数据位32 CMD PP 命令/回复3 Vss S 地4 Vcc S 供电电压5 CLK I 时钟6 Css2 S 地7 DAT0 I/O/PP 数据位08 DAT1 I/O/PP 数据位19 DAT2 I/O/PP 数据位2SD卡接口标准规范SD卡上所有单元由内部时钟发生器提供时钟。

接口驱动单元同步外部时钟的DAT和CMD 信号到内部所用时钟。

本卡由6线SD卡接口控制,包括:CMD,CLK,DAT0-DAT3。

在多SD卡垛叠中为了标识SD卡,一个卡标识寄存器(CID)和一个相应地址寄存器(RCA)预先准备好。

一个附加的寄存器包括不同类型操作参数。

这个寄存器叫做CSD。

使用SD卡线访问存储器还是寄存器的通信由SD卡标准定义。

卡有自己的电源开通检测单元。

无需附加的主复位信号来在电源开启后安装卡。

它防短路,在带电插入或移出卡时。

无需外部编程电压。

编程电压卡内生成。

SD卡支持第二接口工作模式SPI。

如果接到复位命令(CMD0)时,CS信号有效(低电平),SPI模式启用。

sd卡接口规范(完整规范标准)特性:◎容量:32MB/64MB/128MB/256MB/512MB/1GByte◎兼容规范版本1.01◎卡上错误校正◎支持CPRM◎两个可选的通信协议:SD模式和SPI模式◎可变时钟频率0-25MHz◎通信电压范围:2.0-3.6V工作电压范围:2.0-3.6V◎低电压消耗:自动断电及自动睡醒,智能电源管理◎无需额外编程电压◎卡片带电插拔保护◎正向兼容MMC卡◎高速串行接口带随即存取---支持双通道闪存交叉存取---快写技术:一个低成本的方案,能够超高速闪存访问和高可靠数据存储---最大读写速率:10Mbyte/s◎最大10个堆叠的卡(20MHz,Vcc=2.7-3.6V)◎数据寿命:10万次编程/擦除◎CE和FCC认证◎PIP封装技术◎尺寸:24mm宽×32mm长×1.44mm厚本SD卡高度集成闪存,具备串行和随机存取能力。

可以通过专用优化速度的串行接口访问,数据传输可靠。

接口允许几个卡垛叠,通过他们的外部连接。

接口完全符合最新的消费者标准,叫做SD卡系统标准,由SD卡系统规范定义。

SD卡系统是一个新的大容量存储系统,基于半导体技术的变革。

它的出现,提供了一个便宜的、结实的卡片式的存储媒介,为了消费多媒体应用。

SD卡可以设计出便宜的播放器和驱动器而没有可移动的部分。

一个低耗电和广供电电压的可以满足移动电话、电池应用比如音乐播放器、个人管理器、掌上电脑、电子书、电子百科全书、电子词典等等。

使用非常有效的数据压缩比如MPEG,SD卡可以提供足够的容量来应付多媒体数据。

SD卡上所有单元由内部时钟发生器提供时钟。

接口驱动单元同步外部时钟的DAT和CMD 信号到内部所用时钟。

本卡由6线SD卡接口控制,包括:CMD,CLK,DAT0-DAT3。

在多SD卡垛叠中为了标识SD卡,一个卡标识寄存器(CID)和一个相应地址寄存器(RCA)预先准备好。

一个附加的寄存器包括不同类型操作参数。

这个寄存器叫做CSD。

使用SD卡线访问存储器还是寄存器的通信由SD卡标准定义。

卡有自己的电源开通检测单元。

无需附加的主复位信号来在电源开启后安装卡。

它防短路,在带电插入或移出卡时。

无需外部编程电压。

编程电压卡内生成。

SD卡支持第二接口工作模式SPI。

如果接到复位命令(CMD0)时,CS信号有效(低电平),SPI模式启用。

(译者按:以下部分为本人翻译)接口该SD卡的接口可以支持两种操作模式:。

SD卡模式。

SPI模式主机系统可以选择以上其中任一模式,SD卡模式允许4线的高速数据传输。

SPI模式允许简单通用的SPI通道接口,这种模式相对于SD模式的不足之处是丧失了速度。

SD卡模式针脚定义1:S:电源供电,I:输入O:输出I/O:双向PP:I/O使用推挽驱动SD卡的总线概念SD总线允许强大的1线到4线数据信号设置。

当默认的上电后,SD卡使用DAT0。

初始化之后,主机可以改变线宽(译者按:即改为2根线,3根线。

)。

混和的SD卡连接方式也适合于主机。

在混和连接中Vcc,Vss和CLK的信号连接可以通用。

但是,命令,回复,和数据(DAT0~3)这几根线,各个SD卡必须从主机分开。

这个特性使得硬件和系统上交替使用。

SD总线上通信的命令和数据比特流从一个起始位开始,以停止位中止。

CLK:每个时钟周期传输一个命令或数据位。

频率可在0~25MHz之间变化。

SD卡的总线管理器可以不受任何限制的自由产生0~25MHz的频率。

CMD:命令从该CMD线上串行传输。

一个命令是一次主机到从卡操作的开始。

命令可以以单机寻址(寻址命令)或呼叫所有卡(广播命令)方式发送。

回复从该CMD线上串行传输。

一个命令是对之前命令的回答。

回复可以来自单机或所有卡。

DAT0~3:数据可以从卡传向主机或副versa。

数据通过数据线传输。

二、SD卡的命令1.SD卡的命令格式:SD卡的指令由6字节(Byte)组成,如下:Byte1:0 1 x x x x x x(命令号,由指令标志定义,如CMD39为100111即16进制0x27,那么完整的CMD39第一字节为01100111,即0x27+0x40)Byte2-5:Command Arguments,命令参数,有些命令没有参数Byte6:前7位为CRC(Cyclic Redundacy Check,循环冗余校验)校验位,最后一位为停止位02.SD卡的命令SD卡命令共分为12类,分别为class0到class11,不同的SDd卡,主控根据其功能,支持不同的命令集如下:Class0 :(卡的识别、初始化等基本命令集)CMD0:复位SD 卡.CMD1:读OCR寄存器.CMD9:读CSD寄存器.CMD10:读CID寄存器.CMD12:停止读多块时的数据传输CMD13:读Card_Status 寄存器Class2 (读卡命令集):CMD16:设置块的长度CMD17:读单块.CMD18:读多块,直至主机发送CMD12为止.Class4(写卡命令集) :CMD24:写单块.CMD25:写多块.CMD27:写CSD寄存器 .Class5 (擦除卡命令集):CMD32:设置擦除块的起始地址.CMD33:设置擦除块的终止地址.CMD38: 擦除所选择的块.Class6(写保护命令集):CMD28:设置写保护块的地址.CMD29:擦除写保护块的地址.CMD30: Ask the card for the status of the write protection bitsclass7:卡的锁定,解锁功能命令集class8:申请特定命令集。

class10 -11 :保留有关sd卡驱动和fat fs的实现用了3个文件来实现。

sdboot.c为sd的驱动(可理解为pdd)层,主要实现一些对sd控制器的配置以及一些基本sd命令的实现和对sd卡的操作。

sdmmc.c实现了从sd卡读取nk并跳到内存去运行的代码(基本可以理解为sd驱动的mdd 层)。

sdfat.c文件就是实现fat fs的。

mdd层通过fatfs来对pdd层操作以实现读取文件。

在整个过程中遇到了很多问题,现在列举如下:1)sd卡初始化问题……………………………………2)对sd卡操作问题SD卡包括:一个标识寄存器CID,一个相应地址寄存器RCA,一个其他参数寄存器CSD。

检测卡的插入,直接用中断引脚的电平来判断。

判断插入的卡是否是sd卡,用命令cmd55和cmd41,因为mmc卡对cmd55不做回应。

命令9就是获取sd卡中csd寄存器的值的,该值包括很多sd卡的信息,其中就有sd卡的容量。

这个值在sd卡接收到cmd9之后会以response的形式存放在sd控制器的SDI Response Register[0,1,2,3]中。

在执行cmd9,cmd10等这样的命令的时候,卡的状态应该是不选中的,或直接在执行它们之前发送cmd7(0)不选中卡,不然的话会timeout。

用cmd17来读取单个block的数据,该命令要带地址参数(该参数通过cmd3命令来获取),然后根据SDIDSTA和SDIFSTA状态值来从sd控制器的SDIDAT寄存器中读出要读的数据。

该命令与cmd9相反,在执行它之前要选中卡。

读完一个block之后要做一些善后工作,为下次读取做好准备,不然的话checkcmdend就要一直循环了。

因为用的是每次都读一个block,并地址要以block对齐,这样就要考虑要读取的地址是否是block对齐的,长度是否够一个block。

SDIDCON这个数据控制寄存器也很重要,一些对数据的操作形式就是在这里设置的。

3)fat文件系统问题根据MBR找到分区表,根据分区表找到该分区MBR[446B+4个分区表(每个16B)+2B 结束符)分区表中的第9-12字节为该分区的启始地址(单位没sector),第13-16字节为分区的长度(单位也是sector)4) 通信模式的切换:SD卡有两种通信模式:SPI模式和SD模式,默认情况下的通信模式是SD模式,但是我们常用的模式是SPI模式,这就需要一个切换模式的方法,具体的实现方法在其他地方也都有介绍,其关键的地方就是先上电延时大于74个时钟周期后发送复位命令,复位成功(接收到0x01的响应)后,连续发送CMD55和ACMD41,直到响应0X00为止,此时SD卡已经进入SPI模式。

TF卡,参考,未验证1,DATA22,CD/DATA33,CMD4,VCC5,CLK6,GND7,DATA08,DATA1sd卡:一、SD MODE1、CD/DATA32、CMD3、VSS14、VDD5、CLK6、VSS27、DATA08、DATA19、DATA2二、SPI MODE1、CS2、DI3、VSS4、VDD5、SCLK6、VSS27、DO8、RSV9、RSVCF卡一、PC CARD MEMORY MODE1、GND2、D33、D44、D55、D66、D77、CE18、A109、OE10、A911、A812、A713、VCC14、A615、A516、A417、A318、A219、A120、A021、D022、D123、D224、WP25、CD226、CD127、D1128、D1229、D1330、D1431、D1532、CE234、IORD35、IOWR36、WE37、RDY/BSY38、VCC39、CSEL40、VS241、RESET42、WAIT43、INPACK44、REG45、BVD246、BVD147、D848、D949、D1050、GNDCF卡二、PC I/O CARD MODE1、GND2、D33、D44、D55、D66、D77、CE18、A109、OE10、A911、A812、A713、VCC14、A615、A517、A318、A219、A120、A021、D022、D123、D224、IOIS1625、CD226、CD127、D1128、D1229、D1330、D1431、D1532、CE233、VS134、IORD35、IOWR36、WE37、RDY/BSY38、VCC39、CSEL40、VS241、RESET42、WAIT43、INPACK44、REG45、SPKR46、STSCHG47、D848、D949、D1050、GND三、TRUE IDE MODE1、GND2、D33、D44、D55、D66、D77、CS08、A109、ATA SEL10、A911、A812、A713、VCC14、A615、A516、A417、A318、A219、A120、A021、D022、D123、D224、IOIS1625、CD226、CD127、D1128、D1229、D1330、D1431、D1532、CS133、VS134、IORD35、IOWR36、WE37、INTRQ38、VCC39、CSEL40、VS241、RESET42、IORDY43、INPACK44、REG45、DASP46、PDIAG47、D848、D949、D1050、GND#include "../inc/includes.h"#include "New_sd.h"sbit c_SPI_CS = P2^4; //Sht-mp3 Config//set MMC_Chip_Select to high (MMC/SD-Card Invalid) #define SD_Disable() c_SPI_CS = 1//set MMC_Chip_Select to low (MMC/SD-Card Active) #define SD_Enable() c_SPI_CS = 0sbit c_SPI_SI = P1^5;sbit c_SPI_SO = P1^6;sbit c_SPI_CLK = P1^7;sbit c_SD_In = P2^7;sbit c_SD_WP = P2^6;sbit c_SD_Power = P2^3;#define Macro_Set_SI_High() c_SPI_SI = 1#define Macro_Set_SI_Low() c_SPI_SI = 0#define Macro_Set_CLK_High() c_SPI_CLK = 1 #define Macro_Set_CLK_Low() c_SPI_CLK = 0//bool bSPICLK_LowSpeed;static void SD_PowerOn(void){c_SD_Power = 0;}/*static void SD_PowerOff(void){c_SD_Power = 1;}*///extern uint8 BUFFER[512];uint8 SD_SPI_ReadByte(void);void SD_SPI_WriteByte(uint8 ucSendData);//#define SPI_ReadByte() SD_SPI_ReadByte()//#define SPI_TransferByte(x) SD_SPI_WriteByte(x) /*static uint8 SPI_ReadByte(void){uchar ucReadData;uchar ucCount;ucReadData = 0;Macro_Set_SI_High();for(ucCount=0; ucCount<8; ucCount++){ucReadData <<= 1;//降低时钟频率Macro_Set_CLK_Low();//降低时钟频率// if(bSPICLK_LowSpeed)// {// Delay_100us();// }Macro_Set_CLK_High();// if(bSPICLK_LowSpeed)// {// Delay_100us();// }if(c_SPI_SO){ucReadData |= 0x01;}}return(ucReadData);// SPDR = 0xFF;// while (!(SPSR & 0x80));// return SPDR;}static void SPI_TransferByte(uint8 ucSendData){uchar ucCount;uchar ucMaskCode;ucMaskCode = 0x80;for(ucCount=0; ucCount<8; ucCount++) {Macro_Set_CLK_Low();if(ucMaskCode & ucSendData){Macro_Set_SI_High();}else{Macro_Set_SI_Low();}//降低时钟频率// if(bSPICLK_LowSpeed)// {// Delay_100us();// }Macro_Set_CLK_High();ucMaskCode >>= 1;//降低时钟频率// if(bSPICLK_LowSpeed)// {// Delay_100us();// }}//SPDR=cmp1;//while(!(SPSR&(1<<SPIF)));}*/static uint8 SPI_ReadByte(void){uchar ucReadData;uchar ucCount;ucReadData = 0;Macro_Set_SI_High();for(ucCount=0; ucCount<8; ucCount++) {ucReadData <<= 1;//降低时钟频率Macro_Set_CLK_Low();//降低时钟频率// if(bSPICLK_LowSpeed)// {// Delay_100us();// }Macro_Set_CLK_High();// if(bSPICLK_LowSpeed)// {// Delay_100us();// }if(c_SPI_SO){ucReadData |= 0x01;}}return(ucReadData);// SPDR = 0xFF;// while (!(SPSR & 0x80));// return SPDR;}static void SPI_TransferByte(uint8 ucSendData) {uchar ucCount;uchar ucMaskCode;ucMaskCode = 0x80;for(ucCount=0; ucCount<8; ucCount++){Macro_Set_CLK_Low();if(ucMaskCode & ucSendData){Macro_Set_SI_High();}else{Macro_Set_SI_Low();}//降低时钟频率// if(bSPICLK_LowSpeed)// {// Delay_100us();// }Macro_Set_CLK_High();ucMaskCode >>= 1;//降低时钟频率// if(bSPICLK_LowSpeed)// Delay_100us();// }}//SPDR=cmp1;//while(!(SPSR&(1<<SPIF)));}void SD_Port_Init(void)//**************************************************************************** {c_SPI_SO = 1;c_SD_In = 1;c_SD_WP = 1;SD_PowerOn();}//**************************************************************************** //Send a Command to MMC/SD-Card//Return: the second byte of response register of MMC/SD-Card uint8 Write_Command_SD(uint8 *cmd)//**************************************************************************** {uint8 tmp,i;uint8 retry=0;SD_Disable();SPI_TransferByte(0xFF);SD_Enable();for(i=0;i<6;i++)SPI_TransferByte(*cmd++);}SPI_ReadByte();do{tmp = SPI_ReadByte();}while((tmp==0xff)&&(retry++ <100));return(tmp);}//**************************************************************************** //Send a Command to MMC/SD-Card//Return: the second byte of response register of MMC/SD-Card uint8 Write_Command_SD_HighSpeed(uint8 *cmd)//**************************************************************************** {uint8 tmp,i;uint8 retry=0;SD_Disable();SD_SPI_WriteByte(0xFF);SD_Enable();for(i=0;i<6;i++){SD_SPI_WriteByte(*cmd++);}SD_SPI_ReadByte();do{tmp = SD_SPI_ReadByte();}while((tmp==0xff)&&(retry++ <100));return(tmp);}//****************************************************************************//Routine for Init MMC/SD card(SPI-MODE)uint8 SD_Init(void)//**************************************************************************** {uint8 retry,temp;uint8 i;uint8 CMD[] = {0x40,0x00,0x00,0x00,0x00,0x95};SD_Port_Init(); //Init SPI port// for (i = 0; i < 200; i++) asm("nop"); //Wait MMC/SD ready...for (i = 0; i < 200; i++){_nop_();}//Active SPI bus at low speed// SPCR=0x53; //SPI Master,MSB First// SPSR=0x00; //double speed disable,Fsck=Fosc/128for (i = 0; i < 16; i++)SPI_TransferByte(0xff); //send 74 clock at least!!!//Send Command CMD0 to MMC/SD CardSD_Enable();retry = 0;do{ //retry 200 times to send CMD0 commandtemp = Write_Command_SD(CMD);if (retry++ == 200)return INIT_CMD0_ERROR;//CMD0 Error!}while (temp != 1);//Send Command CMD1 to MMC/SD-CardCMD[0] = 0x41; //Command 1CMD[5] = 0xFF;retry = 0;do{ //retry 100 times to send CMD1 commandtemp = Write_Command_SD(CMD);if (retry++ == 100)return INIT_CMD1_ERROR;//CMD1 Error!}while (temp != 0);//Active High-speed SPI mode(Fsck=Fosc/2)// SPCR = 0x50;// SPSR = 0x00;SD_Disable(); //set MMC_Chip_Select to highreturn INIT_OK; //All commands have been taken.}uint8 SD_Read_Block(uint8 *CMD,uint8 *Buffer,uint16 Bytes)//**************************************************************************** {uint16 i;uint8 retry, temp;//Send Command CMD to MMC/SD-Cardretry=0;//#if 1do{ //Retry 100 times to send command.// temp=Write_Command_SD(CMD);temp=Write_Command_SD_HighSpeed(CMD);if(retry++ == 100)return READ_BLOCK_ERROR; //block write Error!}while (temp != 0);//Read Start Byte form MMC/SD-Card (FEh/Start Byte)while (SPI_ReadByte() != 0xfe);//#endif//Read blocks(normal 512Bytes) to MMC/SD-Card#if 1for (i = 0; i < Bytes; i++) //int count for loop cost 13 machine cycle{// *Buffer++ = SPI_ReadByte(); //Cost 70 Machine Cycle//When define point is a Xdata point then Cost 62 Machine Cycle*Buffer++ = SD_SPI_ReadByte(); //Cost 70 Machine Cycle// put_c(*Buffer);}#endif/*i = Bytes;while(i--) //When Delete {} 2 Machine Cycle is save.*Buffer++ = SPI_ReadByte(); //Cost 70 Machine Cycle*///CRC-ByteSPI_ReadByte();//CRC - ByteSPI_ReadByte();//CRC - Byte//set MMC_Chip_Select to high (MMC/SD-Card invalid)SD_Disable();return READ_BLOCK_OK;}//**************************************************************************** //Routine for writing a Block(512Byte) to MMC/SD-Card//Return 0 if sector writing is completed.uint8 SD_read_sector(uint32 addr,uint8 *Buffer)//**************************************************************************** {//Command 16 is reading Blocks from MMC/SD-Card uint8 CMD[] = {0x51,0x00,0x00,0x00,0x00,0xFF};// asm("cli"); //clear all interrupt.//Address conversation(logic block address-->byte address)addr = addr << 9; //addr = addr * 512CMD[1] = ((addr & 0xFF000000) >>24 );CMD[2] = ((addr & 0x00FF0000) >>16 );CMD[3] = ((addr & 0x0000FF00) >>8 );return SD_Read_Block(CMD, Buffer, 512);}/*uint8 SD_write_sector(uint32 addr,uint8 *Buffer)//**************************************************************************** {uint8 tmp,retry;uint16 i;//Command 24 is a writing blocks command for MMC/SD-Card.uint8 CMD[] = {0x58,0x00,0x00,0x00,0x00,0xFF};asm("cli"); //clear all interrupt.addr = addr << 9; //addr = addr * 512CMD[1] = ((addr & 0xFF000000) >>24 );CMD[2] = ((addr & 0x00FF0000) >>16 );CMD[3] = ((addr & 0x0000FF00) >>8 );//Send Command CMD24 to MMC/SD-Card (Write 1 Block/512 Bytes) retry=0;do{ //Retry 100 times to send command.tmp = Write_Command_SD(CMD);if(retry++ == 100)return(tmp); //send commamd Error!}while(tmp != 0);//Before writing,send 100 clock to MMC/SD-Cardfor (i = 0; i < 100; i++)SPI_ReadByte();//Send Start Byte to MMC/SD-CardSPI_TransferByte(0xFE);//Now send real data Bolck (512Bytes) to MMC/SD-Cardfor (i = 0; i < 512; i++)SPI_TransferByte(*Buffer++); //send 512 bytes to Card//CRC-ByteSPI_TransferByte(0xFF); //Dummy CRCSPI_TransferByte(0xFF); //CRC Codetmp=SPI_ReadByte(); // read responseif((tmp & 0x1F) != 0x05) // data block accepted ?{SD_Disable();return WRITE_BLOCK_ERROR; //Error!}//Wait till MMC/SD-Card is not busywhile (SPI_ReadByte() != 0xFF){};//set MMC_Chip_Select to high (MMC/SD-Card Invalid)SD_Disable();return 0;}*/extern unsigned char xdata Page_Buf[512]; //文件缓冲区。

相关文档
最新文档