USART3 TEST


USART1 to USART3 Bridge.

Toolkit:STM Development System

Location:/bipom/devtools/STM32/examples/usart3

Code Example


UCB uart1;
int TComplete1 = 0;

UCB uart3;
int TComplete3 = 0;

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

int main (void)
{
	delayMs(250);
	
	int dataInt,len;
	UBYTE dataByte;
	ERRCODE ec=SUCCESS;
	/* Send messages to TERMINAL window */
	tprintf("\n\rMini-Max/STM32F1");
	tprintf("\n\rUSART3 TEST REV 1.01");
	delayMs(200);
	/* Initialize USART1 interface (native USART1 port)*/
	uart1.iface			= SERIALAPI_UART1_INTERFACE;
	uart1.baudRate		= 115200;									// uart baudrate

	uart1.parity		= SERIALAPI_PARITY_NO;						// uart parity

	uart1.stop			= SERIALAPI_STOP_1;							// uart stop bit

	uart1.word_length	= SERIALAPI_WORLD_LENGTH_8;					// uart word length

	uart1.transferComplete = TransferComplete1;
	//

	ec = serialAPI_init(&uart1);
	if(ec) 
	{
		tprintf("\r\nERROR: can't initialize USART1, ec = %d",ec);
		for(;;);	
	}
	serialAPI_tiprintf(&uart1,"\r\nuart1 init is OK");
	delayMs(200);
	/* Initialize USART3 interface (native USART3 port)*/
	uart3.iface			= SERIALAPI_UART3_INTERFACE;
	uart3.baudRate		= 115200;									// uart baudrate

	uart3.parity		= SERIALAPI_PARITY_NO;						// uart parity

	uart3.stop			= SERIALAPI_STOP_1;							// uart stop bit

	uart3.word_length	= SERIALAPI_WORLD_LENGTH_8;					// uart word length

	uart3.transferComplete = TransferComplete3;
	//

	ec = serialAPI_init(&uart3);
	if(ec) 
	{
		serialAPI_tiprintf(&uart1,"\r\nERROR: can't initialize USART3, ec = %d",ec);
		for(;;);	
	}
	serialAPI_tiprintf(&uart1,"\r\nuart3 init is OK");
	//

	/* Run the loop back test  */
	serialAPI_tiprintf(&uart1,"\r\nPress '?' to get statistics");
	serialAPI_tiprintf(&uart1,"\r\n>");
	for (;;)
	{
		dataInt = uart1.getData();
		if (dataInt != -1) 
		{	
			if(dataInt == '?')
			{
				// Print statistics

				serialAPI_tiprintf(&uart1,"\n\rUART1: rx=%08lu tx=%08lu errors=%08lu overflows=%08lu tc=%08lu", 
					uart1.getRxCnt(),uart1.getTxCnt(),uart1.getErrors(),uart1.getOverflows(),TComplete1);
				serialAPI_tiprintf(&uart1,"\n\rUART3: rx=%08lu tx=%08lu errors=%08lu overflows=%08lu tc=%08lu", 
					uart3.getRxCnt(),uart3.getTxCnt(),uart3.getErrors(),uart3.getOverflows(),TComplete3);
				continue; 
			}
			//

			dataByte = dataInt;
			len = 1;
			while(uart3.getTxCounter());
			uart3.setFiFoData(&dataByte,len);
		}
		//

		#if 1
		dataInt = uart3.getData();
		if (dataInt != -1) 
		{	
			dataByte = dataInt;
			len = 1;
			while(uart1.getTxCounter());
			uart1.setFiFoData(&dataByte,len);
		}
		#endif
	}
	return 0;
}

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

void TransferComplete1(void)
{
	TComplete1++;
}

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

void TransferComplete3(void)
{
	TComplete3++;
}