pic 18f2550 , micro sd and MikroC

Discussion in 'Embedded Systems and Microcontrollers' started by dxtr, Oct 14, 2012.

  1. dxtr

    Thread Starter New Member

    Oct 14, 2012
    1
    0
    Hey everyone
    i want to interface my micro sd with pic 18f2550 , i format it with FAT 16 and i used the code in the mmc help section
    here is my code :
    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.  int i;
    8.  
    9. void main() {
    10.   ADCON1 |= 0x0F;                  // Configure AN pins as digital
    11.   CMCON  |= 7;                     // Turn off comparators
    12.   trisa = 0x00;
    13.  
    14.   // Initialize SPI1 module
    15.   SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    16.     while (1)
    17.     {
    18.    i = Mmc_Fat_Init();
    19.  switch (i)
    20.    {
    21.       case 0 : porta = 0b00000001; break;
    22.       case 1 : porta = 0b00000010; break;
    23.       case 255 : porta = 0b00000011; break;
    24.       default: porta = 0xff; break;
    25.       }
    26.       delay_ms(50);
    27.      }
    28. }}
    29.  
    i always get 255
    i even tried with MMC_INIT() with no result
    can u please guide me to the problem ?
     
Loading...