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

📄 cjsd.h

📁 没有谁会编写低速模式的下的SDHC驱动
💻 H
📖 第 1 页 / 共 2 页
字号:
/******************************** 基本命令集 Basic command set **************************/
/* 复位SD 卡 Reset cards to idle state */
#define CMD0 0
#define CMD0_R R1

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

/* 读CSD寄存器 Card sends the CSD */
#define CMD9 9
#define CMD9_R R1

/* 读CID寄存器 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

/* 读 Card_Status 寄存器 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

/* 读多块,直至主机发送CMD12为止 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

/* 写CSD寄存器 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

/* 读OCR寄存器  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 ***************/
/* 获取 SD Status寄存器 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

/* 读取OCR寄存器 Get the card's OCR (SD mode) */
#define ACMD41 41
#define ACMD41_R R1

/* 连接/断开CD/DATA[3]引脚上的上拉电阻 Connect or disconnect the 50kOhm internal pull-up on CD/DAT[3] */
#define ACMD42 42
#define ACMD42_R R1

/* 读取SCR寄存器 Get the SD configuration register */
#define ACMD51 51
#define ACMD51_R R1



unsigned char SD_SendCmd(unsigned char cmd, unsigned char *param, unsigned char resptype, unsigned char *resp);  // 一个SPI命令 
void SD_PackParam(unsigned char *parameter, unsigned long value);						 // 封装参数
unsigned char SD_BlockCommand(unsigned char cmd, unsigned char resptype, unsigned long parameter);		 // 块命令 

	
unsigned char SD_ResetSD(void);											// 复位SD卡

unsigned char SD_ReadCSD(unsigned char csdlen, unsigned char *recbuf);					// 读CSD 			read CSD register
unsigned char SD_ReadCID(unsigned char cidlen, unsigned char *recbuf);					// 读CID			read CID register
unsigned char SD_StopTransmission(void);								// 停止传输			

unsigned char SD_ReadCard_Status(unsigned char len, unsigned char *buffer);				// 读Card Status	read Card Status register
unsigned char SD_SetBlockLen(unsigned long length);							// 设置块长度

unsigned char SD_ReadSingleBlock(unsigned long blockaddr);						// 读单块
unsigned char SD_ReadMultipleBlock(unsigned long blockaddr);					// 读多块

unsigned char SD_WriteSingleBlock(unsigned long blockaddr);					// 写单块
unsigned char SD_WriteMultipleBlock(unsigned long blockaddr);					// 写多块 


unsigned char SD_ProgramCSD(unsigned char len, unsigned char *buff);					// 写CSD寄存器  	write CSD register 

unsigned char SD_EraseStartBlock(unsigned long startblock);					// 擦块起始地址
unsigned char SD_EraseEndBlock(unsigned long endblock);						// 擦块终止地址
unsigned char SD_EraseSelectedBlock(void);								// 擦除所选的块


unsigned char SD_ReadOCR(unsigned char ocrlen,unsigned char *recbuf);					// 读OCR			read OCR register
unsigned char SD_EnableCRC(unsigned char bEnable);								// 使能CRC校验		enable CRC


// 特殊应用命令
unsigned char SD_ReadSD_Status(unsigned char sdslen, unsigned char *recbuf);			// 读SD_Status  read SD_Status 
unsigned char SD_GetNumWRBlcoks(unsigned long *blocknum);						// 得到正确写入块数
unsigned char SD_ReadSCR(unsigned char scrlen, unsigned char *recbuf);					// 读SCR 		read SCR register


// 数据流函数
unsigned char SD_ReadRegister(unsigned long len, unsigned char *recbuf);						// 读数据
unsigned char SD_ReadBlockData(unsigned long len, unsigned char *recbuf);						// 读块数据
unsigned char SD_WriteBlockData(unsigned char bmulti, unsigned long len, unsigned char *sendbuf);		// 写块数据

// 其它函数
void SD_StopMultiToken(void);									// 停止多块写令牌
unsigned char SD_WaitBusy(unsigned char waittype);								// 忙
void SD_SPIDelay(unsigned char value);									// 发生SPI时钟



extern unsigned short SD_GetCRC16(unsigned char *pSource,unsigned short len);	//得到len个字节的CRC16

extern unsigned char SD_GetCmdByte6(unsigned char cmd,unsigned char *param);	//得到SD命令的第6个字节: CRC7 + 停止位1

extern unsigned char SD_GetCRC7(unsigned char *pSource,unsigned short len);		//得到len个字节的CRC7

/* 检测卡是否完全插入  check weather card is insert entirely */
extern unsigned char SD_ChkCard(void);


extern unsigned char SD_ChkCardWP(void);


/* 初始化访问SD卡的硬件初始化 initialize the hardware that access sd card */
extern void SD_HardWareInit(void);

/* 设置SPI的时钟小于400kHZ set the clock of SPI less than 400kHZ */
extern void SPI_Clk400k(void);

/* 设置SPI的clock到最大值 set the clock of SPI to maximum */
extern void SPI_ClkToMax(void);

/* 通过SPI接口发送一个字节 send a byte by SPI interface */
extern void SPI_SendByte(unsigned char byte);

/* 从SPI接口接收一个字节 receive a byte from SPI interface */
extern unsigned char SPI_RecByte(void);

/* 片选SPI从机 select the SPI slave */
extern void SPI_CS_Assert(void);

/* 不片选SPI从机 not select the SPI slave */
extern void SPI_CS_Deassert(void);

⌨️ 快捷键说明

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