UART3 DIO test on Wipom board


Serial API test to check SPI1, CS10, CH A interface (communication and DIO control).

Toolkit:STM Development System

Location:/bipom/devtools/STM32/examples/Wipom/uart3_dio

Code Example


int main (void)
{
	delayMs(250);

	ERRCODE ec;
	/* Send messages to TERMINAL window */
	tprintf("\n\rMini-Max/STM32F1");
	tprintf("\n\rMODEM TEST REV 1.01");
	/* Initialize Device Manager */
	DM_Init();
	/* 	Initialize SPI1 and register to Device Manager	*/
	SPI1_Init(SPI1_INTERFACE_TYPE,DEVICE_INTERFACE_IN_PROGRESS);
	//

	/* Initialize SPI/SC16IS76X/UART interface ( SPI1, CS10, CH A )*/
	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.rxFifo		= SERIALAPI_FIFO_8;							// uart RX FIFO trigger level

	uart3.txFifo		= SERIALAPI_FIFO_56;						// uart TX FIFO trigger level

	//SPI1/SC16IS760

	uart3.clock			= SC16IS7XX_SPI_CLOCK;						// SPI clock = 1MHz

	uart3.iface			= SERIALAPI_SPI1_INTERFACE;					// SPI1 interface

	uart3.channel 		= CHANNEL_A;								// Channel A of sc16is76x chip 

	// GPIO

	uart3.gpioDir		= 0xE3;										// All outputs

	uart3.gpioState		= 0;
	// RTS

	uart3.rts			= SC16IS7XX_LOW_RTS;
	//

	// Define Rx/Tx buffers

	uart3.rxBuffer		= uart3_rxBuffer;
	uart3.rxLen			= sizeof(uart3_rxBuffer);
	uart3.txBuffer		= uart3_txBuffer;
	uart3.txLen			= sizeof(uart3_txBuffer);
	//

	ec = serialspi1cs10chA_init(&uart3);
	if(ec) goto func_end;
	tprintf("\r\nuart3 init is OK");
	//

	/* Initialize INT_ARM interrupts */
	INT_ARM_Init();
	/* Register INT ARM interface  to Device Manager as a part of SPI2 interfcace */
	INT_ARM_RegisterInterface(&spi1_int_arm);
	spi1_int_arm.iFaceType 	= SPI1_INTERFACE_TYPE;
	spi1_int_arm.iFaceState	= DEVICE_INTERFACE_PROCESS_REQUEST;
	spi1_int_arm.process	= DM_Process;
	/* Run the bridge  */
	tprintf("\r\n>");
	ec = SC16IS76X_Bridge();
	//

func_end:	
	tprintf("\r\nEND, ec =%d",ec);
	return 0;
}

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

ERRCODE SC16IS76X_Bridge(void)
{
	ERRCODE ec=SUCCESS;
	int dataInt=-1;
	int restart_cnt=0;
	UINT len=1;
	UBYTE dataByte;
	UINT status;
	
	//

	// uart3.write(SC16IS762_IOSTATE,0xFF);

	// while(uart3.getStatus());

	for (;;)
	{
		// try to get data byte from uart0

		{
			dataInt = getChar();
			if(dataInt != -1 ) 
			{
				dataByte = dataInt;
				// Check if we have available space to send data

				//if (uart3.isTxFiFoAvailable(len))

				while(uart3.getTxCounter());
				uart3.setFiFoData(&dataByte,len);
				// Check 

				if(dataInt == '-')
				{ 
					//delayMs(500);

					if (++restart_cnt == 3) 
					{
						restart_cnt =0;
						tprintf("\r\nRestart...");
						uart3.write(SC16IS762_IOSTATE,0x00);
						do
						{
							status = uart3.getStatus();
							tprintf("\r\nW0status=%d",status);
						}while(status);
						//

						// Read GPIO register

						uart3.read(SC16IS762_IOSTATE);
						do
						{
							status = uart3.getStatus();
							tprintf("\r\nR0status=%d",status);
						}while(status);
						tprintf("\n\rUART3 IOSTATE =0x%02x", uart3.getValue());
						//

						delayMs(100);
						uart3.write(SC16IS762_IOSTATE,0x02);
						do
						{
							status = uart3.getStatus();
							tprintf("\r\nW1status=%d",status);
						}while(status);
						//

						tprintf("\r\nRESTART OK");
					}
				}
				else
				{
					restart_cnt =0;
				}		
			}
		}
		// try to get data byte from uart3

		if (uart3.getRxCounter())
		{
			dataInt = uart3.getData();
			if (dataInt != -1) 
			{
				dataByte = dataInt;
				putChar(dataByte);
			}		
		}
	}
	return ec;
}