keil_examples/SSP/ssptest.c
/*****************************************************************************
** Function name:		SEEPROMTest
**
** Descriptions:		Serial EEPROM(Atmel 25xxx) test
**				
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
Function name:         SEEPROMTest
Descriptions:          Serial EEPROM(Atmel 25xxx) test

None
Returned value:                None
Function name : SEEPROMTest Descriptions : Serial EEPROM ( Atmel 25xxx ) test None Returned value : None
void SEEPROMTest( uint32_t portnum, uint32_t location )
{
  uint32_t i, timeout;
#if SSP_DEBUG
  uint8_t temp[2];
#endif
  if ( portnum == 1 )
  {
	LPC_GPIO0->FIODIR |= (0x1<<16);		
  }
  else
  {
	LPC_GPIO0->FIODIR |= (0x1<<6);		
  }
  SSP_SSELToggle( portnum, 0 );
  src_addr[0] = WREN;			
  SSPSend( portnum, (uint8_t *)src_addr, 1 );
  SSP_SSELToggle( portnum, 1 );
  for ( i = 0; i < DELAY_COUNT; i++ );	
  SSP_SSELToggle( portnum, 0 );
  src_addr[0] = RDSR;	
  SSPSend( portnum, (uint8_t *)src_addr, 1 );
  SSPReceive( portnum, (uint8_t *)dest_addr, 1 );
  SSP_SSELToggle( portnum, 1 );
  if ( dest_addr[0] & (RDSR_WEN|RDSR_RDY) != RDSR_WEN ) 
  {
	while ( 1 );
  }
  for ( i = 0; i < SSP_BUFSIZE; i++ )	    
  {
	src_addr[i+3] = i;	
	dest_addr[i] = 0;
  }
  SSP_SSELToggle( portnum, 0 );
  src_addr[0] = WRITE;	
  src_addr[1] = 0x00;	
  src_addr[2] = 0x00;	
  SSPSend( portnum, (uint8_t *)src_addr, SSP_BUFSIZE );
  SSP_SSELToggle( portnum, 1 );
  for ( i = 0; i < 0x30000; i++ );	
  timeout = 0;
  while ( timeout < MAX_TIMEOUT )
  {
	SSP_SSELToggle( portnum, 0 );
	src_addr[0] = RDSR;	
	SSPSend( portnum, (uint8_t *)src_addr, 1);
	SSPReceive( portnum, (uint8_t *)dest_addr, 1 );
	SSP_SSELToggle( portnum, 1 );
	if ( (dest_addr[0] & RDSR_RDY) == 0x00 )	
	{
	    break;
	}
	timeout++;
  }
  if ( timeout == MAX_TIMEOUT )
  {
	while ( 1 );
  }
  for ( i = 0; i < DELAY_COUNT; i++ );	
  SSP_SSELToggle( portnum, 0 );
  src_addr[0] = READ;		
  src_addr[1] = 0x00;		
  src_addr[2] = 0x00;		
  SSPSend( portnum, (uint8_t *)src_addr, 3 ); 
  SSPReceive( portnum, (uint8_t *)&dest_addr[3], SSP_BUFSIZE-3 );
  SSP_SSELToggle( portnum, 1 );
  for ( i = 3; i < SSP_BUFSIZE; i++ )
  {
	if ( src_addr[i] != dest_addr[i] )
	{
	  while( 1 );			
	}
  }
  return;
}
void SEEPROMTest ( uint32_t portnum , uint32_t location ) { uint32_t i , timeout ; #if SSP_DEBUG uint8_t temp [ 2 ] ; #endif if ( portnum == 1 ) { LPC_GPIO0 -> FIODIR |= ( 0x1 << 16 ) ; } else { LPC_GPIO0 -> FIODIR |= ( 0x1 << 6 ) ; } SSP_SSELToggle ( portnum , 0 ) ; src_addr [ 0 ] = WREN ; SSPSend ( portnum , ( uint8_t * ) src_addr , 1 ) ; SSP_SSELToggle ( portnum , 1 ) ; for ( i = 0 ; i < DELAY_COUNT ; i ++ ) ; SSP_SSELToggle ( portnum , 0 ) ; src_addr [ 0 ] = RDSR ; SSPSend ( portnum , ( uint8_t * ) src_addr , 1 ) ; SSPReceive ( portnum , ( uint8_t * ) dest_addr , 1 ) ; SSP_SSELToggle ( portnum , 1 ) ; if ( dest_addr [ 0 ] & ( RDSR_WEN | RDSR_RDY ) != RDSR_WEN ) { while ( 1 ) ; } for ( i = 0 ; i < SSP_BUFSIZE ; i ++ ) { src_addr [ i + 3 ] = i ; dest_addr [ i ] = 0 ; } SSP_SSELToggle ( portnum , 0 ) ; src_addr [ 0 ] = WRITE ; src_addr [ 1 ] = 0x00 ; src_addr [ 2 ] = 0x00 ; SSPSend ( portnum , ( uint8_t * ) src_addr , SSP_BUFSIZE ) ; SSP_SSELToggle ( portnum , 1 ) ; for ( i = 0 ; i < 0x30000 ; i ++ ) ; timeout = 0 ; while ( timeout < MAX_TIMEOUT ) { SSP_SSELToggle ( portnum , 0 ) ; src_addr [ 0 ] = RDSR ; SSPSend ( portnum , ( uint8_t * ) src_addr , 1 ) ; SSPReceive ( portnum , ( uint8_t * ) dest_addr , 1 ) ; SSP_SSELToggle ( portnum , 1 ) ; if ( ( dest_addr [ 0 ] & RDSR_RDY ) == 0x00 ) { break ; } timeout ++ ; } if ( timeout == MAX_TIMEOUT ) { while ( 1 ) ; } for ( i = 0 ; i < DELAY_COUNT ; i ++ ) ; SSP_SSELToggle ( portnum , 0 ) ; src_addr [ 0 ] = READ ; src_addr [ 1 ] = 0x00 ; src_addr [ 2 ] = 0x00 ; SSPSend ( portnum , ( uint8_t * ) src_addr , 3 ) ; SSPReceive ( portnum , ( uint8_t * ) & dest_addr [ 3 ] , SSP_BUFSIZE - 3 ) ; SSP_SSELToggle ( portnum , 1 ) ; for ( i = 3 ; i < SSP_BUFSIZE ; i ++ ) { if ( src_addr [ i ] != dest_addr [ i ] ) { while ( 1 ) ; } } return ; }
Function name:         SEEPROMTest
Descriptions:          Serial EEPROM(Atmel 25xxx) test
Function name : SEEPROMTest Descriptions : Serial EEPROM ( Atmel 25xxx ) test
/* SSP1, P0.16 defined as Outputs */ /* SSP0 P0.6 defined as Outputs */ /* Test Atmel 25016 SPI SEEPROM. */ /* set write enable latch */ /* delay minimum 250ns */ /* check status to see if write enabled is latched */ /* bit 0 to 0 is ready, bit 1 to 1 is write enable */ /* Init RD and WR buffer */ /* leave three bytes for cmd and offset(16 bits) */ /* please note the first two bytes of WR and RD buffer is used for
  commands and offset, so only 2 through SSP_BUFSIZE is used for data read,
  write, and comparison. */ /* Write command is 0x02, low 256 bytes only */ /* write address offset MSB is 0x00 */ /* write address offset LSB is 0x00 */ /* delay, minimum 3ms */ /* check status to see if write cycle is done or not */ /* bit 0 to 0 is ready */ /* delay, minimum 250ns */ /* Read command is 0x03, low 256 bytes only */ /* Read address offset MSB is 0x00 */ /* Read address offset LSB is 0x00 */ /* verifying, ignore the difference in the first two bytes */ /* Verification failed */