1.SD卡命令
static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size)
{
struct mmc_command cmd;
int ret;
cmd.opcode = MMC_SET_BLOCKLEN; //命令
cmd.arg = size; //参数
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; //命令类型
ret = mmc_wait_for_cmd(test->card->host, &cmd, 0);
if (ret)
return ret;
return 0;
}
命令类型(BC,BCR,AC,ADTC):
SPI Mode & SD Mode:
The SD Card wakes up in the SD Bus mode. It will enter SPI mode if the CS signal is asserted (negative) during the reception of the reset command (CMD0).
The default command structure/protocol for SPI mode is that CRC checking is disabled. Since the card powers up in SD Bus mode, CMD0 must be followed by a valid CRC byte (even though the command is sent using the SPI structure). Once in SPI mode, CRCs are disabled by default.
2.SD参考程序
//sd卡写命令 //sd send command uint8 MMC_SD_SendCommand(uint8 cmd, uint32 arg) { uint8 r1; uint8 retry=0; SPI_WriteByte(0xff); SPI_WriteByte(0xff); SPI_WriteByte(0xff); SPI_WriteByte(0xff); SPI_WriteByte(0xff); SPI_WriteByte(0xff); SPI_CS_Assert(); SPI_WriteByte(cmd | 0x40);//分别写入命令 //send command SPI_WriteByte(arg>>24); SPI_WriteByte(arg>>16); SPI_WriteByte(arg>>8); SPI_WriteByte(arg); SPI_WriteByte(0x95); while((r1 = SPI_WriteByte(0xff)) == 0xff)//等待响应, //wait response if(retry++ > 100) break;//超时退出 //time out error SPI_CS_Deassert(); return r1;//返回状态值 //return state } //sd卡复位 //reset sd card (software) uint8 MMC_SD_Reset(void) { uint8 i; uint8 retry; uint8 r1=0; retry = 0; SPI_Low(); do { for(i=0;i<100;i++) SPI_WriteByte(0xff); r1 = MMC_SD_SendCommand(0, 0);//发idle命令 //send idle command retry++; if(retry>10) return 1;//超时退出 //time out } while(r1 != 0x01); retry = 0; do { r1 = MMC_SD_SendCommand(1, 0);//发active命令 //send active command retry++; if(retry>100) return 1;//超时退出 //time out } while(r1); SPI_High(); r1 = MMC_SD_SendCommand(59, 0);//关crc //disable CRC r1 = MMC_SD_SendCommand(16, 512);//设扇区大小512 //set sector size to 512 return 0;//正常返回 //normal return }
3.处理器关于如何识别SDIO、SD、MMC的流程图(LINUX)
nanjing