I’ve been confused by my SD design for a few weeks.I try to write a single block to SD with CPU.I follow the procedures in the SD card controller user’s Guide.However, After I send CMD24(WRITE_BLOCK),I use CMD13 to check the card state, it remains to be tran,which is supposed to be rcv.Thus the timeout occurs.Any suggesions will be well appreciated .My code are as follow:
int MMCSD_WRITE_BLOCK()
{
int i=0,j=0,cnt=0;
int RW_TIMEOUT=0xFFFF;
//SELECT THE CARD ACCORDING TO THE RCA.//CMD7//R1b
Mmcsd0regs->MMCARGHL=RCA<<16;
Mmcsd0regs->MMCCMD=0x307;
while(!(Mmcsd0regs->MMCST0>>2));
//Check the card state,and it turns to be stby(Currentstate=3)
Currentstate=((Mmcsd0regs->MMCRSP67)>>9) & 0xF;
********
CMD9 and CMD16 are abandoned because it has no need for my situation
*********
//CMD9,SEND CSD
//hllc->regs->MMCARGHL=0x0;
//hllc->regs->MMCCMD=0x409;
//CMD16,SET BLOCKLEN
//hllc->regs->MMCARGHL=0x200;
//hllc->regs->MMCCMD=0x210;
//FIFO setup
Mmcsd0regs->MMCFIFOCTL =0x1;//RESET FIFO
Task_delay(1000);
Mmcsd0regs->MMCFIFOCTL =0x2;//FIFO direction:Write
// Tell the controller how much to expect
Mmcsd0regs->MMCNBLK=0x1;
for (j = 0; j < 8; j++)
{
Mmcsd0regs->MMCDXR = 0xFFFFFFFF;
}
//CMD24,Write_BLock and set the trigger//R1
Mmcsd0regs->MMCARGHL=0x0;//data address
Mmcsd0regs->MMCCMD=0x1AA18;
while(!(Mmcsd0regs->MMCST0>>2));
//Check the card state,and it turns to be tran((Currentstate=4))
Currentstate=((Mmcsd0regs->MMCRSP67)>>9) & 0xF;
//SEND_STATUS//CMD13//R1
Mmcsd0regs->MMCARGHL=RCA<<16;
Mmcsd0regs->MMCCMD=0x20D;
while(!(Mmcsd0regs->MMCST0>>2));
//Check the card state,and it retain to be tran which supposed to be rcv(Currentstate=4)
Currentstate=((Mmcsd0regs->MMCRSP67)>>9) & 0xF;
for(i=0;i<16;i++)
{
while(!((Mmcsd0regs->MMCST0>>9) & 0x1))
{
if(cnt++>RW_TIMEOUT)
{
printf("write timeout ERROR\n\n");
return 0;
}
}
for (j = 0; j < 8; j++)
{
Mmcsd0regs->MMCDXR = 0xFFFFFFFF;
}
}
cnt =0;
while(!((Mmcsd0regs->MMCST0) & 0x1))
{
if(cnt++>RW_TIMEOUT)
{
printf("tranmit timeout ERROR\n\n");
return 0;
}
}
return 1;
}
What do i miss? In addtion ,I not sure about the MMCARGHL in the CMD24.Does the data address means the offset address in the SD card.That is if I set it to be 0,it means to write to the SD card from the very beginning while if I set it to be 0xFF,it means to write to the card from the offset address of 0xFF?
regards,
Stanley