Here is what I use to initialize my SD card
Code: Select all
void sd_init()
{
unsigned int m;
unsigned int test;
PUT32(CONTROL0,0x00100000);
PUT32(CONTROL1,0x070F0F27);
PUT32(CONTROL2,0x00000000);
do
{
m = GET32(CONTROL1);
test = m & 0x10000000;
}while(test!=0); //Waiting it to reset
PUT32(CONTROL0,0x00100000);
PUT32(CONTROL1,0x000F0F27);
PUT32(CONTROL2,0x00000000);
PUT32(IRPT_MASK,0xFFFFFFFF);
do
{
m = GET32(CONTROL1);
test = m & 0x00000002;
}while(test!=2); //Waiting for clock to be stable
//GO_IDLE_STATE
PUT32(ARG1,0x00000000);
PUT32(CMDTM,0x00000010);
//SD_SEND_IF_COND
PUT32(ARG1,0x000001AA);
PUT32(CMDTM,0x08030010);
wait();
unsigned int check;
//APP_CMD
PUT32(ARG1,0x00000000);
PUT32(CMDTM,0x37020000);
wait();
do
{
//SD_SEND_OP_COND (repeat until Powerup bit is set)
print_s("\n\rIN2 ");
PUT32(ARG1,0x40FF0000);
PUT32(CMDTM,0x29020000);
wait();
check = GET32(GET32(RESP3));
hexstrings(check);
check = check & 0x80000000;
hexstrings(check);
}while(check == 0);
//ALL_SEND_CID
PUT32(ARG1,0x00000000);
PUT32(CMDTM,0x02020000);
After doing this, following is what I get
After CMD0 ---- STATUS : 01FF0000 INTERRUPT : 00000041
After CMD8 ---- STATUS : 01FF0000 INTERRUPT : 00000043 RESP0 : 000001AA
After CMD55 --- STATUS : 01FF0000 INTERRUPT : 00000043 RESP0 : 00000120
After ACMD41-- STATUS : 01FF0000 INTERRUPT : 00000043 RESP3 : EA00000E RESP0 : FFFFFFFF
After CMD10 --- RESP0 : 00FF8000
Any idea what might be going wrong?
Thank you,
Brijen