Exemplo n.º 1
0
int main (void) 
{
  volatile uint32_t i;

SystemCoreClockUpdate();

  for ( i = 0; i < BUFSIZE; i++ )
  {
	if ( i & 0x01 )
	  UARTTxBuffer[i] = 0x55;
	else
	  UARTTxBuffer[i] = 0xAA;
	UARTTxDummyBuffer[i] = UARTRxBuffer[i] = 0x00;	
  }

  /* NVIC is installed inside UARTInit file. */
  USARTInit(9600, MASTER_MODE);

  /* To run USART test, reset at the slave side first, master will
  send a block of data first, if it's not in the continuous mode,
  master send a block of dummy data to clock in the data from the slave,
  on the slave side, it's ready to receive, once it's received a block
  of data, send the same data back to the master. Once the master receives
  the block of data from the slave. It verifies the result. */

  /* For Sync comminication with STARTSTOP disabled, the sync. is very important
  or received data will be one bit off. If SYNCCTRL_NOSS bit is set, the program
  should have a break point to stop below, then, reset the slave side. Without
  doing so, this program will fail. If SYNCCTRL_NOSS is not set, STARTSTOP bit
  is enabled, then break point is not necessary. */
  USARTSend( (uint8_t *)UARTTxBuffer, BUFSIZE );

  for ( i = 0; i < 0x4000; i++ );		/* Short delay and wait for slave to be ready. */
  UARTBlockReceived = 0;

  /* Send dummy block for read, one more than needed. It's not necessary 
  if continuous clock is turned on while STARTSTOP is enabled. */
  if ( LPC_USART->SYNCCTRL & SYNCCTRL_NOSS )
  {
	/* If StartStop is disabled, no continuous clock should be turned on. */
	USARTSend( (uint8_t *)UARTTxDummyBuffer, BUFSIZE );
  }
  else if ( !(LPC_USART->SYNCCTRL & SYNCCTRL_CSCEN) )
  {
	USARTSend( (uint8_t *)UARTTxDummyBuffer, BUFSIZE );
  }
	
  while ( !UARTBlockReceived );		/* Whole data block received from the slave. */

  /* Verifying buffer. */
  for ( i = 0; i < BUFSIZE; i++ )
  {
	if ( UARTTxBuffer[i] != UARTRxBuffer[i] )
	{
	  while ( 1 );
	}
  }
  UARTBlockReceived = 0;
  while ( 1 );	/* never exit from main for debugging. */
}
Exemplo n.º 2
0
uint32_t USARTSendString(USART_TypeDef *USARTPort, char *buff)
{
    uint32_t i = 0;

    // Get the exact length of the buffer
    while(buff[i] != '\0') { i++; }

    return USARTSend(USARTPort, (uint8_t *)buff, i);
}
Exemplo n.º 3
0
int main (void) 
{
  uint32_t i;

SystemCoreClockUpdate();

  for ( i = 0; i < BUFSIZE; i++ )
  {
	UARTTxBuffer[i] = UARTRxBuffer[i] = 0x00;
  }

  /* To run USART test, reset at the slave side first, master will
  send a block of data first, if it's not in the continuous mode,
  master send a block of dummy data to clock in the data from the slave,
  on the slave side, it's ready to receive, once it's received a block
  of data, send the same data back to the master. Once the master receives
  the block of data from the slave. It verifies the result. */

  /* NVIC is installed inside USARTInit file. */
  USARTInit(9600, SLAVE_MODE);

  while ( !UARTBlockReceived );

  for ( i = 0; i < BUFSIZE; i++ )
  {
	if ( (UARTRxBuffer[i] != 0xAA) && ((i&0x1)==0x0) )
	{
	  while ( 1 );
	}
	if ( (UARTRxBuffer[i] != 0x55) && ((i&0x1)==0x1) )
	{
	  while ( 1 );
	}
	UARTTxBuffer[i] = UARTRxBuffer[i];			/* Copy to the transmit buffer. */
	UARTRxBuffer[i] = 0;	/* Clear the Rx buffer for next block if necessary. */
  }
  USARTSend( (uint8_t *)UARTTxBuffer, BUFSIZE );
  UARTBlockReceived = 0;
  
  while ( 1 );	/* Never exit from main for debugging purpose. */

}