Problems with SD Card Interfacing
Tue Sep 02 2008, 02:07 am
you can set the clock divisor for baudrate generator to Fosc/8 ( 010) in SPCON register of ED2.
more information check page 65 of datasheet.
more information check page 65 of datasheet.
Fri Sep 05 2008, 05:37 pm
i m sorry,Ajay..but i m still very confuse how to calculate the SPI clock frequency
SPI clock frequency = baud rate?
according to the data sheet,
baudrate = Fclk periph / baud rate divisor
Fclk periph = Fosc/[4*(255-CKRL)]
do we need to set the CKRL?
SPI clock frequency = baud rate?
according to the data sheet,
baudrate = Fclk periph / baud rate divisor
Fclk periph = Fosc/[4*(255-CKRL)]
do we need to set the CKRL?
[ Edited Fri Sep 05 2008, 05:39 pm ]
Fri Sep 05 2008, 05:50 pm
i couldnt initialize my sdcard
is my sd card initialization steps correct?
is my sd card initialization steps correct?
unsigned char InitSD() { int i; unsigned char status; SPI_set_speed (128); //Set SPI speed to below 400khz CS= SD_OFF; //assert sd card for(i=0; i<10; i++) //delay minimum 74clock; 10 X 8byte = 80clock cycle { SPI_transmit(0xFF); } CS = SD_ON; //deassert sd card for(i=0; i<3; i++) //delay minimum 16 clock; 3x8 =24 clock { SPI_transmit(0xFF); } // Wait for the SD Card to go into IDLE state for(i=0;i<=50;i++) { status = SD_WriteCommand(CMD0_GO_IDLE_STATE); if(status == 0x01) break; if(i==50) return 1; } // Wait for SD Card to initialize for(i=0;i<=50;i++) { status = SD_WriteCommand(CMD1_SEND_OP_COND); if((status & R1_IN_IDLE_STATE)==0) //card initialization is completed and wait for next command break; if(i==50) return 2; } for(i=0;i<=50;i++) // Send the ACMD41 command to initialize SD Card mode (not supported by MMC cards) { status = SD_WriteCommand(ACMD41_SD_SEND_OP_COND); if((status & R1_IN_IDLE_STATE)==0) // Might return 0x04 for Invalid Command if MMC card is connected break; if(i==50) return 3; } status = SD_WriteCommand(CMD55_APP_CMD); // Send CMD55, required to precede all "application specific" commands // Do not check response here SPI_set_speed(2); CS = SD_OFF; return 0; }
[ Edited Sat Sep 06 2008, 01:33 am ]
Sat Sep 06 2008, 01:59 am
most of your initialization routine is correct but few changes needed.
1. Make a routine for sending SPI byte
2. Make a routine for sending command to MMC
now see how to send command to MMC..
MMC command contains command byte + parameter bytes (hope you are taking care of it)
now after command is sent to mmc, you have to wait for response from mmc.
if you have a function to send SPI byte then..
response wait will be like this..
so after you send command to MMC..
but when sending CMD1 to MMC, you have to do the way you have done already..
and please go through the documents i provided for MMC initialization. You only need to send CMD0 and CMD1 to mmc for full initialization.
no need to send CMD41 and CMD55.
1. Make a routine for sending SPI byte
2. Make a routine for sending command to MMC
now see how to send command to MMC..
MMC command contains command byte + parameter bytes (hope you are taking care of it)
now after command is sent to mmc, you have to wait for response from mmc.
if you have a function to send SPI byte then..
response wait will be like this..
unsigned char MMCWait(){ int timeout = 1000; unsigned char read; while( (read == 0xff) && (timeout--) ) read = spiSend(0xff); return read; }
so after you send command to MMC..
SD_WriteCommand(CMD0_GO_IDLE_STATE); if(MMCWait() != 0x01) //response of Idle state return 0; //return failure status.. or whatever there in your program.
but when sending CMD1 to MMC, you have to do the way you have done already..
and please go through the documents i provided for MMC initialization. You only need to send CMD0 and CMD1 to mmc for full initialization.
no need to send CMD41 and CMD55.
Sat Sep 06 2008, 01:00 pm
Does anyone know what does this error mean?
warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
Sun Sep 07 2008, 10:55 pm
l am trying to initialize SD card in SPI mode. what the difference between CMD1 and ACMD41? why don't need to send ACMD41 for SD card initialization?
Mon Sep 08 2008, 12:19 am
well i have provided document for SD/MMC card initialization. Please check it I have worked on MMC myself so least thing required for this init is CMD0 and CMD1.
Powered by e107 Forum System