Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MMC initialization steps (via SPI)

Status
Not open for further replies.

vinodstanur

New Member
Pls give me some working mmc initialization steps;
I tried CMD0 at first and got response 0x01 . But then i give CMD1 but not getting response!=0. Tried in loop untill the response !=0. But not getting response. Tried another MMC .Still same problem. Then i give command(16,0,512,0xfF)//CMD16
But not getting response 1;
Then i had given command(17,0,(512),0xff);//write enable command CMD17
The I could receive 0x05 as response!!!!!!! So i am getting some response as correct. So what is my problem? I think its initialization problem. So any one could give me the correct initialization steps?
 
Maybe this will help...

You have to initialise the MMC to SPI mode

Code:
nt mmc_init() 
	{
	DWORD i; 
	/* Generate a data pattern for write block */ 
	for(i=0;i<MMC_DATA_SIZE;i++) 
		{  
		MMCWRData[i] = i; 
		{  
	MMCStatus = 0; 
	IOSET0 = SPI_SEL; /* set SPI SSEL */ 
	/* initialise the MMC card into SPI mode by sending 80 clks on */ 
	/* Use MMCRDData as a temporary buffer for SPI_Send() */  
	for(i=0; i<10; i++)  
		{ 
		MMCRDData[i] = 0xFF; 
		}  
	SPI_Send( MMCRDData, 10 ); 
   
	IOCLR0 = SPI_SEL; /* clear SPI SSEL */ 
	/* send CMD0(RESET or GO_IDLE_STATE) command, all the arguments  
	are 0x00 for the reset command, precalculated checksum */ 
	MMCCmd[0] = 0x40; 
	MMCCmd[1] = 0x00; 
	MMCCmd[2] = 0x00; 
	MMCCmd[3] = 0x00; 
	MMCCmd[4] = 0x00; 
	MMCCmd[5] = 0x95; 
	SPI_Send( MMCCmd, MMC_CMD_SIZE );
	/* if = 1 then there was a timeout waiting for 0x01 from the MMC */ 
	if( mmc_response(0x01) == 1 ) 
		{  
		MMCStatus = IDLE_STATE_TIMEOUT; 
		IOSET0 = SPI_SEL; /* set SPI SSEL */ 
		return MMCStatus; 
		}  
	/* Send some dummy clocks after GO_IDLE_STATE */ 
	IOSET0 = SPI_SEL; /* set SPI SSEL */ 
	SPI_ReceiveByte(); 
	IOCLR0 = SPI_SEL; /* clear SPI SSEL */      
	
	/* must keep sending command until zero response ia back. */ 
    	i = MAX_TIMEOUT; 
	do  
		{  
		/* send mmc CMD1(SEND_OP_COND) to bring out of idle state */ 
		/* all the arguments are 0x00 for command one */ 
		MMCCmd[0] = 0x41; 
		MMCCmd[1] = 0x00; 
		MMCCmd[2] = 0x00; 
		MMCCmd[3] = 0x00; 
		MMCCmd[4] = 0x00; 
		/* checksum is no longer required but we always send 0xFF */ 
		MMCCmd[5] = 0xFF; 
		SPI_Send( MMCCmd, MMC_CMD_SIZE ); 
		i--; 
		} while ( (mmc_response(0x00) != 0) && (i>0) ); 
	/* timeout waiting for 0x00 from the MMC */ 
	if ( i == 0 ) 
		{  
		MMCStatus = OP_COND_TIMEOUT; 
		IOSET0 = SPI_SEL; /* set SPI SSEL */ 
		return MMCStatus; 
		}  
	/* Send some dummy clocks after SEND_OP_COND */ 
	IOSET0 = SPI_SEL; /* set SPI SSEL */ 
	SPI_ReceiveByte(); 
	IOCLR0 = SPI_SEL; /* clear SPI SSEL */ 
      
	/* send MMC CMD16(SET_BLOCKLEN) to set the block length */ 
	MMCCmd[0] = 0x50; 
	MMCCmd[1] = 0x00;  /* 4 bytes from here is the block length */ 
	/* LSB is first */   
	/* 00 00 00 10 set to 16 bytes */ 
	/* 00 00 02 00 set to 512 bytes */ 
	MMCCmd[2] = 0x00; 
	/* high block length bits - 512 bytes */ 
	MMCCmd[3] = 0x02; 
	/* low block length bits */ 
	MMCCmd[4] = 0x00; 
	/* checksum is no longer required but we always send 0xFF */ 
	MMCCmd[5] = 0xFF; 
	SPI_Send( MMCCmd, MMC_CMD_SIZE ); 
     
	if( (mmc_response(0x00))==1 ) 
		{  
		MMCStatus = SET_BLOCKLEN_TIMEOUT; 
		IOSET0 = SPI_SEL;  /* set SPI SSEL */
		return MMCStatus; 
		}
	IOSET0 = SPI_SEL;  /* set SPI SSEL */ 
	SPI_ReceiveByte(); 
	return 0; 
	}

Ian
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top