Following the example of pseudocode on the datasheet of p2020 I have implemented the function that allows me to send commands.
void send_command(int cmd_index)
{
int count;
unsigned int wCmd;
unsigned int temp0,temp1;
// cmd_index
wCmd = (cmd_index & 0x3F) << 24;
// -No response
// -Data present
// -Enable. The eSDHC checks the index field in the response to see if it has the same value as the command index. If it is not, it is reported as a command index error.
// -Enable. The eSDHC checks the CRC field in the response if it contains the CRC field. If an error is detected, it is reported as a command CRC error.
// -No response
// -Write (host to card)
(*MMC_REG.XFERTYP)= CMDTYP | DPSEL | CICEN | CCCEN | RSPTYP | DTDSEL;
// Command Argument
(*MMC_REG.CMDARG) = 0x00000000;
// set XFERTYP register as wCmd value to issue the command
(*MMC_REG.XFERTYP)= wCmd;
// wait_for_response
while(1)
{
temp0=(*MMC_REG.IRQSTAT) & 0x00000001;
temp1 = (*MMC_REG.CMDRSP0);
printf("%x\n",temp1);
printf("%x\n",(*MMC_REG.CMDRSP1));
printf("%x\n",(*MMC_REG.CMDRSP2));
printf("%x\n",(*MMC_REG.CMDRSP2));
if ( temp0 == 0x00000001) break;
}
// write 1 to clear IRQSTAT[CC] and all command error bits;
(*MMC_REG.IRQSTAT) = 0x00000001;
}
set CMDTYP, DPSEL, CICEN, CCCEN, RSTTYP, and DTDSEL according to the command index;
XFERTYP register bits
i can't understand these two steps.
How does a status register be able to send the command
write_reg(XFERTYP, wCmd); // set XFERTYP register as wCmd value to issue the command
for now the send command function has been implemented only to send the Zero command, just to verify correct operation