Information Technology Reference
In-Depth Information
Error Codes
The SDC_Error enumeration names various MultiMediaCard communica-
tion errors:
typedef enum
{
sdcValid = 0, // No error
sdcCardInitCommFailure, // Communication hasn't been established with the card.
sdcCardNotInitFailure,
// Card did not initialize.
sdcCardInitTimeout,
// Card initialization timed out.
sdcCardTypeInvalid,
// Card type was not able to be defined.
sdcCardBadCmd,
// Card did not recognize the command.
sdcCardTimeout,
// Card timed out during a read, write or erase sequence.
sdcCardCRCError,
// A CRC error occurred during a read.
sdcCardDataRejected,
// CRC did not match.
sdcEraseTimedOut
// Erase timed out.
}SDC_Error;
A Function for Sending Commands
The SendSDCCmd function sends a command on the SPI bus and returns
an SDC_RESPONSE structure. The function accepts a byte that corre-
sponds to an entry in the command table (cmd) and a 4-byte command
argument (address). The function calls the ReadMedia and WriteSPI func-
tions introduced in Chapter 4.
The function ends after sending a command and receiving a response. If the
response will be followed by data to or from the card, the function leaves CS
low. Firmware can then call another function (SectorWrite or SectorRead,
presented later in this chapter) to send or receive data.
SDC_RESPONSE SendSDCCmd(byte cmd, dword address)
{
CMD_PACKET
CmdPacket;
byte
index;
SDC_RESPONSE
response;
word
timeout = 9;
// Bring the card's chip-select line low.
SDC_CS = 0;
Search WWH ::




Custom Search