SDcard+LPC1114

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SDcard+LPC1114

253 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gigi095 on Thu Oct 04 21:26:13 MST 2012
Hi,

I tried to save data to SD card using SPI mode.
I did the following:

void SDcard_Init(void)
{
GPIOSetDir(3, 2, 1);
uint8_t i, response=0, retry=0 ;
/* Send CMD0 to SDcard for SPI mode */
while(response != 0x01){
for (i=0;i<10;i++)
{
SSP1_Send(0xFF);//80 clk cycles
}
response = SD_sendCommand(0, 0);//CMD0
retry++;
if(retry>0xFE)//255 attempts
{
printf("SD init fail..\n");//Give up
break;
}//time out
}
if(response==0x01)printf("SD init success..\n");
}

uint8_t SD_sendCommand(uint8_t cmd, unsigned long arg)
{
uint8_t response, retry=0;

SSP1_Send(cmd | 0x40); //send command, first two bits always '01'
SSP1_Send(arg>>24);
SSP1_Send(arg>>16);
SSP1_Send(arg>>8);
SSP1_Send(arg);
if (cmd == 8)
SSP1_Send(0x87);
else
SSP1_Send(0x95);

while((response = SSP1_Receive()) == 0xFF)//if receive garbage, try again
{
retry++;
if(retry> 0xfe) break; //time out error
}
//SSP1_Receive(); //extra 8 CLK
//SD_CS_DEASSERT;
return response; //return state
}

I couldn't even get the right response when initializing the SD card.
Can anyone provide your code for interfacing SD card with LPC1114?
I've seen some code for related FATFS stuff, but I don't understand that.
Can't we just treat SD card as a normal slave, and use the regular SPI protocol to communicate?
BTW, is it possible to add more RAM on my LPC1114?
Thanks in advance!
0 Kudos
0 Replies