Information Technology Reference
In-Depth Information
// Store a command byte, address, and CRC value in the CMD_PACKET structure.
CmdPacket.cmd = sdmmc_cmdtable[cmd].CmdCode;
CmdPacket.address = address;
CmdPacket.crc = sdmmc_cmdtable[cmd].CRC;
// Send the command byte, address bytes, and CRC byte.
// The WriteSPI library function writes a byte on the SPI bus.
WriteSPI(CmdPacket.cmd);
WriteSPI(CmdPacket.addr3);
WriteSPI(CmdPacket.addr2);
WriteSPI(CmdPacket.addr1);
WriteSPI(CmdPacket.addr0);
WriteSPI(CmdPacket.crc);
// Is the command's response type R1 or R1b?
if (sdmmc_cmdtable[cmd].responsetype == R1 ||
sdmmc_cmdtable[cmd].responsetype == R1b)
{
do
{
// Read a byte from the card until the byte doesn't equal FFh or a timeout occurs.
response.r1._byte = ReadMedia();
timeout--;
} while ((response.r1._byte == 0xFF) && (timeout != 0));
}
// Is the command's response type R2?
else if (sdmmc_cmdtable[cmd].responsetype == R2)
{
do
{
// read the first bye of the response.
// _byte0 transmits first.
response.r2._byte0 = ReadMedia();
timeout--;
} while ((response.r2._byte0 == 0xFF) && (timeout != 0));
Search WWH ::




Custom Search