MultiMedia Card (MMC)


Test MMC connected to MINI-MAX/51 series board. Using MMC BiPOM Library.

Toolkit:SDCC 8051 Development System

Location:/bipom/devtools/SDCC/examples/mmc

Code Example


extern UBYTE _DATA_BUFFER[_DATA_BUFFER_SIZE];
//

int main()
{
	UBYTE b; 
	ERRCODE errCode;
	int ndx; 

	b = ByteSPI(0xFF);
	
	b = 16;
	
	delay(b);
	
	delay(500);
	serinit(19200>>1);

	printf ("\n** Test MMC **");
	errCode = ResetMMC(); 	
	if(errCode==SUCCESS)
	{	
		printf ("\nReset MMC - OK");
	}
	else
	{
		printf ("\nReset MMC - BAD, ec = %d",errCode);		
		goto func_end;
	}
	
	
	// Initialize MMC 

	errCode = InitMMC(); 	
	if(errCode==SUCCESS)
	{	
		printf ("\nInit MMC - OK");
	}
	else
	{
		printf ("\nInit MMC - BAD, ec = %d",errCode);		
		goto func_end;
	}	
	
	// Read CID register

	errCode = ReadCIDMMC();
	if(errCode==SUCCESS)
	{	
		printf ("\nRead MMC CID - OK");
	}
	else
	{
		printf ("\nRead MMC CID - BAD, ec = %d",errCode);		
		goto func_end;
	}		
	
	// Read CSD register

	errCode = ReadCSDMMC();
	if(errCode==SUCCESS)
	{	
		printf ("\nRead MMC CSD - OK");
	}
	else
	{
		printf ("\nRead MMC CSD - BAD, ec = %d",errCode);		
		goto func_end;
	}	
	
	// Set Block Length 

	errCode = SetBlockLengthMMC(512);
	if(errCode==SUCCESS)
	{	
		printf ("\nSet Block Length - OK");
	}
	else
	{
		printf ("\nSet Block Length - BAD, ec = %d",errCode);		
		goto func_end;
	}			
	
	// Write Block 

	for ( ndx = 0 ; ndx <512 ; ndx++)
		_DATA_BUFFER[ndx]=ndx&0xFF;
	
	errCode = WriteBlockMMC(0,0,512);		
	if(errCode==SUCCESS)
	{	
		printf ("\nWrite Block - OK");
	}
	else
	{
		printf ("\nWrite Block - BAD, ec = %d",errCode);		
		goto func_end;
	}		
	
	// Set Block Length 

	errCode = SetBlockLengthMMC(512);
	if(errCode==SUCCESS)
	{	
		printf ("\nSet Block Length - OK");
	}
	else
	{
		printf ("\nSet Block Length - BAD, ec = %d",errCode);		
		goto func_end;
	}		
	
	for ( ndx = 0 ; ndx <512 ; ndx++) 
		_DATA_BUFFER[ndx]=0;
	
	// Read  Block 

	errCode = ReadBlockMMC(0,0,512);
	if(errCode==SUCCESS)
	{	
		printf ("\n\nRead Block - OK");
		for ( ndx = 0 ; ndx <512 ; ndx++)
		{
			if (!(ndx%16)) 
				printf("\n");
				
			printf ( "%02x ", _DATA_BUFFER[ndx]);  
			 		
		}		
	}
	else
	{
		printf ("\nRead Block - BAD, ec = %d",errCode);		
		goto func_end;
	}		
	
func_end:
	for (;; );

}