Regarding interfacing of MMC card

Thread Starter

kovendan_23

Joined Jul 18, 2008
4
sir I am interfacing A MMC Card to MY AT89C51SND2c controller .
Here I send CMD0 and CMD1 but i could not get any response from it .
Could any help me in this case . or Plz send some source code for this controller
 

Thread Starter

kovendan_23

Joined Jul 18, 2008
4
Sir I am programming with C language . here is the code that i wrote for MMC card interfacing using KEIL . Plz view and give some solutions or Plz otherwise send me the source code which would be helpful to finish my work
 

hgmjr

Joined Jan 28, 2005
9,029
here is the code that i had written for this interfacing

/************************************************** ************************************************** *****/
/* 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" */
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],temp;
unsigned long int i,j;
LED2=1;
MINTSTA='F'; /* Clear this flag. Whenever interuppt occurs set this flag*/
delay(100);
MMCLK=0x27; /* division factor 40 = 400khz*/ /*Set MMC Clock frequency*/
MMCON2 |= 0x86; /* Set MMCEN, Delay tx=9 MMC clock*/
MMMSK=0x3C ; /* */
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*/
MMCON1 |= 0x02; /*Set Response enable bit */
MMCON0 |= 0x03; /*48 bit response format and CRC7 disabled*/
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(1000);
for(j=0;j<20000;j++)
{
if(MINTSTA=='F')
{
sndopcmd1();
LED1=!LED1;
delay(10000);
}
}
for(j=0;j<200;j++)
{
if(MINTSTA=='T')
{
sndcmd2();
LED2=!LED2;
delay(10000);
}
}

wrtram(&a);
rdram(&a);
while (1) {
}
}
/*----------------------------------------------------------*/
/* FUNCTIONS */
/*----------------------------------------------------------*/
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 sndrstcmd(void) {
MMCON1 &= 0xF7;
MMCON2 |= 0x86;
MMCON2 |= 0x60;
MMCON2 &= 0x9F;
MMCON0 |= 0x30;
MMCON0 &= 0xCF;
MMCON0 |= 0xC0;
MMCON0 &= 0x3F;
MMCMD = 0x40;
MMCMD = 0x00;
MMCMD = 0x00;
MMCMD = 0x00;
MMCMD = 0x00;
MMCMD = 0x95;
MMCON1 |= 0x01;
MMCON1 &= 0xFE;
}
/************************************************** ********************************/
/* MMC interrupt routine */
/*--------------------------------------------------------------------------------*/
/* Vector: 003Bh using register bank 2 */
mmcint() interrupt 7 using 2 {
unsigned char valmmint, valmmsta, cmdres[17],i;
if(MINTSTA=='F'){
valmmint=MMINT;
valmmsta=MMSTA;
if(valmmint >= 0x40){
for(i=0;i<6;i++){
cmdres=MMCMD;
}
/*Check for the busy bit */
if (cmdres[1]>=0x80){
LED1=0;
MINTSTA='T';
}
}
}
else{
if(MINTSTA=='T'){
valmmint=MMINT;
valmmsta=MMSTA;
for (i=0;i<6;i++){
cmdres=MMCMD;
}
LED2=0;
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++;
}
}
void delay(long int x) {
long int j;
for(j=0;j<x;j++) {
}
}
/*----------------------------------------------------------*/


I have copied your code and placed it in this the original thread.

hgmjr
 

Thread Starter

kovendan_23

Joined Jul 18, 2008
4
Sir i think u had find my C file could u plz help me to interface the mmc card. Plz give me some idea to do this interfacing .i struck up there
 
Top