Ejemplo n.º 1
0
/*---------------------------------------------------------------------------------------------------------*/
void UART_FunctionTest()
{
    printf("+-----------------------------------------------------------+\n");
    printf("|  UART Function Test                                       |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  Description :                                            |\n");
    printf("|    The sample code will print input char on terminal      |\n");
    printf("|    Please enter any to start     (Press '0' to exit)      |\n");
    printf("+-----------------------------------------------------------+\n");
   
    /*
        Using a RS232 cable to connect UART0 and PC.
        UART0 is set to debug port. UART0 is enable RDA and RLS interrupt.
        When inputing char to terminal screen, RDA interrupt will happen and         
        UART0 will print the received char on screen.
    */
   
    /* Enable Interrupt and install the call back function */
    _UART_ENABLE_INT(UART0, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
    NVIC_EnableIRQ(UART02_IRQn);
    while(g_bWait); 
        
    /* Disable Interrupt */
    _UART_DISABLE_INT(UART0, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
    NVIC_DisableIRQ(UART02_IRQn);
    g_bWait =TRUE;
    printf("\nUART Sample Demo End.\n");
        
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------------------------------------*/
void RS485_9bitModeSlave()
{
    /* Set Data Format*/ /* Only need parity enable whenver parity ODD/EVEN */
    _UART_SET_DATA_FORMAT(UART1, UART_WORD_LEN_8 | UART_PARITY_EVEN | UART_STOP_BIT_1);   

    /* Set RX Trigger Level = 1 */
    _UART_SET_RX_TRG_LEV(UART1,UART_FCR_RFITL_1BYTE);

    #if(IS_USE_RS485NMM == 1)
        printf("+-----------------------------------------------------------+\n");
        printf("|    Normal Multidrop Operation Mode                        |\n");
        printf("+-----------------------------------------------------------+\n");
        printf("| The function is used to test 9-bit slave mode.            |\n");
        printf("| Only Address %2x and %2x,data can receive                  |\n",MATCH_ADDRSS1,MATCH_ADDRSS2);
        printf("+-----------------------------------------------------------+\n");
        
        /* Set RX_DIS enable before set RS485-NMM mode */
        UART1->FCR |= UART_FCR_RX_DIS_Msk;
        
        /* Set RS485-NMM Mode */
        UART1->ALT_CSR = UART_ALT_CSR_RS485_NMM_Msk | 
                         UART_ALT_CSR_RS485_ADD_EN_Msk ;
    #else
        printf("Auto Address Match Operation Mode\n");
        printf("+-----------------------------------------------------------+\n");
        printf("| The function is used to test 9-bit slave mode.            |\n");
        printf("|    Auto Address Match Operation Mode                      |\n");
        printf("+-----------------------------------------------------------+\n");
        printf("|Only Address %2x,data can receive                          |\n",MATCH_ADDRSS1);
        printf("+-----------------------------------------------------------+\n");

        /* Set RS485-AAD Mode and address match is 0xC0 */
        UART1->ALT_CSR = UART_ALT_CSR_RS485_AAD_Msk    | 
                         UART_ALT_CSR_RS485_ADD_EN_Msk |     //ADD_EN is option. 
                         ((uint32_t)(MATCH_ADDRSS1)<< UART_ALT_CSR_ADDR_MATCH_Pos) ;
    #endif
    /* Set RS485 Function */
    _UART_SEL_FUNC(UART1,UART_FUNC_SEL_RS485);

    /* Enable RDA\RLS\Time-out Interrupt  */
    _UART_ENABLE_INT(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_RTO_IEN_Msk));
    NVIC_EnableIRQ(UART1_IRQn);

    printf("Ready to recevice data...(Press any key to stop test)\n");
    GetChar();
    
    /* Flush FIFO */
    _UART_FLUSH_FIFO(UART1,UART_FCR_TFR_Msk|UART_FCR_RFR_Msk);

    _UART_DISABLE_INT(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RLS_IEN_Msk | UART_IER_RTO_IEN_Msk));     

    /* Set UART Function */
    _UART_SEL_FUNC(UART1,UART_FUNC_SEL_UART);
    printf("\n\nEnd test\n");
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------------------------------------*/
void AutoFlow_FunctionTest()
{
    uint8_t u8Item;
    uint32_t u32i;
    printf("+-----------------------------------------------------------+\n");
    printf("|     Pin Configure                                         |\n");
    printf("+-----------------------------------------------------------+\n");
    printf("|  _______                                      _______     |\n");
    printf("| |       |                                    |       |    |\n");  
    printf("| |Master |---TXD1(pin46) <====> RXD1(pin45)---| Slave |    |\n");  
    printf("| |       |---RTS1(pin39) <====> CTS1(pin40)---|       |    |\n");  
    printf("| |_______|---CTS1(pin40) <====> RTS1(pin39)---|_______|    |\n");  
    printf("|                                                           |\n");
    printf("+-----------------------------------------------------------+\n\n");  

    /* Set RTS Trigger Level */
    UART_SetRTS_TrgLev(UART1,UART_RTS_IS_HIGH_LEV_TRG,UART_FCR_RTS_TRI_LEV_14BYTES);
    
    /* Enable RTS and CTS autoflow control */
    UART1->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_SENDBYTE(UART1,((u32i+1)&0xFF));

            /* Slave will control RTS pin*/
            while(_UART_GET_RTSPIN(UART1));
        }
        printf("\n Transmit Done\n");
    }
    else
    {
        g_i32pointer = 0;
    
        /* Enable RDA\RLS\RTO Interrupt  */
        _UART_ENABLE_INT(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));

        /* Set RX Trigger Level = 8 */
        _UART_SET_RX_TRG_LEV(UART1,UART_FCR_RFITL_8BYTES);

        /* Set Timeout time 0x3E bit-time */
        UART_SetTimeOutCounter(UART1,0x3E);
        
        NVIC_EnableIRQ(UART1_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(UART1_IRQn);

    _UART_DISABLE_INT(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
}