⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdcmd.h

📁 SD卡的SPI驱动程序
💻 H
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzhou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			sdcmd.h
** Last modified Date:	2005-1-6
** Last Version:		V1.0
** Descriptions:		Soft Packet of SD Card Driver: commands that sd card supported in spi mode(header file)
**
**------------------------------------------------------------------------------------------------------
** Created by:			Ming Yuan Zheng
** Created date:		2005-1-6
** Version:				V1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Jing.Zhang
** Modified date:		2005-12-19
** Version:				
** Descriptions:		
**
**------------------------------------------------------------------------------------------------------
** Modified by: 
** Modified date:
** Version:	
** Descriptions: 
**
********************************************************************************************************/
#ifndef  __SD_CMD_H__
#define  __SD_CMD_H__

#ifdef __SDCMD_GLOBAL__
#define  __SDCMD_EXT__ 
#else
#define  __SDCMD_EXT__ extern
#endif
/*
 *Command Set of SD card  
 *
 */

/* Responses */
#define R1  1     //Standard response
#define R1B 2     //is identical to R1 with an optional busy signal
#define R2  3     //CID,CSD register
#define R3  4     //OCR register

/* the Mask of bit error indications in Format R1 */
#define MSK_IDLE          		  0x01   //In idle State
#define MSK_ERASE_RST     		  0x02   //Erase Reset
#define MSK_ILL_CMD       		  0x04   //Illegal command
#define MSK_CRC_ERR       		  0x08   //Communication CRC error
#define MSK_ERASE_SEQ_ERR 		  0x10   //Erase sequence error
#define MSK_ADDR_ERR      		  0x20   //Address error
#define MSK_PARAM_ERR     		  0x40   //Parameter error

/* the Mask of bit error indications in Data Error Token */
#define MSK_TOK_ERROR             0x01   //Error
#define MSK_TOK_CC_ERROR          0x02   //Internal device controller error
#define MSK_TOK_ECC_FAILED        0x04   //ECC was applied but failed
#define MSK_TOK_CC_OUTOFRANGE     0x08   //Out of range
#define MSK_TOK_CC_LOCKED         0x10   //not supported by the SanDisk TriFlash
 


/* Data Tokens */
#define SD_TOK_READ_STARTBLOCK    0xFE   //Start Block token for Single Block Read
#define SD_TOK_WRITE_STARTBLOCK   0xFE   //Start Block token for Single Block Write
#define SD_TOK_READ_STARTBLOCK_M  0xFE   //Start Block token for Multiple Block Read
#define SD_TOK_WRITE_STARTBLOCK_M 0xFC   //Start Block token for Multiple Block Write
#define SD_TOK_STOP_MULTI         0xFD   //Stop Multiple Block transmission

/* Data Response Tokens */
#define SD_RESP_DATA_MSK		  0x0F		//Mask of the Data Response Tokens 
#define SD_RESP_DATA_ACCETPTED	  0x05		//Data accepted
#define SD_RESP_DATA_REJECT_CRC	  0x0B      //Data rejected due to a CRC error
#define SD_RESP_DATA_REJECT_WRITE 0x0D		//Data rejected due to a write error

/* Wait Type */
#define SD_WAIT_READ			  0x00		//No need to wait read
#define SD_WAIT_WRITE			  0x01		//wait 8(clocks)*1 
#define SD_WAIT_ERASE		 	  0x02		//wait 8(clocks)*2 


#define SD_READREG_TIMEOUT		  8



/********************************  Basic command set **************************/
/*  Reset cards to idle state */
#define CMD0 0
#define CMD0_R R1

/*  Read the OCR (MMC mode, do not use for SD cards) */
#define CMD1 1
#define CMD1_R R1

/*  Card sends the CSD */
#define CMD9 9
#define CMD9_R R1

/*  Card sends CID */
#define CMD10 10
#define CMD10_R R1

/*  Stop a multiple block (stream) read/write operation */
#define CMD12 12
#define CMD12_R R1B

/*  Get the addressed card's status register */
#define CMD13 13
#define CMD13_R R2

/*****************************  Block read commands **************************/

/*  Set the block length */
#define CMD16 16
#define CMD16_R R1

/*  Read a single block */
#define CMD17 17
#define CMD17_R R1

/*  Read multiple blocks until a CMD12 */
#define CMD18 18
#define CMD18_R R1

/*****************************  Block write commands *************************/
/*  Write a block of the size selected with CMD16 */
#define CMD24 24
#define CMD24_R R1

/*  Multiple block write until a CMD12 */
#define CMD25 25
#define CMD25_R R1

/*  Program the programmable bits of the CSD */
#define CMD27 27
#define CMD27_R R1

/*****************************  Write protection *****************************/
/* Set the write protection bit of the addressed group */
#define CMD28 28
#define CMD28_R R1B

/* Clear the write protection bit of the addressed group */
#define CMD29 29
#define CMD29_R R1B

/* Ask the card for the status of the write protection bits */
#define CMD30 30
#define CMD30_R R1

/*****************************  Erase commands *******************************/
/*  Set the address of the first write block to be erased */
#define CMD32 32
#define CMD32_R R1

/*  Set the address of the last write block to be erased */
#define CMD33 33
#define CMD33_R R1

/*  Erase the selected write blocks */
#define CMD38 38
#define CMD38_R R1B

/*****************************  Lock Card commands ***************************/
/*  Set/reset the password or lock/unlock the card */
#define CMD42 42
#define CMD42_R	R1B
/* Commands from 42 to 54, not defined here */

/*****************************  Application-specific commands ****************/
/*  Flag that the next command is application-specific */
#define CMD55 55
#define CMD55_R R1

/*  I/O  General purpose I/O for application-specific commands */
#define CMD56 56
#define CMD56_R R1

/*  Read the OCR (SPI mode only) */
#define CMD58 58
#define CMD58_R R3

/*  CRC Turn CRC on or off */
#define CMD59 59
#define CMD59_R R1

/*****************************  Application-specific commands ***************/
/*  Get the SD card's status */
#define ACMD13 13
#define ACMD13_R R2

/*  Get the number of written write blocks (Minus errors ) */
#define ACMD22 22
#define ACMD22_R R1

/*  Set the number of write blocks to be pre-erased before writing */
#define ACMD23 23
#define ACMD23_R R1

/*  Get the card's OCR (SD mode) */
#define ACMD41 41
#define ACMD41_R R1

/*  Connect or disconnect the 50kOhm internal pull-up on CD/DAT[3] */
#define ACMD42 42
#define ACMD42_R R1

/*  Get the SD configuration register */
#define ACMD51 51
#define ACMD51_R R1



__SDCMD_EXT__ int SD_SendCmd(INT8U cmd, INT8U *param, INT8U resptype, INT8U *resp);  
__SDCMD_EXT__ void SD_PackParam(INT8U *parameter, INT32U value);						 
__SDCMD_EXT__ int SD_BlockCommand(INT8U cmd, INT8U resptype, INT32U parameter);		 

	
__SDCMD_EXT__ int SD_ResetSD(void);						                   // Reset SD card   

__SDCMD_EXT__ int SD_ReadCSD(INT8U csdlen, INT8U *recvbuf);		    		// read CSD register
__SDCMD_EXT__ int SD_ReadCID(INT8U cidlen, INT8U *recvbuf);					// read CID register
__SDCMD_EXT__ int SD_StopTransmission(void);							
__SDCMD_EXT__ int SD_ReadCard_Status(INT8U len, INT8U *buffer);				// read Card Status register
__SDCMD_EXT__ int SD_SetBlockLen(INT32U length);				    		// 
__SDCMD_EXT__ int SD_ReadSingleBlock(INT32U blockaddr);						// 
__SDCMD_EXT__ int SD_ReadMultipleBlock(INT32U blockaddr);			    	// 

__SDCMD_EXT__ int SD_WriteSingleBlock(INT32U blockaddr);				    // 
__SDCMD_EXT__ int SD_WriteMultipleBlock(INT32U blockaddr);					//  


__SDCMD_EXT__ int SD_ProgramCSD(INT8U len, INT8U *buff);					// write CSD register 

__SDCMD_EXT__ int SD_EraseStartBlock(INT32U startblock);					// 
__SDCMD_EXT__ int SD_EraseEndBlock(INT32U endblock);	            		// 
__SDCMD_EXT__ int SD_EraseSelectedBlock(void);					    		// 


__SDCMD_EXT__ int SD_ReadOCR(INT8U ocrlen, INT8U *recvbuf);					// read OCR register
__SDCMD_EXT__ int SD_EnableCRC(INT8U bEnable);								// enable CRC


// Application specific
__SDCMD_EXT__ int SD_ReadSD_Status(INT8U sdslen, INT8U *recvbuf);			// read SD_Status 
__SDCMD_EXT__ int SD_GetNumWRBlcoks(INT32U *blocknum);				    	// 
__SDCMD_EXT__ int SD_ReadSCR(INT8U scrlen, INT8U *recvbuf);					// read SCR register



__SDCMD_EXT__ int SD_ReadRegister(INT32U len, INT8U *recvbuf);				// 
__SDCMD_EXT__ int SD_ReadBlockData(INT32U len, INT8U *recbuf);				// 
__SDCMD_EXT__ int SD_WriteBlockData(INT8U bmulti, INT32U len, const INT8U *sendbuf);		


void SD_StopMultiToken(void);									// 
__SDCMD_EXT__ int SD_WaitBusy(INT8U waittype);								// 
void SD_SPIDelay(INT8U value);									// 

#endif /* __SD_CMD_H__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -