void main(){

    UART_1_Start();
	
	/* choose when we receive interrupts from tx and rx */
	UART_1_SetTxInterruptMode(UART_1_TX_STS_COMPLETE);
	UART_1_SetRxInterruptMode(UART_1_RX_STS_FIFO_NOTEMPTY);
	
	CyGlobalIntEnable;
    
	UART_1_ClearTxBuffer();
	UART_1_ClearRxBuffer();
	
	LCD_Char_1_Start();
	LCD_Char_1_Position(0,0);
	
	/* initialize our source data to index */
	int j;
	for(j = 0; j < DATA_SIZE; ++j){
		sourceData[j] = j;
	}
	
	/* enable our interrupt routines */
	isr_1_StartEx(tx_int);
	isr_2_StartEx(rx_int);	
		
	/* idle loop until we finish our transmission */	
 	while(!rx_done){}

 	int k;
	int errors = 0;
	/* data validation */
	for(k = 0; k < DATA_SIZE; ++k)
		if(sourceData[k] != receiveData[k]) ++errors;
	
	/* print errors to lcd */
	LCD_Char_1_PrintString("errors: ");
	LCD_Char_1_PrintNumber(errors);
	
	LCD_Char_1_Position(1,0);
	LCD_Char_1_PrintString("tx:");

	LCD_Char_1_PrintNumber(tx_cnt);
	LCD_Char_1_PrintString(" rx:");

	LCD_Char_1_PrintNumber(rx_cnt);

	for(;;){
	
    }
}
Example #2
0
/*******************************************************************************
* Function Name: UART_1_Wakeup
********************************************************************************
*
* Summary:
*  Restores and enables the user configuration. Should be called
*  just after awaking from sleep.
*
* Parameters:
*  None.
*
* Return:
*  None.
*
* Global Variables:
*  UART_1_backup - used when non-retention registers are restored.
*
* Reentrant:
*  No.
*
*******************************************************************************/
void UART_1_Wakeup(void)
{
    UART_1_RestoreConfig();
    #if( (UART_1_RX_ENABLED) || (UART_1_HD_ENABLED) )
        UART_1_ClearRxBuffer();
    #endif /* End (UART_1_RX_ENABLED) || (UART_1_HD_ENABLED) */
    #if(UART_1_TX_ENABLED || UART_1_HD_ENABLED)
        UART_1_ClearTxBuffer();
    #endif /* End UART_1_TX_ENABLED || UART_1_HD_ENABLED */

    if(UART_1_backup.enableState != 0u)
    {
        UART_1_Enable();
    } 
}
void main(){
	/* initialize UART */
    UART_1_Start();
	
	/* disable interrupts */
	UART_1_DisableRxInt();
	UART_1_DisableTxInt();
	
	UART_1_ClearTxBuffer();
	UART_1_ClearRxBuffer();
	
	LCD_Char_1_Start();
	LCD_Char_1_Position(0,0);
	
	/* initialize or source array */
	int j;
	for(j = 0; j < DATA_SIZE; ++j){
		sourceData[j] = j;
	}
	
	/* loop to transmit all 4096 bytes of our source array */
	int i;
	for(i = 0; i < DATA_SIZE; ++i){
		UART_1_WriteTxData(sourceData[i]);
		
		/* we check the receiver FIFO to see when we get the data */
		while(UART_1_ReadRxStatus() != UART_1_RX_STS_FIFO_NOTEMPTY){}
		
		/* if FIFO is not empty, save the data */
		receiveData[i] = UART_1_ReadRxData();
	}
 
 	int k;
	int errors = 0;
	/* loop through received data to verify it */
	for(k = 0; k < DATA_SIZE; ++k)
		if(sourceData[k] != receiveData[k]) ++errors;
	
	/* print errors */
	LCD_Char_1_PrintString("errors: ");
	LCD_Char_1_PrintNumber(errors);
	for(;;){
	
    }
}