UART1 to UART2 bridge on nanoWipom board


Establishes a bridge connection between UART1 and UART2.

Toolkit:STM Development System

Location:/bipom/devtools/STM32/examples/nanoWipom/uart1_to_uart2_bridge

Code Example


int main(void) 
{
	UCB uart1,uart2;
	int dataInt,len;
	UBYTE dataByte;
	ERRCODE ec=SUCCESS;
	/* Initialize all port pins */
	NWDIO_Init();
	
	delayMs(250);
		
	/* Reset modem */
	NWDIO_ModemReset();
	/* Send messages to TERMINAL window */
	tprintf("\n\rNanoWipom %s %s",__DATE__,__TIME__);
	tprintf("\n\rMODEM TEST REV 1.01");
	delayMs(200);
	/* Initialize UART1 interface (native UART1 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 = NULL;
	//

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

	uart2.parity		= SERIALAPI_PARITY_NO;						// uart parity

	uart2.stop			= SERIALAPI_STOP_1;							// uart stop bit

	uart2.word_length	= SERIALAPI_WORLD_LENGTH_8;					// uart word length

	uart2.transferComplete = NULL;
	//

	ec = serialAPI_init(&uart2);
	if(ec) 
	{
		serialAPI_tiprintf(&uart1,"\r\nERROR: can't initialize UART2, ec = %d",ec);
		for(;;);	
	}
	serialAPI_tiprintf(&uart1,"\r\nuart2 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", 
					uart1.getRxCnt(),uart1.getTxCnt(),uart1.getErrors(),uart1.getOverflows());
				serialAPI_tiprintf(&uart1,"\n\rUART2: rx=%08lu tx=%08lu errors=%08lu overflows=%08lu", 
					uart2.getRxCnt(),uart2.getTxCnt(),uart2.getErrors(),uart2.getOverflows());
				continue; 
			}
			//

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

		dataInt = uart2.getData();
		if (dataInt != -1) 
		{	
			dataByte = dataInt;
			len = 1;
			while(uart1.getTxCounter());
			uart1.setFiFoData(&dataByte,len);
		}
	}
	//

	return 0;
}