/*---------------------------------------------------------------------------------------------------------*/ void AutoFlow_FunctionTxTest() { uint32_t u32i; printf("\n"); printf("+-----------------------------------------------------------+\n"); printf("| Pin Configure |\n"); printf("+-----------------------------------------------------------+\n"); printf("| ______ _____ |\n"); printf("| | | | | |\n"); printf("| |Master|--UART1_TXD(PB.3) <==> UART1_RXD(PB.2)--|Slave| |\n"); printf("| | |--UART1_nCTS(PB.4) <==> UART1_nRTS(PB.8)--| | |\n"); printf("| |______| |_____| |\n"); printf("| |\n"); printf("+-----------------------------------------------------------+\n"); printf("\n"); printf("+-----------------------------------------------------------+\n"); printf("| AutoFlow Function Test (Master) |\n"); printf("+-----------------------------------------------------------+\n"); printf("| Description : |\n"); printf("| The sample code needs two boards. One is Master and |\n"); printf("| the other is slave. Master will send 1k bytes data |\n"); printf("| to slave. Slave will check if received data is correct |\n"); printf("| after getting 1k bytes data. |\n"); printf("| Press any key to start... |\n"); printf("+-----------------------------------------------------------+\n"); GetChar(); /* Enable RTS and CTS autoflow control */ UART_EnableFlowCtrl(UART1); /* Send 1k bytes data */ for(u32i = 0; u32i < RXBUFSIZE; u32i++) { /* Send 1 byte data */ UART_WRITE(UART1, u32i & 0xFF); /* Wait if Tx FIFO is full */ while(UART_IS_TX_FULL(UART1)); } printf("\n Transmit Done\n"); }
/*---------------------------------------------------------------------------------------------------------*/ void AutoFlow_FunctionRxTest() { uint32_t u32i; printf("\n"); printf("+-----------------------------------------------------------+\n"); printf("| Pin Configure |\n"); printf("+-----------------------------------------------------------+\n"); printf("| ______ _____ |\n"); printf("| | | | | |\n"); printf("| |Master|--UART1_TXD(PB.5) <==> UART1_RXD(PB.4)--|Slave| |\n"); printf("| | |--UART1_nCTS(PB.7) <==> UART1_nRTS(PB.6)--| | |\n"); printf("| |______| |_____| |\n"); printf("| |\n"); printf("+-----------------------------------------------------------+\n"); printf("\n"); printf("+-----------------------------------------------------------+\n"); printf("| AutoFlow Function Test (Slave) |\n"); printf("+-----------------------------------------------------------+\n"); printf("| Description : |\n"); printf("| The sample code needs two boards. One is Master and |\n"); printf("| the other is slave. Master will send 1k bytes data |\n"); printf("| to slave.Slave will check if received data is correct |\n"); printf("| after getting 1k bytes data. |\n"); printf("| Press any key to start... |\n"); printf("+-----------------------------------------------------------+\n"); GetChar(); /* Enable RTS and CTS autoflow control */ UART_EnableFlowCtrl(UART1); /* Set RTS Trigger Level as 8 bytes */ UART1->FCR &= ~UART_FCR_RTS_TRI_LEV_Msk; UART1->FCR |= UART_FCR_RTS_TRI_LEV_8BYTES; /* Set RX Trigger Level as 8 bytes */ UART1->FCR &= ~UART_FCR_RFITL_Msk; UART1->FCR |= UART_FCR_RFITL_8BYTES; /* Set Timeout time 0x3E bit-time and time-out counter enable */ UART_SetTimeoutCnt(UART1, 0x3E); /* Enable RDA\RLS\RTO Interrupt */ UART_EnableInt(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_TOUT_IEN_Msk)); printf("\n Starting to receive data...\n"); /* Wait for receive 1k bytes data */ while(g_i32pointer < RXBUFSIZE); /* Compare Data */ for(u32i = 0; u32i < RXBUFSIZE; u32i++) { if(g_u8RecData[u32i] != (u32i & 0xFF)) { printf("Compare Data Failed\n"); while(1); } } printf("\n Receive OK & Check OK\n"); /* Disable RDA\RLS\RTO Interrupt */ UART_DisableInt(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_TOUT_IEN_Msk)); }