regarding Interfacing of the MMc card

Discussion in 'Embedded Systems and Microcontrollers' started by kovendan_23, Jul 23, 2008.

  1. kovendan_23

    kovendan_23 Thread Starter New Member

    Joined:
    Jul 18, 2008
    Messages:
    4
    Sir :
    i am interfacing An MMC card with my AT89C51snd2c , i send upto four commandsc to my MMC card , but i didnt get response from the MMC card i.e MMint register is not set and crc and resp bit .

    /*********************************************************************************************************/
    /* Field Programmable Announcement System */
    /* Main.c */
    /*********************************************************************************************************/
    #include<at8xc51snd2.h>
    sbit LED1 = P2^5;
    sbit LED2 = P2^6;
    void wrtram(char *);
    void rdram(char *);
    void delay(long int); /*delay routine - (parameter-delay) */
    void sndopcmd1(void); /*transmit command to multimedia card: CMD1-"Send_Output_Condition" */
    void sndcmd2(void); /*transmit command to multimedia card: CMD1-"Send_Output_Condition" */
    void sndrstcmd(void); /*transmit command to multimedia card: CMD1-"Send_Output_Condition" */
    void sndcmd3(void);
    char MINTSTA;
    char code dummy[3] _at_ 0x23;
    unsigned char intval; /*global variable to store the MMCINT value at the time of interrupt */
    main(void) {
    unsigned char xdata a[10];
    unsigned long int j,i;

    delay(100);
    MINTSTA='F';
    MMCLK=0x27; /* division factor 40 = 400khz*/ /*Set MMC Clock frequency*/
    MMCON2 |= 0x86; /* Set MMCEN, Delay tx=9 MMC clock*/
    MMMSK=0x3C ; /*for */
    IEN1=0x01; /* enable EMMC, MMC interrupt enable bit */
    IEN0=0x80; /* enable EA, Global interrupt enable bit */
    IPH0=0x00;
    IPH1=0x01; /* Set High priority to MMC interrupt*/
    MMCON2 |= 0x60; /* Set Data and Command controller reset bit*/
    MMCON2 &= 0x9F; /* Clear Data and Command controller reset bit*/
    delay(74);
    MMCON0 |= 0x30; /*Set Command transmit pointer and receive pointer reset bit*/
    MMCON0 &= 0xCF; /*Clear Command transmit pointer and receive pointer reset bit*/
    MMCON0 |= 0xC0; /*Set Data transmit pointer and receive pointer reset bit*/
    MMCON0 &= 0x3F; /*Clear Data transmit pointer and receive pointer reset bit*/
    //-------------IDLE STATE -----------------//
    MMCON1 |= 0x02; /*Set Response enable bit */
    MMCON0 |= 0x03; /*48 bit response format and CRC7 enabled*/
    MMCMD=0x40; /* Load "CMD0 - Command 0" - go_idle state/Software reset*/
    MMCMD=0x00; /*Argument byte 1*/
    MMCMD=0x00; /*Argument byte 2*/
    MMCMD=0x00; /*Argument byte 2*/
    MMCMD=0x00; /*Argument byte 2*/
    MMCMD=0x95; /*Argument byte 2*/
    MMCON1 |= 0x03; /* Set Command transmission bit*/
    MMCON1 &= 0xFC; /* Clear Command transmission bit*/
    delay(80);
    //-------------IDLE STATE -----------------//


    /*for(j=0;j<20;j++)
    {
    MMCON0 |= 0x03; /*Set Response format bit for 48bit format*/
    //MMCON1 |= 0x02; /*Set Response enable bit */
    //MMCMD=0x41; /* Load "CMD1 - Command 1" - SEND_OP_COND */
    //MMCMD=0x00; /*Argument byte 4 - OCR byte 4 */
    //MMCMD=0x00; /*Argument byte 3 - OCR byte 3 - selected voltage range 2.8V to 3.2V */
    //MMCMD=0x00; /*Argument byte 2 - OCR byte 2 */
    //MMCMD=0x00; /*Argument byte 1 - OCR byte 1 */
    //MMCMD=0xFF; /*Checksum is no longer required. Even we always send FF */
    //MMCON1 |= 0x03; /* Set Command transmission and response enable bit*/
    //MMCON1 &= 0xFC; /* Clear Command tx & Response enable bit. */
    //delay(80);
    //}*/
    /*for(j=0;j<20;j++)
    {
    MMCON0=0x31; /* Clear CMD TX & RX pointer */
    //MMCON1=0x03; /* Command tx enable. */
    //MMCON0=0x01; /* Clear CMD TX & RX pointer, 138 bit response & disable CRC */
    //MMCON0 |= 0x03; /*Set Response format bit for 48bit format*/
    //MMCON1 |= 0x02; /*Set Response enable bit */
    //MMCMD=0x42; //SEND CID
    //MMCMD=0x00; /* 4 bytes from here is the block length */
    //MMCMD=0x00;
    //MMCMD=0x00;
    //MMCMD=0x00;
    //MMCMD=0xFF;/* checksum is no longer required but we always send 0xFF */
    //MMCON1 |= 0x03; /* Set Command transmission and response enable bit*/
    //MMCON1 &= 0xFC; /* Clear Command tx & Response enable bit. */
    //delay(80);
    //}

    //for data reading //
    //MMCON1 &= 0xF7; /*Set datdir=0 for data in read mode */
    //if(MMINT==0x10)
    //{
    //if(MMSTA==0x0c)
    // LED1=!LED1;
    //}
    //for data reading //

    i=2;
    do
    {
    //for(j=0;j<0xff;j++)
    {
    //if(MINTSTA=='F')

    sndopcmd1();
    LED1=!LED1;
    delay(10000);
    }
    i--;
    }
    while(MMCMD!=0);
    for(j=0;j<200;j++)
    {
    if(MINTSTA=='T')
    {
    sndcmd2();

    delay(10000);
    }
    }

    for(j=0;j<20;j++)
    {
    sndcmd3();
    LED2=!LED2;
    delay(10000);
    }
    wrtram(&a);
    rdram(&a);
    while (1) {
    }
    }
    /*----------------------------------------------------------*/
    /* FUNCTIONS */
    /*------------ for ----------------------------------------------*/
    void sndopcmd1(void) {
    MMCON0 |= 0x03; /*Set Response format bit for 48bit format*/
    MMCON1 |= 0x02; /*Set Response enable bit */
    MMCMD=0x41; /* Load "CMD1 - Command 1" - SEND_OP_COND */
    MMCMD=0x00; /*Argument byte 4 - OCR byte 4 */
    MMCMD=0x00; /*Argument byte 3 - OCR byte 3 - selected voltage range 2.8V to 3.2V */
    MMCMD=0x00; /*Argument byte 2 - OCR byte 2 */
    MMCMD=0x00; /*Argument byte 1 - OCR byte 1 */
    MMCMD=0xFF; /*Checksum is no longer required. Even we always send FF */
    MMCON1 |= 0x03; /* Set Command transmission and response enable bit*/
    MMCON1 &= 0xFC; /* Clear Command tx & Response enable bit. */
    }
    void sndcmd2(void) {
    MMCON0=0x31; /* Clear CMD TX & RX pointer */
    MMCON1=0x03; /* Command tx enable. */
    MMCON0=0x01; /* Clear CMD TX & RX pointer, 138 bit response & disable CRC */
    MMCMD=0x42; /* SEND_CID */
    MMCMD=0x00; /*Argument byte 4 - */
    MMCMD=0x00; /*Argument byte 3 - */
    MMCMD=0x00; /*Argument byte 2 - */
    MMCMD=0x00; /*Argument byte 1 - */
    MMCON1=0x00;
    }
    void sndcmd3(void) {
    MMCON0 |= 0x03; /*Set Response format bit for 48bit format*/
    MMCON1 |= 0x02; /*Set Response enable bit */
    MMCMD=0x50; /* Load "CMD3 - Command 3" - for blocklength select */
    MMCMD=0x00; /*Argument byte 4 - OCR byte 4 */
    MMCMD=0x02; /*Argument byte 3 - OCR byte 3 - selected voltage range 2.8V to 3.2V */
    MMCMD=0x00; /*Argument byte 2 - OCR byte 2 */
    MMCMD=0x00; /*Argument byte 1 - OCR byte 1 */
    MMCON1 |= 0x03; /* Set Command transmission and response enable bit*/
    MMCON1 &= 0xFC; /* Clear Command tx & Response enable bit. */
    }

    /**********************************************************************************/
    /* MMC interrupt routine */
    /*--------------------------------------------------------------------------------*/
    /* Vector: 003Bh using register bank 2 */
    mmcint() interrupt 7 using 2 {
    unsigned char valmmint, valmmsta, cmdres[17],i;
    valmmint=MMINT;
    valmmsta=MMSTA;

    if(MINTSTA=='F'){
    if(valmmint >= 0x40){
    for(i=0;i<6;i++){
    LED2=!LED2;
    cmdres=MMCMD;
    }
    /*Check for the busy bit */
    if (cmdres[1]>=0x80){

    MINTSTA='T';
    }
    }
    }
    else{
    if(MINTSTA=='T'){
    valmmint=MMINT;
    valmmsta=MMSTA;
    for (i=0;i<6;i++){
    cmdres=MMCMD;
    }

    MINTSTA='S'; /* Interrup */
    }
    }
    }
    /*---------------------------------------------------------------------------------*/
    void wrtram (char *pa) {
    int i;
    for (i=0 ; i<=10; i++) {
    *pa=0xAA;
    pa++;
    }
    }
    void rdram(char *pb) {
    unsigned int i;
    unsigned char temp;
    for(i=0; i<10 ;i++) {
    temp=*pb;
    pb++;
    }
    if(temp==0xAA)
    {
    LED2=!LED2;
    }
    }
    void delay(long int x) {
    long int j;
    for(j=0;j<x;j++) {
    }
    }
    /*----------------------------------------------------------*/
Similar Threads
Forum Title Date
Embedded Systems and Microcontrollers regarding interfacing sd card with pic 18f4520 Nov 8, 2010
Embedded Systems and Microcontrollers Help Regarding mobile camera interfacing Dec 21, 2009
Embedded Systems and Microcontrollers Regarding interfacing of MMC card Jul 18, 2008
Embedded Systems and Microcontrollers doubt regarding adc&8051 Jun 5, 2014
Embedded Systems and Microcontrollers Question regarding STM32F407 Jun 19, 2013

Share This Page