sd card interfacing with pic18f4520

Discussion in 'Embedded Systems and Microcontrollers' started by nirav jasani, Jan 13, 2014.

  1. nirav jasani

    Thread Starter New Member

    Jul 17, 2013
    6
    0
    hello all,

    i am trying to connect micro sd card with pic18f4520 using mikroC.
    but i have ready module of micro sd card socket with required push-pull and pulled down resisters.but i am not able to detect sd card.

    i have attached my code below please give me solution as soon as fast.
    thanks

    Code ( (Unknown Language)):
    1.  
    2. // MMC module connections
    3. sbit Mmc_Chip_Select           at LATC0_bit;  // for writing to output pin always use latch (PIC18 family)
    4. sbit Mmc_Chip_Select_Direction at TRISC0_bit;
    5. // eof MMC module connections
    6.  
    7. const LINE_LEN = 43;
    8. char err_txt[20]       = "FAT16 not found";
    9. char file_contents[LINE_LEN] = "XX MMC/SD FAT16 library by Anton Rieckertn";
    10. char           filename[14] = "MIKRO00x.TXT";          // File names
    11. unsigned short loop, loop2;
    12. unsigned long  i, size;
    13. char           Buffer[512];
    14.  
    15.  
    16. void M_Create_New_File()
    17. {
    18.   filename[7] = 'A';
    19.   Mmc_Fat_Set_File_Date(2010, 4, 19, 9, 0, 0); // Set file date & time info
    20.   Mmc_Fat_Assign(&filename, 0xA0);          // Find existing file or create a new one
    21.   Mmc_Fat_Rewrite();                        // To clear file and start with new data
    22.   for(loop = 1; loop <= 99; loop++)
    23.   {
    24.     UART1_Write('.');
    25.     file_contents[0] = loop / 10 + 48;
    26.     file_contents[1] = loop % 10 + 48;
    27.     Mmc_Fat_Write(file_contents, LINE_LEN-1);   // write data to the assigned file
    28.   }
    29. }
    30.  
    31. void main() {
    32.   #define COMPLETE_EXAMPLE         // comment this line to make simpler/smaller example
    33.   ADCON1 |= 0x0F;                  // Configure AN pins as digital
    34.   CMCON  |= 7;                     // Turn off comparators
    35.  
    36.   // Initialize UART1 module
    37.  // UART1_Init(19200);
    38.   Delay_ms(10);
    39.  
    40.  // UART1_Write_Line("PIC-Started"); // PIC present report
    41.  
    42.   // Initialize SPI1 module
    43.   SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    44.  
    45.   // use fat16 quick format instead of init routine if a formatting is needed
    46.   if (Mmc_Fat_Init() == 0) {
    47.     // reinitialize spi at higher speed
    48.     SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    49.     //--- Test start
    50.     UART1_Write_Line("Test Start.");
    51.     //--- Test routines. Uncomment them one-by-one to test certain features
    52.     M_Create_New_File();
    53. }
    54.  
    55.      
     
    Last edited by a moderator: Jan 14, 2014
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Does your PIC not require any configuration bits?

    Does your code not require any included files?

    Don't you need to initialize the SDI interface?

    Does you code show any signs of working at all?
     
Loading...