www.ti.com
Initialization and Configuration Using Peripheral APIs
365
SWRU543–January 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
SD Host Controller Interface
11.4.2 Sending Command
The code that follows shows how to send a command to an attached SD card using peripheral APIs.
SendCmd(unsigned long ulCmd, unsigned long ulArg)
{
unsigned long ulStatus;
//
// Clear interrupt status
//
SDHostIntClear(SDHOST_BASE,0xFFFFFFFF);
//
// Send command
//
SDHostCmdSend(SDHOST_BASE,ulCmd,ulArg);
//
// Wait for command complete or error
//
do
{
ulStatus = SDHostIntStatus(SDHOST_BASE);
ulStatus = (ulStatus
& (SDHOST_INT_CC|SDHOST_INT_ERRI));
}
while( !ulStatus );
//
// Check error status
//
if(ulStatus
&SDHOST_INT_ERRI)
{
//
// Reset the command line
//
SDHostCmdReset(SDHOST_BASE);
return 1;
}
else
{
return 0;
}
}
The ulCmd parameter is logical OR of the SD command, expected response length, or flags, indicating if
the command is followed by a block read or write, a multiblock read or write, and whether the host
controller will generate a DMA request for data to and from the internal FIFO.
For example, the SD card command 0 (or GO_IDLE command) has neither a response associated with it
nor any block read or write that follows it. The command does not take any argument. For this the
SendCmd() is invoked as follows:
#define CMD_GO_IDLE_STATE SDHOST_CMD_0
SendCmd(CMD_GO_IDLE_STATE, 0)