DataFlash Example


This example demonstrates how to read/write SPI DataFlash on-board the MINI-MAX/ARM boards.The example uses ReadPage_SPI_DATAFLASH() and WritePage_SPI_DATAFLASH() functions from BiPOM Library. Hardware SPI port is used.

Toolkit:ARM Development System

Location:/bipom/devtools/GCC/LPC2000/examples/AT45DB081

Code Example


int main (void)
{
	ERRCODE ec=SUCCESS;
	UBYTE dataBuffer[DATA_LENGTH]={0};
	UINT ndx;

	/* Initialize the system */
	Initialize();

	tiprintf("\n\rBIPOM MINI-MAX/ARM");
	tiprintf("\n\rDATAFLASH TEST ");
	
	/* Disable Hardware Protection */
	tiprintf("\n\rDisable Hardware Protection...");

	/* Disable Write Protect of DataFlash; this pin is controlled by AVR secondary processor on the board */
	ec = Change_AVR_pin( WP_PIN, SET_PIN );

	if( ec )
	{
		tiprintf ("FAILED, ec = %d",ec);
		goto func_end;
	}
	else tiprintf ("PASSED");

	/* Initialize SPI hardware port (7MHz) */
	Initialize_FAST_SPI(SPI_7MHZ_BUS);		
	
	/* Fill Data Buffer */
	for( ndx=0; ndx<DATA_LENGTH; ndx++ ) 
		dataBuffer[ndx] = ndx;
	
	/* Write Data Buffer */
	tiprintf("\n\rWrite Data Buffer.............");
	
	ec = WritePage_SPI_DATAFLASH(0,dataBuffer);
	
	if( ec )
	{
		tiprintf ("FAILED, ec = %d",ec);
		goto func_end;
	}
	else tiprintf ("PASSED");	
	
	/* Clear Data Buffer */
	for( ndx=0; ndx<DATA_LENGTH; ndx++ ) 
		dataBuffer[ndx] = 0;		
	
	/* Read Data Buffer */
	tiprintf("\n\rRead Data Buffer..............");
	
	ReadPage_SPI_DATAFLASH( 0, dataBuffer );
	
	tiprintf ("PASSED");
	
	/* Check Data Buffer by comparing what we wrote to what we read back */
	tiprintf( "\n\rCheck Data Buffer............." );
	
	for( ndx=0; ndx<DATA_LENGTH; ndx++ ) 
	{
		/* If there is a mismatch, this is an error */
		if( dataBuffer[ndx] != (ndx & 0xFF) ) 
		{
			ec = ERROR;
			break;		
		}
	}
	
	if( ec )	
		tiprintf( "FAILED, ec = %d", ec );
	else
		tiprintf( "PASSED" );
		
	/* Print Data Buffer */
	tiprintf( "\n\rPrint Data Buffer" );
	
	PrintDataBlock( dataBuffer, DATA_LENGTH );
	
	
func_end:
	tiprintf( "\n\rSPI DATAFLASH TEST " );
	
	if( ec )	
		tiprintf("FAILED");
	else
		tiprintf("PASSED");	
	
}