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 support@ccsinfo.com

mmc sd card interfacing........problem

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



Joined: 24 Jun 2011
Posts: 23
Location: INDIA

View user's profile Send private message Send e-mail

mmc sd card interfacing........problem
PostPosted: Wed Apr 03, 2013 12:18 pm     Reply with quote

hai friends,
i have a problem while reading the mmc card. i use a 512mb memory card and pic18f452 as the host controller. my problem is that when i read data from mmc it will not give the token(0xfe). but i can read the master boot sector correctly. but when i read the root directory it will give only 32byte of data for the first time and will give 0xff for the second or other time.i don't know why is this happened.but when i try to read the 32byte of data for the second time the read command's response given by the mmc is correct. but it would not give 0xfe. pls any one help me to find the error...........

main
Code:

void main()
{
int8 response;

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
SETUP_SPI (SPI_MASTER |  SPI_SS_DISABLED |SPI_H_TO_L| SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H);
   response = mmc_init();

   if(response == TRUE)
   {
   printf("mmc Intialization OK...\r\n");
   update_directory();
   mmc_file_open(2);
   }
   
}

my code for mmc.c is here

mmcsd.c

Code:

/*this the response type specification
*________________*
|0|1|1|1|1|1|1|1|
*----------------*
 ||||||||__0x01-->the mmcsd is in IDEAL STATE
 |||||||____0x02-->the mmcsd is in ERASE RESET
 ||||||______0x04-->the mmcsd is in ILLEGAL COMMAND
 |||||________0x08-->the mmcsd is in COMMAND CRC ERROR
 ||||__________0x10-->the mmcsd is in ERASE SEQUENCE ERROR
 |||____________0x20-->the mmcsd is in ADDRESS ERROR
 ||______________0x40-->the mmcsd is in PARAMETER ERROR
 |________________0x00-->the mmcsd is in SUCCESFULL CIONDITION
There are three types of Responses R1,R2,R3
*/
#include "mmc.h"


void mmc_select()
{
   output_low ( MMCSD_PIN_SS );
   spi_read ( 0xFF );
}

void mmc_deselect()
{
   output_high ( MMCSD_PIN_SS );
}

uint8_t get_response_r1(uint8_t res)
{
   //int8 response;
   uint32_t i;
   
   for ( i=0;i<=0xFF;i++ )
   {
      response=spi_read  ( 0xff );
      //printf ( "\r\nresponse_in_res:%x;i=%ld",response,i ) ;
      if ( response==res )
      {
         //printf ( "\r\n true" );
         return true;
      }

      //else if ( response!=0x01 ){printf ( "\r\n false" );return false1;}
      else if ( i==0xff&&response!=res )
      {
         //intf  ( "\r\n time_out" );
         return time_out;
      }
   }
}

uint8_t mmc_cmd(int8_t cmd,uint32_t address,uint8_t crc,uint8_t val_res)
{
   uint8_t i;
   mmc_select ( );
   //printf("cmd_address%lu\r\n",address);
   for ( i=0;i<=16;i++ )  spi_read  ( 0xFF );//for digetion purpose make a delay of 16 clock cycle
   cmd=cmd|0x40;
   spi_write ( cmd );//send the command byte
   spi_write ( MAKE8 ( address,3 ) ) ;
   spi_write ( MAKE8 ( address,2 ) ) ;
   spi_write ( MAKE8 ( address,1 ) ) ;
   spi_write ( MAKE8 ( address,0 ) ) ;
   spi_write ( crc );
   return get_response_r1 ( val_res );
}

uint8_t set_block_length(uint32_t size)
{
   //int8 response;
   mmc_select ( );
   response=mmc_cmd  ( SET_BLOCKLEN,size,0xFF,0x00 );
   mmc_deselect ( );
   if ( response==true )
   {
      block_size=size;
      //printf  ( "\r\nBlock length set...%ld",block_size )  ;
      return true;
   }

   else if ( response==false||response==time_out ){printf  ( "\r\n-->time_out.." );return time_out;}
}

uint8_t mmc_read_block(uint32_t address,char *buff)
{
   //int8 response;
   uint32_t i,y;
   //char buff[512];
   //printf("read address%lu\r\n",address);
   mmc_select ( );
   response=mmc_cmd  ( READ_SINGLE_BLOCK,address,0xFF,0x00 );
   //printf("read response %u\r\n",response);
   if ( response==true ) goto token;
   else if ( response!=true ) return false;

   token:
   for ( y=0;y<1024;y++ )
   {
      response=spi_read  ( 0xFF );
      //printf ( "\r\nsree :%2X",r1 );

      if ( response==0xFE ) goto read_data;     
   }    //mmc_read_data ( 0x00000000 );
   return false;
   
   read_data:
         for ( i=0;i<block_size;i++ )
         {
            buff[i]=spi_read  ( 0xFF );
            //printf ( "\r\ndata :%2X,i :%ld",buff[i],i ) ;
         }

         spi_read ( 0xff );
         spi_read ( 0xff );
         mmc_deselect ( );
         return true;
     
   }


uint8_t mmc_write_block(uint32_t address,char *buff)
{
uint32_t i;

mmc_select();
if(block_size != (uint32_t)512){
response = set_block_length((uint32_t)512);
if(response != true) return time_out;}

response = mmc_cmd(WRITE_BLOCK,address,0xFF,0x00);
if(response != true) return time_out;

spi_read(0xFF);
spi_write(start_data_token);
delay_ms(200);

for(i=0;i<block_size;i++)
{
printf("%c",buff[i]);
spi_write(buff[i]);
}
spi_read(0xff);
spi_read(0xff);

while(spi_read(0xff) != 0xFF)
spi_read(0xFF);

mmc_deselect();
spi_read(0xFF);
return true;
}

uint8_t cluster_address(uint16_t cluster_ptr,uint8_t Culser_ptr)
{
   uint32_t fat1_dup;
   uint32_t cluster_adr;
   char buff[2];

   if(culser_ptr == root_sector_start)
   {
     // printf("\r\ncluster : %lu\r\n\r\n\r\n",cluster_ptr);
      cluster_adr = (((uint32_t)cluster_ptr-(uint32_t)2)*MMC_MBR_INFO.bytes_per_cluster)+data_area_address;
      FILE_INFO.cluster_offset = cluster_adr;
      return true;
   }

   else if(culser_ptr == next_cluster)
   {
      fat1_dup = fat1_address+((uint16_t)2*cluster_ptr);
      //printf("\r\n\r\n\r\n\r\nfat ......%lu\r\n",fat1_dup);
      response = set_block_length((uint32_t) 2);
      if(response == true)goto read;
      else if(response != true)return time_out;

      read:
      response = mmc_read_block(fat1_dup,buff);
      if(response == true)goto next;
      else if(response != true)return time_out;

      next:
      cluster_ptr = make16(buff[1],buff[0]);
      if(cluster_ptr == 0xFFFF) return time_out;
      cluster_adr = (((uint32_t)cluster_ptr-(uint32_t)2)*MMC_MBR_INFO.bytes_per_cluster)+data_area_address;
      FILE_INFO.cluster_offset = cluster_adr;
      return true;
   }
}

uint8_t root_data(int32 address)
{
char buff[32];
DIR_UP.sector = root_directory_address;
   response = set_block_length((uint32_t)32);
   if(response != true) goto error;
   read_again:
   do{
        response = mmc_read_block(DIR_UP.sector,buff);
      if(response != true) goto error;
      DIR_UP.sector = DIR_UP.sector +(uint32_t)32;

      if(buff[0] == 0x00)
      {printf("\r\n the entry not used...\r\n");return true;}
      else if(buff[0] != 0x00 )
      {
         if(buff[0] == deleted) goto read_again;

         if(buff[11] == archive || buff[11] == directory)
         {
            show_updated_directory(buff,2);

            /////////////////////////////////////////////////////
         }

         else  goto read_again;
      }
   }while(buff != 0x00);

   return true;

   
   error:
   printf("Error");
}
void show_updated_directory(char *buff,uint8_t sub)
{
   if(sub == 1)
   {
   #if mmc_update_directory_updation
   printf("|_>>");
   #endif
   }
   sub = 0;
   #if mmc_update_directory_updation
   printf("\r\n");
   #endif
   for ( DIR_UP.i=0;DIR_UP.i<8;DIR_UP.i++)
   {
   #if mmc_update_directory_updation
   printf ( "%c",buff[DIR_UP.i] ) ;
   #endif
   }
   #if mmc_update_directory_updation
   printf ( " . " ) ;
   #endif
   for ( DIR_UP.i=8;DIR_UP.i<11;DIR_UP.i++)
   {
   #if mmc_update_directory_updation
   printf ( "%c",buff[DIR_UP.i] ) ;
   #endif
      //if ( buff[i+offset]=="\0" ) goto start;
   }

   DIR_UP.Attributes = buff[11];
   
   /*
   Date field
   A 16-bit field that is a date relative to 01/01/1980:-
   Bits 15:9 Count of years from 1980,valid range 0 – 127  (=1980–2107 ) .
   Bits 8:5 Month of year,valid range 1–12  ( 1=January)
   Bits 4:0 Day of month,valid range 1-31
   Time Format.
   A 16-bit field with a valid range from Midnight 00:00:00 to 23:59:58:-
   Bits 15:11 Hours,valid range 0 – 23
   Bits 10:5 Minutes,valid range 0 – 59
   Bits 4:0 2-second count,valid range 0–29  (=0 – 58 seconds)
   */
   DIR_UP.time=make16 ( buff[23],buff[22] ) ;
   DIR_UP.hour=DIR_UP.time>>11;
   DIR_UP.mint= ( DIR_UP.time&0x07E0 )>>5;
   DIR_UP.sec=DIR_UP.time&0x001F;
   DIR_UP.date=make16 ( buff[25],buff[24] ) ;
   DIR_UP.year= ( DIR_UP.date>>9 )+1980;
   DIR_UP.month= ( DIR_UP.date&0x01E0 )>>5;
   DIR_UP.day=DIR_UP.date&0x001F;
   if ( DIR_UP.hour>12 ){DIR_UP.hour=DIR_UP.hour-12;DIR_UP.ampm=0;}
   else DIR_UP.ampm=1;
   DIR_UP.start_cluster=make16 ( buff[27],buff[26] ) ;
   DIR_UP.file_size=make32 ( buff[31],buff[30],buff[29],buff[28] ) ;
   
   #if mmc_update_directory_updation
   printf("          %X",DIR_UP.Attributes);
   printf("              %02u/%02u/%02u / ",DIR_UP.hour,DIR_UP.mint,DIR_UP.sec);
   if(DIR_UP.ampm == 1)printf("AM");
   if(DIR_UP.ampm == 0)printf("PM");
   printf("      %02u/%02u/%lu",DIR_UP.day,DIR_UP.month,DIR_UP.year);
   printf("          %lu",DIR_UP.start_cluster);
   printf("          %3.4f MB\r\n",DIR_UP.file_size/(float)1024000);
   #endif
}

int8 update_directory()
{
   char buff[32];
   DIR_UP.sector = root_directory_address;
   response = set_block_length((uint32_t)32);
   if(response != true) goto error;
   #if mmc_update_directory_updation
   printf("\r\nName:     File ext:     Attributes:     Time:              Date:           start cluster:     File size\r\n");
   #endif
   read_again:
   do
   {
      response = mmc_read_block(DIR_UP.sector,buff);
      if(response != true) goto error;
      DIR_UP.sector = DIR_UP.sector +(uint32_t)32;

       if(buff[0] == 0x00)
      {printf("\r\n the entry not used...\r\n");return true;}
      else if(buff[0] != 0x00 )
      {
         if(buff[0] == deleted) goto read_again;
           
         if(buff[11] == archive || buff[11] == directory || buff[11] == 0x01)
         {
            show_updated_directory(buff,2);

            if(buff[11] == directory)
            {
               DIR_UP.sector_plus = data_area_address + (((uint32_t)DIR_UP.start_cluster-(uint32_t)2)*MMC_MBR_INFO.bytes_per_cluster);

               do
               {
                  read_plus:
                  response = mmc_read_block(DIR_UP.sector_plus,buff);
                  if(response != true)goto error;
                  DIR_UP.sector_plus = DIR_UP.sector_plus + (uint32_t)32;
                  //printf("\r\n\r\\r\nbuff :%X\r\n\r\n",buff[0]);
                  if(buff[0] == 0x00) goto read_again;
                  /*{printf("\r\n the entry not used...\r\n");return true;}*/
                  else if(buff[0] != 0x00 )
                  {
                     if(buff[0] ==deleted) goto read_plus;

                     if(buff[11] == archive || buff[11] == directory)
                     {
                        show_updated_directory(buff,1);
                     }

                     else goto read_plus;
                  }
               }while(buff!= 0x00);

               //buff = 0xFF;
               //printf("\r\n\r\\r\nbuff :%X\r\n\r\n",buff[0]);
               goto read_again;
            }

            ///////////////////////////////////////////////////////
         }

         else  goto read_again;
      }
   }while(buff != 0x00);

   return true;

   error:
   printf ( "\r\n*-->error..." ) ;
   return time_out;
}

uint8_t mmc_init()
{
   char buff[512];
   uint8_t i;
   //int8 response;
   delay_ms ( 200) ;
   delay_ms ( 10 );
   mmc_deselect ( );
   delay_ms ( 10 );
   for ( i=0;i<10;i++ )  spi_read  ( 0xFF );//to make 80clock pulse for digetion purpose
   delay_ms ( 10 );
   #if mmc_init_updation
   printf ( "\r\n*-->intialization..." );
   #endif

   cmd0:
   i=0;
   for ( i=0;i<=16;i++ )
   {
      if (i==16 ) return false;
      //mmc_select ( );
      response=mmc_cmd  ( GO_IDLE_STATE,0x00000000,0x95,0x01 );
      mmc_deselect ( );
      if ( response==false ) goto cmd0;
      else if ( response==true ) goto cmd1;
      else if ( response==time_out ) goto cmd0;
   }

   cmd1:
   //mmc_select ( );
   response=mmc_cmd  ( SEND_OP_COND,0x00000000,0xF9,0x00 );
   mmc_deselect ( );
   if ( response==false ) goto cmd1;
   else if ( response==true ) goto cmd2;
   else if ( response==time_out ) goto cmd1;

   cmd2:
   //mmc_select ( );
   /*response=mmc_cmd  ( APP_CMD,0x00000000,0xE5,0x04 );
   mmc_deselect ( );
   if ( response==false ) goto cmd0;

   else if ( response==true )
   {
   #if mmc_init_updation
      printf ( "\r\n*-->The given card type is MMC...." );
   #endif   
      goto cmd3;
   }

   else if ( response==time_out ) goto cmd0;*/

   cmd3:
   //to set the block length
   response=set_block_length  ( (uint32_t ) 512 ) ;
   mmc_deselect ( );

   if ( response==true )
   {
   #if mmc_init_updation
      printf ( "\r\n*-->Ok" );
   #endif
      goto cmd4;
   }

   else if ( response==false||response==time_out ) return time_out;

   cmd4:
   //mmc_read_ocr  ( ) ;
   response=mmc_read_block  ( 0x00000000,buff );
   if ( response==true ) goto Boot;
   else if ( response!=true ) goto error;

   boot:
   #if mmc_init_updation
   printf("\r\n*-->jump                   : ");
   #endif
   for(i=0;i<3;i++)
   {
      MMC_MBR_INFO.jump[i]=buff[i];
      #if mmc_init_updation
      printf("%X"MMC_MBR_INFO.jump[i]);
      #endif
   }
   #if mmc_init_updation
   printf("\r\n*-->Name                   : ");
   #endif
   for(i=3;i<11;i++)
   {
      MMC_MBR_INFO.ome[i]=buff[i];
      #if mmc_init_updation
      printf("%c"MMC_MBR_INFO.ome[i]);
      #endif
   }

   MMC_MBR_INFO.bytes_per_sector = make16(buff[12],buff[11]);
   MMC_MBR_INFO.sectors_per_clustor = buff[13];
   MMC_MBR_INFO.reserved_sectors = make16(buff[15],buff[14]);
   MMC_MBR_INFO.fats = buff[16];
   MMC_MBR_INFO.root_entries = make16(buff[18],buff[17]);
   MMC_MBR_INFO.small_sectors = make16(buff[20],buff[19]);
   MMC_MBR_INFO.media_descriptor = buff[21];
   MMC_MBR_INFO.sectors_per_fat = make16(buff[23],buff[22]);
   MMC_MBR_INFO.sectors_per_track = make16(buff[25],buff[24]);
   MMC_MBR_INFO.heads = make16(buff[27],buff[26]);
   MMC_MBR_INFO.hidden_sectors = make32(buff[31],buff[30],buff[29],buff[28]);
   MMC_MBR_INFO.large_sectors = make32(buff[35],buff[34],buff[33],buff[32]);
   #if mmc_init_updation
   printf("\r\n*-->Bytes per sector       : %lu",MMC_MBR_INFO.bytes_per_sector);
   printf("\r\n*-->sectors per clustor    : %u",MMC_MBR_INFO.sectors_per_clustor);
   printf("\r\n*-->Reserved sectors       : %lu",MMC_MBR_INFO.reserved_sectors);
   printf("\r\n*-->No of fats             : %u",MMC_MBR_INFO.fats);
   printf("\r\n*-->Root entries           : %lu",MMC_MBR_INFO.root_entries);
   printf("\r\n*-->small sectors          : %lu",MMC_MBR_INFO.small_sectors);
   printf("\r\n*-->media                  : %2X",MMC_MBR_INFO.media_descriptor);
   printf("\r\n*-->no of fat sectors      : %lu",MMC_MBR_INFO.sectors_per_fat);
   printf("\r\n*-->sectors per track      : %lu",MMC_MBR_INFO.sectors_per_track);
   printf("\r\n*-->heads                  : %lu",MMC_MBR_INFO.heads);
   printf("\r\n*-->hidden sectors         : %lu",MMC_MBR_INFO.hidden_sectors);
   printf("\r\n*-->Large sectors          : %lu",MMC_MBR_INFO.large_sectors);
   #endif
   // calculation
   MMC_MBR_INFO.bytes_per_cluster = (uint32_t)MMC_MBR_INFO.bytes_per_sector * (uint32_t)MMC_MBR_INFO.sectors_per_clustor;
   root_directory_address = (uint32_t)(MMC_MBR_INFO.sectors_per_fat*2+MMC_MBR_INFO.reserved_sectors)*MMC_MBR_INFO.bytes_per_sector;
   data_area_address = (uint32_t) (root_directory_address+(MMC_MBR_INFO.root_entries*32));
   fat1_address = (uint32_t)(MMC_MBR_INFO.reserved_sectors*MMC_MBR_INFO.bytes_per_sector);
   fat2_address = (fat1_address + (uint32_t)(MMC_MBR_INFO.sectors_per_fat * (uint32_t)MMC_MBR_INFO.bytes_per_sector));
   total_size = ((MMC_MBR_INFO.large_sectors + MMC_MBR_INFO.small_sectors)* (uint32_t)MMC_MBR_INFO.bytes_per_sector)/(uint32_t)1000000;
   
   #if mmc_init_updation
   printf("\r\n*-->Bytes per cluster      : %lu",MMC_MBR_INFO.bytes_per_cluster);
   printf("\r\n*-->Root directory address : %lu",root_directory_address);
   printf("\r\n*-->data area address      : %lu",data_area_address);
   printf("\r\n*-->Fat 1 address          : %lu",fat1_address);
   printf("\r\n*-->Fat 2 address          : %lu",fat2_address);
   printf("\r\n*-->Total Disk size        : %4.2f MB\r\n",total_size);
   #endif
   
   return true;

   error:
   return time_out;
}

uint8_t mmc_file_open(uint16_t clu_adr)
{
   uint16_t i,y,j,k;
   uint16_t cluster_ptr;
   char buff[32];
   FILE_INFO.byte_read = 0;
   y = 0;
   cluster_ptr = clu_adr;

   read_again:
   j=0;

   if(y > 0)
   {
      //printf("\r\n\r\n\r\n\r\n\r\n kayary....cluster ptr %lu\r\n\r\n\r\n\r\n",cluster_ptr);
      response =cluster_address(cluster_ptr,next_cluster);
      cluster_ptr++;
      if(response != true) goto error;
   }

   else if(y == 0)
   {
      response =cluster_address(cluster_ptr,root_sector_start);
      if(response != true) goto error;
      //cluster_ptr++;
      y++;
   }

   //printf("\r\ncluster : %lu\r\n\r\n\r\n",cluster_ptr);
   //output_high(PIN_B0);
   //delay_ms(1000);
   //output_low(PIN_B0);
   for(j=0;j<MMC_MBR_INFO.sectors_per_clustor;j++)
   {
      k=0;
      for(k=0;k<16;k++)
      {
         //buff = 0;

         if(block_size != (uint32_t) 32)
         {
            response = set_block_length((uint32_t)32);
            if ( response!=true ) goto error;
         }

        // printf("\r\n\r\nFILE_INFO.cluster_offset :%lu\r\n\r\n\r\n",FILE_INFO.cluster_offset);
         response = mmc_read_block(FILE_INFO.cluster_offset,buff);
        // printf("\r\n%d\r\n",response);
         if(response !=true || (buff[0] == 0x00 && buff[1]==0)) goto error;
         i=0;
         for(i=0;i<32;i++)
         {
            printf("%c",buff[i]);
            FILE_INFO.byte_read++;
         }

         //FILE_INFO.cluster_offset++;
         FILE_INFO.cluster_offset = FILE_INFO.cluster_offset + 32;
      }
   }

   goto read_again;

   error:
   printf("\r\n*-->Byte_read : %lu,buff0 %X,j:%lu",FILE_INFO.byte_read,buff[0],j);
   return time_out;
}
 :roll:
Code:
Rolling Eyes Rolling Eyes
Code:
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 04, 2013 12:33 am     Reply with quote

Code:
SETUP_SPI (SPI_MASTER |  SPI_SS_DISABLED |SPI_H_TO_L| SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H);
This is an invalid SPI setup, the SPI_SS_DISABLED parameter should only be used on a slave device, on a master it creates an invalid set of parameters with unknown behaviour.

SPI settings are easier to read when you use the following defines:
Code:
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
The correct setup then becomes:
Code:
SETUP_SPI (SPI_MASTER | SPI_CLK_DIV_16 | SPI_MODE_3);


Did you write this driver yourself? If yes, why not use an existing library?
If you used an existing driver, then please post a link.

For completeness, post your compiler version number.[/code]
sreejith.s.s



Joined: 24 Jun 2011
Posts: 23
Location: INDIA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 04, 2013 12:54 am     Reply with quote

Thank you very much ckielstra for your kind reply. I wrote this code myself...... but there is some help from the ccs c fat16 library. I wrote this code myself without using any library.........because I need to study.....what's actually happened in mmc/sd operation. I use the ccs c PCW compiler for coding, and pic 18f452 as microcontroller. In my program I can read all the masterboot data correctly without any problem. After this if any read operation will be happen the data token I get from the mmc is always 0xff instead of 0xfe. I don't know why this happened.............but in Proteus all the function is going well. I call read and write and everything is going ok..........pls help me............
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Thu Apr 04, 2013 1:26 am     Reply with quote

How are you doing the voltage translation between the card and the 452?.
This is the commonest problem.
Proteus does not correctly emulate the input voltage behaviour of the PIC...

Best Wishes
sreejith.s.s



Joined: 24 Jun 2011
Posts: 23
Location: INDIA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 04, 2013 1:34 am     Reply with quote

Thank you Mr. Ttelmah for your kind reply. I use a voltage divider circuit which is given from the mikro electronika site...........for pic to mmc interface. I can read the block for the first time but when i read the mmc second time it will give the data token as 0xff. Pls help me.............in my program first i read the master boot sector, it will read all correct but after that function i can't read any data from mmc. The data token given is 0xff insted of 0xfe. Pls help me.
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Thu Apr 04, 2013 1:57 am     Reply with quote

Voltage divider will give the 'down' conversion, but not the conversion back.
With the voltage divider approach, you can _only_ use software SPI, and your PIC inputs must be chosen to be ones with TTL compatible input buffers. Hardware SPI, just will not work reliably. On your chip, the SPI inputs require a signal that goes up to 3.5v. A 3.3v SD card cannot do this. If you run the PIC at 4.2v, then you may _just_ get it to work. The input requirement then drops to 2.94v.

This is the commonest mistake in interfacing to SD cards. Unfortunately there are several hundred sites on the web, that publish divider based circuits that don't work.

Depending on luck, and the PIC, you will get occasional partial data transfers, just enough to make you think the hardware is working. It doesn't.

Proteus gets it wrong, because the pin has two voltage levels it requires. 2.4v for normal operation, and the higher voltage for SPI operation. Proteus uses the lower voltage for both....

You need to fix your hardware I'm afraid.....

Best Wishes
sreejith.s.s



Joined: 24 Jun 2011
Posts: 23
Location: INDIA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 04, 2013 2:23 am     Reply with quote

Thanks Ttelmah.......for your reply. Before i use voltage divider i use transistor TTL circuit but it will not give me any result. So why i am using this voltage divider. I lived in Kerala, India but here is no buffer ic's that we want to buy.......so i choose these options to interface my mmc ! Is there any other option to interface the mmc to pic without ic's ? Pls help me ! Rolling Eyes
sreejith.s.s



Joined: 24 Jun 2011
Posts: 23
Location: INDIA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 04, 2013 2:40 am     Reply with quote

from the pic 18f452 datasheet, the operating voltage range is (2.0V to 5.5V).
sreejith.s.s



Joined: 24 Jun 2011
Posts: 23
Location: INDIA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 04, 2013 2:43 am     Reply with quote

http://www.google.co.in/imgres?um=1&hl=en&sa=X&rlz=1C2_____enIN518&biw=1304&bih=683&tbm=isch&tbnid=Y7UxlH5izt7jnM:&imgrefurl=http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/mmc_library.htm&docid=7mypxn0dAcQ6cM&imgurl=http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/img/schemes/scheme_mmc.gif&w=600&h=312&ei=uDxdUeK5L-iNiAfFpID4AQ&zoom=1&ved=1t:3588,r:0,s:0,i:79&iact=rc&dur=662&page=1&tbnh=162&tbnw=312&start=0&ndsp=14&tx=212&ty=78


the above is the circuit i use to interface the mmc with pic...........
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Thu Apr 04, 2013 2:53 am     Reply with quote

The operating voltage range of the 18F452, is 4.2v to 5.5v. Only the LF version can go down to 2v, and then only at 4MHz. Look at the voltage-frequency figure in the data sheet.

Best Wishes
sreejith.s.s



Joined: 24 Jun 2011
Posts: 23
Location: INDIA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 04, 2013 3:35 am     Reply with quote

Thanks.......
sreejith.s.s



Joined: 24 Jun 2011
Posts: 23
Location: INDIA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 04, 2013 5:55 am     Reply with quote

i give the 5v input to pic using ttl converter but still given the same result....?.......pls help me.
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Thu Apr 04, 2013 7:17 am     Reply with quote

OK. So now you have what should be working hardware, prove it by using the mmcsd library. _Once_ you have this working, then use your code.
All debugging is down to reducing the number of locations with potential problems, till you get things going, and in doing so finding where the fault is. Work from the 'known' to the 'unknown'. So start with a working library, _then_ progress to trying your code.

Best Wishes
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