SWRU543B January 2019 – June 2025 CC3230S , CC3230SF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
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)
Another command example is the SD card command 18, used to read multiple blocks from the SD card. The command takes the block number or linear address of the first byte to be read based on the version and capacity of the attached card:
#define CMD_READ_MULTI_BLKSDHOST_CMD_18| SDHOST_RD_CMD| SDHOST_RESP_LEN_48| SDHOST_MULTI_BLK
SendCmd(CMD_READ_MULTI_BLK,
<ulBlockNo>)