/*---------------------------------------------------------------------------------------------------------*/ void AutoFlow_FunctionTest() { uint8_t u8Item; uint32_t u32i; printf("+-----------------------------------------------------------+\n"); printf("| Pin Configure |\n"); printf("+-----------------------------------------------------------+\n"); printf("| _______ _______ |\n"); printf("| | | | | |\n"); printf("| |Master |---TXD0(pin46) <====> RXD0(pin45)---| Slave | |\n"); printf("| | |---RTS0(pin37) <====> CTS0(pin38)---| | |\n"); printf("| |_______|---CTS0(pin38) <====> RTS0(pin37)---|_______| |\n"); printf("| |\n"); printf("+-----------------------------------------------------------+\n\n"); /* Set RTS Trigger Level */ UART->MCR |= UART_RTS_IS_HIGH_LEV_TRG; UART->FCR = (UART->FCR &~ UART_FCR_RTS_TRI_LEV_Msk) | UART_FCR_RTS_TRI_LEV_14BYTES; /* Enable RTS and CTS autoflow control */ UART->IER |= UART_IER_AUTO_RTS_EN_Msk | UART_IER_AUTO_CTS_EN_Msk; printf("+-----------------------------------------------------------+\n"); printf("| AutoFlow Function Test |\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("| Please select Master or Slave test |\n"); printf("| [0] Master [1] Slave |\n"); printf("+-----------------------------------------------------------+\n\n"); u8Item = getchar(); if(u8Item=='0') { for(u32i=0;u32i<(RXBUFSIZE-1);u32i++) { UART_WRITE(UART,((u32i+1)&0xFF)); /* Slave will control RTS pin*/ while(UART->MCR & UART_MCR_RTS_ST_Msk); } printf("\n Transmit Done\n"); } else { g_i32pointer = 0; /* Enable RDA\RLS\RTO Interrupt */ UART_ENABLE_INT(UART, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk)); /* Set RX Trigger Level = 8 */ UART->FCR = (UART->FCR &~ UART_FCR_RFITL_Msk) | UART_FCR_RFITL_8BYTES; /* Set Timeout time 0x3E bit-time */ UART_SetTimeoutCnt(UART,0x3E); NVIC_EnableIRQ(UART_IRQn); printf("Starting to recevice %d bytes data...\n", RXBUFSIZE); while(g_i32pointer<(RXBUFSIZE-1)) { printf("%d\r",g_i32pointer); } /* Compare Data */ for(u32i=0;u32i!=(RXBUFSIZE-1);u32i++) { if(g_u8RecData[u32i] != ((u32i+1)&0xFF) ) { printf("Compare Data Failed\n"); while(1); } } printf("\n Receive OK & Check OK\n"); } NVIC_DisableIRQ(UART_IRQn); UART_DISABLE_INT(UART, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk)); }
/*---------------------------------------------------------------------------------------------------------*/ 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)); }