XC888 - Sd Card Initialization(doesnt work)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User322
Level 1
Level 1
Hi all.
Ive got some problems with initialization my sd card. Ive been siting for a couples of days trying to do something and there is no results. Can anyone help me whats wrong in my code:
char sdInit()
{
unsigned char i;

// 74 clocks z cs

P3_1 = 0x1; //cs high
for(i=0;i<10;i++) spiSendByte(0xFF);
P3_1 = 0x0;
return 1;
}

BYTE spiSendByte(BYTE dana)
{
SSC_TBL = dana; //send data by spi
while(SSC_CONH_O & 0x10); //wait when busy
return SSC_RBL; //read spi
}

//comand
BYTE sd_cmd(BYTE cmd, DWORD arg)
{
BYTE result, retry=0;
spiSendByte(cmd | 0x40);
spiSendByte((BYTE)(arg >> 24));
spiSendByte((BYTE)(arg >> 16));
spiSendByte((BYTE)(arg >> 8));
spiSendByte((BYTE)(arg >> 0));
if(cmd==CMD_GO_IDLE_STATE)
result = spiSendByte(0x95);
else
result = spiSendByte(0xff);
while(result == 0xff) {
if(++retry > 10) break; //lets give a chance to answer
result = spiSendByte(0xff);
}
spiSendByte(0xff); //adding some clks
return result;
}

BYTE sd_cmd_cs(BYTE cmd, DWORD arg)
{
BYTE result;
P3_1 = 0;
result = sd_cmd(cmd, arg);
P3_1 = 1;
return result;
}

When init spi baudrate = 40kb, after init 400kb. I am using Sandisk Ultra 15mb/s 8 gb card. I think my spi reading doesnt work well.... I am sending good frames, but the card keep giving the same answer 0xff. The schematic of the circuit is the same like sandisk`s documentation schematic.
Thank you for any help.
0 Likes
0 Replies