• AVR Freaks

MMC Interfacing problem

Author
tom_g_robin
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2009/05/21 07:26:31
  • Location: 0
  • Status: offline
2009/05/21 08:02:44 (permalink)
0

MMC Interfacing problem


I am just trying to interface a multimedia card to my current project using PIC24FJ256GB110 using SPI interface. I just read that we have to send 0xFF 10 times to initialize MMC in SPI mode. But I don't know more about it. I have to write files to it as packets of 512bytes(mmc accepts packets with 512bytes size only). If there is anyone who know to interface it pease help me. Thank you.
#1

12 Replies Related Threads

    eddygo
    Super Member
    • Total Posts : 691
    • Reward points : 0
    • Joined: 2004/03/04 15:45:37
    • Location: Bucharest, ROMANIA
    • Status: offline
    RE: MMC Interfacing problem 2009/05/21 08:28:13 (permalink)
    0
    I've done with SD/SDHC... MMC are quite old. I think hardware INIT it's simmilar
     
    - CS_HI (deselected)
    - send > 74 clock pulses on SCK
    - CS_LO (selected)
    - send CMD0 with correct checksum and args 0 (0, 0x00, 0x00, 0x00, 0x00, 0x95)
    - expect 0x01 as reply <- important to expect, means you may read some sequence
     
    0xFF 0xFF 0xFF 0xFF 0x01 0xFF 0xFF
     
    card may reply little longer so wait known reply in a small loop
     
    Also note you must send some extra clocks after each command, some of them called NCR (check SD specs), so for CMD0 actually you shoud send
     
    0xFF 0x00  0x00 0x00 0x00 0x00 0x95
    NCR  CMD0 arg arg arg arg CRC
     
    and now wait for card reply.
     
    Hope helps,
    Edi
     
     

    ENEA, OSECK
    http://www.enea.com
    #2
    tom_g_robin
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2009/05/21 07:26:31
    • Location: 0
    • Status: offline
    RE: MMC Interfacing problem 2009/05/21 09:28:57 (permalink)
    0

    So first have to send 74 clocks with CS low, then send CMD0, but i don't know what is CMD0 do in the card. Anyway what are the other commands I have to use. Give me some detailed explanations, Thank you.
    #3
    eddygo
    Super Member
    • Total Posts : 691
    • Reward points : 0
    • Joined: 2004/03/04 15:45:37
    • Location: Bucharest, ROMANIA
    • Status: offline
    RE: MMC Interfacing problem 2009/05/21 10:50:22 (permalink)
    0
    Search this forum for SD, you'll find a lot of old good information. Also may check SD specs here:
    http://www.flashgenie.net/productmanualsdcardv2.2final.pdf

    CMD0 resets cards controller and is part of initialization process. Now init process differs from MMC/SD/SDHC/SDIO ... so either you study them all and make compatible funcs :) or pick one-two. 
    I choose to make all my (unfinished) library only for SD/SDHC.

    Also may check on google about SD memory card CMD0 keywords...
    http://sawdust.see-do.org/serial/serial.html
    http://elm-chan.org/docs/mmc/mmc_e.html

    Hope helps,
    Edi

    Note : There are file systems libs ready made for PIC (not free) you may choose.
    post edited by eddygo - 2009/05/21 10:51:57

    ENEA, OSECK
    http://www.enea.com
    #4
    asmallri
    Super Member
    • Total Posts : 1864
    • Reward points : 0
    • Joined: 2004/05/26 09:00:05
    • Location: Perth, Australia
    • Status: offline
    RE: MMC Interfacing problem 2009/05/21 19:32:15 (permalink)
    0
    Note : There are file systems libs ready made for PIC (not free) you may choose.


    I offer such file systems if interested (it will save you a lot of time).

    Regards, Andrew

    http://www.brushelectronics.com/index.php?page=software
    Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
    #5
    peertje888
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2009/04/19 21:02:33
    • Location: 0
    • Status: offline
    RE: MMC Interfacing problem 2009/05/25 19:50:39 (permalink)
    0
    Microchip has a beautiful application library which contains the source code for file handling on a SD Card. I got it to work, it's pretty good documented. You can download it here (2nd line):

    http://www.microchip.com/microchip.www.securesoftwarelist/whatsnewsoftware.aspx?lang=en#

    Good luck!

    #6
    costa
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2008/12/05 01:23:16
    • Location: 0
    • Status: offline
    RE: MMC Interfacing problem 2009/05/27 07:01:48 (permalink)
    0
    Hi all,
     
    I have been some time working successfully with Explorer 16 + PIC Tail SD Daugther + 2 GB SD Card + Microchip code as in AN1405b and associated source library
     
    Now, I moved to SDHC 4 GB card and it doesn't work.
     
    Initialisation code ...
     
        // According to spec cmd1 must be repeated until the card is fully initialized
        timeout = 0xFFF;
       
        do
        {
            response = SendMMCCmd(SEND_OP_COND,0x0);
            timeout--;
        }while(response.r1._byte != 0x00 && timeout != 0);

     
        // see if it failed
        if(timeout == 0) .........

     
    exits due timeout condition.
     
    Any clue ?
     
     


    #7
    eddygo
    Super Member
    • Total Posts : 691
    • Reward points : 0
    • Joined: 2004/03/04 15:45:37
    • Location: Bucharest, ROMANIA
    • Status: offline
    RE: MMC Interfacing problem 2009/05/27 10:19:51 (permalink)
    0
    Check newest SD specs. (>2.0). MMC init is compatible only with SD 1.x or lower.
    For SD 2.0 or higher (including high capacity SDHC) you'll need a different approach to proper init cards.
     
    Basically CMD0 (reset) was maintained. CMD1 was substituted by ACMD41 which is a combo command (CMD55+CMD41) doing the same thing.
     
    Before this ACMD41 you need to issue CMD8 (ask card if current voltage is supported) other ways SDHC will remain permanently in idle state. Both SD and SDHC will recognize CMD8, but older not -> so here you can select between MMC/SD 1.x and SD 2.x/SDHC.
     
    ACMD41 has a newly defined HCS bit in argument meaning "High Capacity Support". Basically you provide ACMD41 with HCS=1 and after init, read OCR register and check its (also newer) CCS bit which indicates if high capacity or not -> this way you will differentiate SD by SDHC.
     
    I never used MChip lib, but SDHC has a little different addressing scheme so I think you need to change'it for working with these cards.
     
    Hope helps,
    Edi

     


    ENEA, OSECK
    http://www.enea.com
    #8
    costa
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2008/12/05 01:23:16
    • Location: 0
    • Status: offline
    RE: MMC Interfacing problem 2009/05/28 08:16:41 (permalink)
    0
    Many thanks Edi for your quick reply.
     
    Yes, you are right. I have a read on several articles regarding SDHC and init is not compatible as you indicated. Addressing is different too due 32TB data space, but I have not studied the details yet.
     
    MChip made some changes in the library in order to support FAT32 but NOT SDHC
     
    So, I have to continue with SD or rewrite code for SDHC.
     
    73 de EA3CIU 
    #9
    bien_van_khat
    Starting Member
    • Total Posts : 45
    • Reward points : 0
    • Joined: 2006/05/11 20:41:17
    • Location: Vietnam
    • Status: offline
    RE: MMC Interfacing problem 2009/05/28 19:28:34 (permalink)
    0
    You should use FatFS instead of MDD, it has more powerful SD/MMC driver.

    I have tested on uSD, MMC, uSDHC, It faster than MDD but has a different set of APIs so not compatible with microchip libraries.

    FatFS comes with an example proj for PIC24. Microchip has a port for PIC32, but it has a silly bug with loop counting.

    P/S:
    I don't know why all my posts got this line at the end:
    "var dd = new YAHOO.util.DD('maindiv'); dd.setHandleElId('titlediv');"

    Is it a bug of the forum or my browser (FireFox 3.0)?
    post edited by bien_van_khat - 2009/05/28 19:32:15
    #10
    costa
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2008/12/05 01:23:16
    • Location: 0
    • Status: offline
    RE: MMC Interfacing problem 2009/06/05 04:07:15 (permalink)
    0
    ORIGINAL: bien_van_khat

    You should use FatFS instead of MDD, it has more powerful SD/MMC driver.

    I have tested on uSD, MMC, uSDHC, It faster than MDD but has a different set of APIs so not compatible with microchip libraries.

    FatFS comes with an example proj for PIC24. .....

     
    Example downloaded, code adapted to Explorer 16 board (PIC and ports) and working with SD and SDHC !!!
     
    Thanks to you all for your help. 
    #11
    eddygo
    Super Member
    • Total Posts : 691
    • Reward points : 0
    • Joined: 2004/03/04 15:45:37
    • Location: Bucharest, ROMANIA
    • Status: offline
    RE: MMC Interfacing problem 2009/06/05 07:40:28 (permalink)
    0
    ORIGINAL: costa
    Addressing is different too due 32TB data space, but I have not studied the details yet.

     
    My pleasure,
     
    You may be interested for a simple suggestion. My library it's designed for SD/SDHC compatible and actually, it's very easy. Except init(), read/write/erase are all the same but each function must contain some "address correction" like this:
     
    write_block(addr){
     
    if(!CCS) // card capacity status reported by OCR
        address_correction(addr); // only for SD, make addr = addr * 512
     
    }
     
    as long as you use 512 bytes block, however supported by all media I've seen, this works perfect.
    So all you need to do (presuming 512 bytes block in your library) is addr = addr/512;
     
    73' Edi
     

    ENEA, OSECK
    http://www.enea.com
    #12
    costa
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2008/12/05 01:23:16
    • Location: 0
    • Status: offline
    RE: MMC Interfacing problem 2009/06/05 10:40:53 (permalink)
    0
    ORIGINAL: eddygo

    You may be interested for a simple suggestion. My library it's designed for SD/SDHC compatible and actually, it's very easy. Except init(), read/write/erase are all the same but each function must contain some "address correction" like this:

    write_block(addr){

    if(!CCS) // card capacity status reported by OCR
      address_correction(addr); // only for SD, make addr = addr * 512

    }



    Thanks again

    I had a look to Chan's code, and in disk_write() and disk_read() operations, does:


    if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */


    ( CT_BLOCK bit in CardType is 1 for SDHC devices )

    So, the code should properly manage SD and SDHC.

    73s



    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5