CART
  • Cart is empty.

    ItemQuantityPrice

    Total: $0

Multi Media Card


Multi Media Card ( SD Card ) read/write test

Toolkit:AVR Development System

Location:/bipom/devtools/WinAVR/minimaxavrc/Examples/Labs/mmc

Code Example


#define MMC_BUFFER_SIZE		512
UBYTE mmcBuffer[MMC_BUFFER_SIZE];

// ****************************************************************************

int main (void)
{
	ERRCODE errCode;
	UINT ndx;

	// Allow Power Up peripheral devices 

 	_delay_ms(500);

	// Initialize SPI bus

	spiInit();	

	// Initialize the serial port

	uart1Init(19200);

	uart1Printf("\n\r** Test MMC **");

	errCode = mmcReset(); 	

	if(errCode != SUCCESS)
	{
		uart1Printf("\n\rReset MMC - BAD, ec = %d",errCode);		
		goto func_end;
	}

	uart1Printf("\n\rReset MMC - OK");
	
	// Initialize MMC 

	errCode = mmcInit(); 
		
	if(errCode != SUCCESS)
	{
		uart1Printf("\n\rInit MMC - BAD, ec = %d",errCode);		
		goto func_end;
	}	

	uart1Printf("\n\rInit MMC - OK");

	// Set Block Length 

	errCode = mmcSetBlockLength(MMC_BUFFER_SIZE);

	if(errCode != SUCCESS)
	{
		uart1Printf("\nSet Block Length - BAD, ec = %d",errCode);		
		goto func_end;
	}			

	uart1Printf("\nSet Block Length - OK");

	// Write Block 

	for ( ndx = 0 ; ndx <MMC_BUFFER_SIZE ; ndx++)
		mmcBuffer[ndx] = ndx & 0xFF;

	errCode = mmcWriteBlock(0, 0, mmcBuffer, MMC_BUFFER_SIZE);		

	if(errCode != SUCCESS)
	{
		uart1Printf("\nWrite Block - BAD, ec = %d",errCode);		
		goto func_end;
	}	
	
	uart1Printf("\nWrite Block - OK");	

	// Set Block Length 

	errCode = mmcSetBlockLength(MMC_BUFFER_SIZE);

	if(errCode != SUCCESS)
	{
		uart1Printf("\nSet Block Length - BAD, ec = %d",errCode);		
		goto func_end;
	}	
	
	uart1Printf("\nSet Block Length - OK");		

	// Clear data buffer

	for( ndx=0; ndx<MMC_BUFFER_SIZE; ndx++ ) 
		mmcBuffer[ndx] = 0;

	// Read Block 

	errCode = mmcReadBlock(0, 0, mmcBuffer, MMC_BUFFER_SIZE);

	if(errCode != SUCCESS)
	{
		uart1Printf("\nRead Block - BAD, ec = %d",errCode);		
		goto func_end;
	}		

	uart1Printf("\n\nRead Block - OK");

	for ( ndx = 0 ; ndx <MMC_BUFFER_SIZE ; ndx++)
	{
		if (!(ndx%16)) uart1Printf("\n");
		uart1Printf( "%02x ", mmcBuffer[ndx]);  			 		
	}		

func_end:
	
	return 0;
}