+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Member level 3
    Points: 1,039, Level: 7

    Join Date
    Apr 2012
    Posts
    66
    Helped
    2 / 2
    Points
    1,039
    Level
    7

    pic 18f2550 , micro sd and MikroC

    Hey everyone
    i know this question has been posted several times , i read all the other topics but i didn't get the right answer yet
    well 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:
    // MMC module connections
    sbit Mmc_Chip_Select           at LATC0_bit;  // for writing to output pin always use latch (PIC18 family)
    sbit Mmc_Chip_Select_Direction at TRISC0_bit;
    // eof MMC module connections
    
     int i;
    
    void main() {
      ADCON1 |= 0x0F;                  // Configure AN pins as digital
      CMCON  |= 7;                     // Turn off comparators
      trisa = 0x00;
    
      // Initialize SPI1 module
      SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
        while (1)
        {
       i = Mmc_Fat_Init();
     switch (i)
       {
          case 0 : porta = 0b00000001; break;
          case 1 : porta = 0b00000010; break;
          case 255 : porta = 0b00000011; break;
          default: porta = 0xff; break;
          }
          delay_ms(50);
         }
    }}
    i even try with MMC_INIT() with no result
    can u please guide me to the problem ?

    •   AltAdvertisment

        
       

  2. #2
    Full Member level 1
    Points: 1,838, Level: 9
    Achievements:
    7 years registered
    ernpao's Avatar
    Join Date
    Sep 2010
    Posts
    100
    Helped
    27 / 27
    Points
    1,838
    Level
    9

    Re: pic 18f2550 , micro sd and MikroC

    hi, i think you haven't clearly stated what your exact problem is in your post, but i can't see anything wrong with your code. have you tried using a different sd card? we've tried interfacing an sd card to a pic18f4620 (using mikroc as well). at first we couldn't figure out what was wrong, the code was ok, it was only after trying a different sd card that we managed to make it work. (we actually used a microSD card attached to an adapter)



    •   AltAdvertisment

        
       

  3. #3
    Member level 3
    Points: 1,039, Level: 7

    Join Date
    Apr 2012
    Posts
    66
    Helped
    2 / 2
    Points
    1,039
    Level
    7

    Re: pic 18f2550 , micro sd and MikroC

    Quote Originally Posted by ernpao View Post
    hi, i think you haven't clearly stated what your exact problem is in your post
    yes sorry , well Mmc_Fat_Init() return 0 if card is detected , 1 if fat 16 boot not found and 255 if card is not found
    i always get 255
    why it can't find the card ?



    •   AltAdvertisment

        
       

  4. #4
    Member level 3
    Points: 1,039, Level: 7

    Join Date
    Apr 2012
    Posts
    66
    Helped
    2 / 2
    Points
    1,039
    Level
    7

    Re: pic 18f2550 , micro sd and MikroC

    also using isis , it doesn't work



  5. #5
    Administrator
    Points: 69,512, Level: 64
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    9,832
    Helped
    2355 / 2355
    Points
    69,512
    Level
    64
    Blog Entries
    4

    Re: pic 18f2550 , micro sd and MikroC

    Are you testing your design only using Proteus or both hardware and simulation?

    Have you level shifted the MMC/SD I/O to the appropriate 3.3v level, the interface is not 5v tolerate.

    Also note according to the MikroC documentation:

    unsigned char Mmc_Init();

    Initializes hardware SPI communication; The function returns 1 if MMC card is
    present and successfuly initialized, otherwise returns 0.
    Mmc_Init needs to be called before using other functions of this library.
    Also, while never sufficiently discussed in the documentation many of the FAT routines require the following resources:

    Code:
    // Variables for MMC routines
    unsigned char SectorData[512]; // Buffer for MMC sector reading/writing
    unsigned char data_for_registers[16];// buffer for CID and CSD registers

    Although, I never personally use MikroC libraries nor the MikroC compiler for that matter, if you upload your simulation file one of us could certainly take a look.


    BigDog
    The Edge... there is no honest way to explain it, because the only people who really know where it is are the ones who have gone over.
    -- Hunter S. Thompson



  6. #6
    Member level 3
    Points: 1,039, Level: 7

    Join Date
    Apr 2012
    Posts
    66
    Helped
    2 / 2
    Points
    1,039
    Level
    7

    Re: pic 18f2550 , micro sd and MikroC

    Quote Originally Posted by bigdogguru View Post
    Although, I never personally use MikroC libraries nor the MikroC compiler for that matter, if you upload your simulation file one of us could certainly take a look.
    BigDog
    thank you bigdog for your reply , here is my simulation with code in MikroC



    •   AltAdvertisment

        
       

  7. #7
    Administrator
    Points: 69,512, Level: 64
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    9,832
    Helped
    2355 / 2355
    Points
    69,512
    Level
    64
    Blog Entries
    4

    Re: pic 18f2550 , micro sd and MikroC

    The main issue appears to be, as ramoneb pointed out in his thread, the MISO and MOSI lines of the MMC are incorrectly switched.

    The clue is the logic contention (yellow indicator) on the MMC DO pin.

    Click image for larger version. 

Name:	dxtrMMC-logiccontention.jpg 
Views:	54 
Size:	279.1 KB 
ID:	81542

    Once the lines are switch, your code yields the expected results, no led lit indicating the card has been successfully detected.

    unsigned char Mmc_Init();
    0 - if MMC/SD card was detected and successfully initialized
    1 - otherwise
    Click image for larger version. 

Name:	dxtrMMC-SPIswitched.jpg 
Views:	47 
Size:	293.2 KB 
ID:	81543


    The labeling on the MMC is obviously in reference to the Master device rather than the Slave device.

    MISO - SDO - (M)DI

    MOSI - SDI - (M)DO
    BigDog
    The Edge... there is no honest way to explain it, because the only people who really know where it is are the ones who have gone over.
    -- Hunter S. Thompson



  8. #8
    Member level 3
    Points: 1,039, Level: 7

    Join Date
    Apr 2012
    Posts
    66
    Helped
    2 / 2
    Points
    1,039
    Level
    7

    Re: pic 18f2550 , micro sd and MikroC

    Quote Originally Posted by bigdogguru View Post
    The main issue appears to be, as ramoneb pointed out in his thread, the MISO and MOSI lines of the MMC are incorrectly switched.

    The clue is the logic contention (yellow indicator) on the MMC DO pin.

    Click image for larger version. 

Name:	dxtrMMC-logiccontention.jpg 
Views:	54 
Size:	279.1 KB 
ID:	81542

    Once the lines are switch, your code yields the expected results, no led lit indicating the card has been successfully detected.



    Click image for larger version. 

Name:	dxtrMMC-SPIswitched.jpg 
Views:	47 
Size:	293.2 KB 
ID:	81543


    The labeling on the MMC is obviously in reference to the Master device rather than the Slave device.



    BigDog
    problem solved
    thank you so much :)


    1 members found this post helpful.

--[[ ]]--