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

📄 sd.h

📁 VS1003_MP3_SPI_SDHC_FAT32
💻 H
字号:
#include "stm32l1xx.h"

#ifndef _SD_H_
#define _SD_H_
/*命令宏*/
#define CMD0	(0x40+0)	/* GO_IDLE_STATE */
#define CMD1	(0x40+1)	/* SEND_OP_COND */
#define ACMD41	(0x40+41)	/* SEND_OP_COND */
#define CMD8	(0x40+8)	/* SEND_IF_COND */
#define CMD9	(0x40+9)	/* SEND_CSD */
#define CMD10	(0x40+10)	/* SEND_CID */
#define CMD12	(0x40+12)	/* STOP_TRANSMISSION */
#define ACMD13	(0x40+13)	/* SD_STATUS */
#define CMD16	(0x40+16)	/* SET_BLOCKLEN */
#define CMD17	(0x40+17)	/* READ_SINGLE_BLOCK */
#define CMD18	(0x40+18)	/* READ_MULTIPLE_BLOCK */
#define ACMD23	(0x40+23)	/* SET_WR_BLK_ERASE_COUNT */
#define CMD24	(0x40+24)	/* WRITE_BLOCK */
#define CMD25	(0x40+25)	/* WRITE_MULTIPLE_BLOCK */
#define CMD32	(0x40+32)	/* ERASE_BLOCK_START_ADDR */
#define CMD33	(0x40+33)	/* ERASE_BLOCK_END_ADDR */
#define CMD38	(0x40+38)	/* ERASE_SELECTED_BLOCKS */
#define CMD55	(0x40+55)	/* APP_CMD */
#define CMD58	(0x40+58)	/* READ_OCR */


#define SD_SO			  GPIO_Pin_11
#define SD_SI			  GPIO_Pin_12
#define SD_SCK			  GPIO_Pin_5

#define SD_CS             GPIO_Pin_11				      // PB
#define SD_CS_ASSERT      GPIO_ResetBits(GPIOB, SD_CS)    // CS = 0
#define SD_CS_DEASSERT    GPIO_SetBits(GPIOB, SD_CS)      // CS = 1

/*SD卡初始化*/
uint8_t SD_init(void);

/*命令发送函数*/
uint8_t SD_sendCommand(uint8_t cmd, uint32_t arg);

/*读单块*/
uint8_t SD_readSingleBlock(uint8_t *buff, uint32_t startBlock);

/*写单块*/
uint8_t SD_writeSingleBlock(const uint8_t *buff, uint32_t startBlock);

/*读多块*/
uint8_t SD_readMultipleBlock (uint8_t *buff, uint32_t startBlock, uint32_t totalBlocks);

/*写单块*/
uint8_t SD_writeMultipleBlock(const uint8_t *buff, uint32_t startBlock, uint32_t totalBlocks);

/*块擦除*/
uint8_t SD_erase (uint32_t startBlock, uint32_t totalBlocks);

/*块接收*/
uint8_t receive_DataBlock(uint8_t *buff, uint32_t btr);

/*块发送*/
uint8_t transmit_DataBlock(const uint8_t *buff, uint8_t token);

#endif

⌨️ 快捷键说明

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