CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Error reading from different sd card

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

Error reading from different sd card
PostPosted: Tue Jan 27, 2009 11:19 am     Reply with quote

Hi there, i´ve got a working MP3 player project with a 18F4620 that took a long to get it working, but now that its done i´ve several clones Very Happy and brought new sd cards, my problem is that i think that the new cards are faster than the old card i´ve used for debug. The old card is a kingston 1Gb the new card as Silicon Power 1Gb too, what could possibly be wrong?

My answer is if i can make the mmc_init routine to work with the new cards why dont i get response when i try to read from it??

here´s my initialization routine

Code:

int mmc_init(){
char p;
int i;
   SETUP_SPI(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4 | SPI_SS_DISABLED);
   SSPSTAT |= 0x40;                       
   SSPCON &= 0xEF;                       
   SS=1;
   for(i=0;i<10;i++){
           SPI_WRITE(0xFF);
   }
   SS=0;
   SPI_WRITE(0x40);
   for(p=4;p>0;p--){
      SPI_WRITE(0x00);
   }
   SPI_WRITE(0x95); 

   if(mmc_response(0x01)==1) return 1;     

   i = 0;
   while((i < 255) && (mmc_response(0x00)==1)){
           SPI_WRITE(0x41);
      for(p=4;p>0;p--){
              SPI_WRITE(0x00);
      }
           SPI_WRITE(0xFF);     
           i++;
   }
   if(i >= 254) return 1;                 
   SS=1;
   SPI_WRITE(0xFF);
   SS=0;
   SPI_WRITE(0x50); 
   SPI_WRITE(0x00);
   SPI_WRITE(0x00);
   SPI_WRITE(0x02);
   SPI_WRITE(0x00);
   SPI_WRITE(0xFF);
   if((mmc_response(0x00))==1) return 1;
   SS=1;
   return 0;
}


I´ve get it in the net while googling...

Any help would be appreciated. Very Happy
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jan 27, 2009 1:55 pm     Reply with quote

Just because the Kingston card is older does not mean its slower. One of the slowest cards I have tested is a brand new SANdisk 8GB card.

I see a couple of problems.

The initial flushing of the SPI bus is meant to be done BEFORE you select the SD card.

You are not waiting long enough for the card to become ready. it can take 500ms. Inside your "i" for loop insert a 2ms delay.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group