[技术问答]

M051 UART

[复制链接]
3088|18
手机看帖
扫描二维码
随时随地手机跟帖
fangyi999|  楼主 | 2017-6-25 22:48 | 显示全部楼层 |阅读模式
各位大神,本人刚开始使用新塘芯片M051系列, 现发现个问题,M051的UART没有TX和RX的使能位的吗?谢谢!
coldfish522| | 2017-6-26 00:01 | 显示全部楼层
有的,你看看寄存器的PDF

使用特权

评论回复
a_ziliu| | 2017-6-26 09:20 | 显示全部楼层

使用特权

评论回复
fangyi999|  楼主 | 2017-6-26 15:15 | 显示全部楼层
coldfish522 发表于 2017-6-26 00:01
有的,你看看寄存器的PDF

在手册中没有看到TX和RX的使能控制位。

使用特权

评论回复
fangyi999|  楼主 | 2017-6-26 15:16 | 显示全部楼层
coldfish522 发表于 2017-6-26 00:01
有的,你看看寄存器的PDF

在手册中没有看到TX和RX的使能控制位。

使用特权

评论回复
643757107| | 2017-6-26 19:05 | 显示全部楼层
你可以去下载库函数BSP,然后找到相关库函数,看看里面有没有这个相关操作。

使用特权

评论回复
643757107| | 2017-6-26 19:14 | 显示全部楼层
/****************************************************************************
* [url=home.php?mod=space&uid=288409]@file[/url]     main.c
* [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
* $Revision: 7 $
* $Date: 15/05/22 3:53p $
* [url=home.php?mod=space&uid=247401]@brief[/url]    Transmit and receive data from PC terminal through RS232 interface.
*
* @note
* Copyright (C) 2011 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "M051Series.h"


#define PLL_CLOCK           50000000

#define RXBUFSIZE 1024

/*---------------------------------------------------------------------------------------------------------*/
/* Global variables                                                                                        */
/*---------------------------------------------------------------------------------------------------------*/
uint8_t g_u8RecData[RXBUFSIZE]  = {0};

volatile uint32_t g_u32comRbytes = 0;
volatile uint32_t g_u32comRhead  = 0;
volatile uint32_t g_u32comRtail  = 0;
volatile int32_t g_bWait         = TRUE;

/*---------------------------------------------------------------------------------------------------------*/
/* Define functions prototype                                                                              */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void);
void UART_TEST_HANDLE(void);
void UART_FunctionTest(void);


void SYS_Init(void)
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init System Clock                                                                                       */
    /*---------------------------------------------------------------------------------------------------------*/

    /* Enable Internal RC 22.1184MHz clock */
    CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);

    /* Waiting for Internal RC clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);

    /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));

    /* Enable external XTAL 12MHz clock */
    CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);

    /* Waiting for external XTAL clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);

    /* Set core clock as PLL_CLOCK from PLL */
    CLK_SetCoreClock(PLL_CLOCK);

    /* Enable UART module clock */
    CLK_EnableModuleClock(UART0_MODULE);

    /* Select UART module clock source */
    CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));

    /*---------------------------------------------------------------------------------------------------------*/
    /* Init I/O Multi-function                                                                                 */
    /*---------------------------------------------------------------------------------------------------------*/

    /* Set P3 multi-function pins for UART0 RXD and TXD */
    SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk);
    SYS->P3_MFP |= (SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0);

}

void UART0_Init()
{
    /*---------------------------------------------------------------------------------------------------------*/
    /* Init UART                                                                                               */
    /*---------------------------------------------------------------------------------------------------------*/
    /* Reset UART0 */
    SYS_ResetModule(UART0_RST);

    /* Configure UART0 and set UART0 Baudrate */
    UART_Open(UART0, 115200);
}

/*---------------------------------------------------------------------------------------------------------*/
/* UART Test Sample                                                                                        */
/* Test Item                                                                                               */
/* It sends the received data to HyperTerminal.                                                            */
/*---------------------------------------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function                                                                                           */
/*---------------------------------------------------------------------------------------------------------*/

int main(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    /* Init UART0 for printf and testing */
    UART0_Init();

    /*---------------------------------------------------------------------------------------------------------*/
    /* SAMPLE CODE                                                                                             */
    /*---------------------------------------------------------------------------------------------------------*/

    printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);

    printf("\n\nUART Sample Program\n");

    /* UART sample function */
    UART_FunctionTest();
   
    while(1);

}

/*---------------------------------------------------------------------------------------------------------*/
/* ISR to handle UART Channel 0 interrupt event                                                            */
/*---------------------------------------------------------------------------------------------------------*/
void UART0_IRQHandler(void)
{
    UART_TEST_HANDLE();
}

/*---------------------------------------------------------------------------------------------------------*/
/* UART Callback function                                                                                  */
/*---------------------------------------------------------------------------------------------------------*/
void UART_TEST_HANDLE()
{
    uint8_t u8InChar = 0xFF;
    uint32_t u32IntSts = UART0->ISR;

    if(u32IntSts & UART_ISR_RDA_INT_Msk)
    {
        printf("\nInput:");

        /* Get all the input characters */
        while(UART_IS_RX_READY(UART0))
        {
            /* Get the character from UART Buffer */
            u8InChar = UART_READ(UART0);

            printf("%c ", u8InChar);

            if(u8InChar == '0')
            {
                g_bWait = FALSE;
            }

            /* Check if buffer full */
            if(g_u32comRbytes < RXBUFSIZE)
            {
                /* Enqueue the character */
                g_u8RecData[g_u32comRtail] = u8InChar;
                g_u32comRtail = (g_u32comRtail == (RXBUFSIZE - 1)) ? 0 : (g_u32comRtail + 1);
                g_u32comRbytes++;
            }
        }
        printf("\nTransmission Test:");
    }

    if(u32IntSts & UART_ISR_THRE_INT_Msk)
    {
        uint16_t tmp;
        tmp = g_u32comRtail;
        if(g_u32comRhead != tmp)
        {
            u8InChar = g_u8RecData[g_u32comRhead];
            while(UART_IS_TX_FULL(UART0));  /* Wait Tx is not full to transmit data */            
            UART_WRITE(UART0, u8InChar);
            g_u32comRhead = (g_u32comRhead == (RXBUFSIZE - 1)) ? 0 : (g_u32comRhead + 1);
            g_u32comRbytes--;
        }
    }
}


/*---------------------------------------------------------------------------------------------------------*/
/*  UART Function Test                                                                                     */
/*---------------------------------------------------------------------------------------------------------*/
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(UART0_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(UART0_IRQn);
    g_bWait = TRUE;
    printf("\nUART Sample Demo End.\n");

}

使用特权

评论回复
643757107| | 2017-6-26 19:15 | 显示全部楼层
/**************************************************************************//**
* @file     UART.h
* @version  V3.00
* $Revision: 23 $
* $Date: 15/05/29 4:19p $
* @brief    M051 series UART driver header file
*
* @note
* Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
*****************************************************************************/
#ifndef __UART_H__
#define __UART_H__


#ifdef __cplusplus
extern "C"
{
#endif


/** @addtogroup Standard_Driver Standard Driver
  @{
*/

/** @addtogroup UART_Driver UART Driver
  @{
*/

/** @addtogroup UART_EXPORTED_CONSTANTS UART Exported Constants
  @{
*/

/*---------------------------------------------------------------------------------------------------------*/
/* UART FIFO size constants definitions                                                                    */
/*---------------------------------------------------------------------------------------------------------*/

#define UART0_FIFO_SIZE 16 /*!< UART0 supports separated receive/transmit 16/16 bytes entry FIFO */
#define UART1_FIFO_SIZE 16 /*!< UART1 supports separated receive/transmit 16/16 bytes entry FIFO */   
   
/*---------------------------------------------------------------------------------------------------------*/
/* UA_FCR constants definitions                                                                            */
/*---------------------------------------------------------------------------------------------------------*/

#define UART_FCR_RFITL_1BYTE        (0x0 << UART_FCR_RFITL_Pos)   /*!< UA_FCR setting to set RX FIFO Trigger Level to 1 byte */
#define UART_FCR_RFITL_4BYTES       (0x1 << UART_FCR_RFITL_Pos)   /*!< UA_FCR setting to set RX FIFO Trigger Level to 4 bytes */
#define UART_FCR_RFITL_8BYTES       (0x2 << UART_FCR_RFITL_Pos)   /*!< UA_FCR setting to set RX FIFO Trigger Level to 8 bytes */
#define UART_FCR_RFITL_14BYTES      (0x3 << UART_FCR_RFITL_Pos)   /*!< UA_FCR setting to set RX FIFO Trigger Level to 14 bytes */

#define UART_FCR_RTS_TRI_LEV_1BYTE        (0x0 << UART_FCR_RTS_TRI_LEV_Pos)  /*!< UA_FCR setting to set RTS Trigger Level to 1 byte */
#define UART_FCR_RTS_TRI_LEV_4BYTES       (0x1 << UART_FCR_RTS_TRI_LEV_Pos)  /*!< UA_FCR setting to set RTS Trigger Level to 4 bytes */
#define UART_FCR_RTS_TRI_LEV_8BYTES       (0x2 << UART_FCR_RTS_TRI_LEV_Pos)  /*!< UA_FCR setting to set RTS Trigger Level to 8 bytes */
#define UART_FCR_RTS_TRI_LEV_14BYTES      (0x3 << UART_FCR_RTS_TRI_LEV_Pos)  /*!< UA_FCR setting to set RTS Trigger Level to 14 bytes */

/*---------------------------------------------------------------------------------------------------------*/
/* UA_LCR constants definitions                                                                            */
/*---------------------------------------------------------------------------------------------------------*/
#define UART_WORD_LEN_5        (0) /*!< UA_LCR setting to set UART word length to 5 bits */
#define UART_WORD_LEN_6        (1) /*!< UA_LCR setting to set UART word length to 6 bits */
#define UART_WORD_LEN_7        (2) /*!< UA_LCR setting to set UART word length to 7 bits */
#define UART_WORD_LEN_8        (3) /*!< UA_LCR setting to set UART word length to 8 bits */

#define UART_PARITY_NONE    (0x0 << UART_LCR_PBE_Pos) /*!< UA_LCR setting to set UART as no parity   */
#define UART_PARITY_ODD     (0x1 << UART_LCR_PBE_Pos) /*!< UA_LCR setting to set UART as odd parity  */
#define UART_PARITY_EVEN    (0x3 << UART_LCR_PBE_Pos) /*!< UA_LCR setting to set UART as even parity */
#define UART_PARITY_MARK    (0x5 << UART_LCR_PBE_Pos) /*!< UA_LCR setting to keep parity bit as '1'  */
#define UART_PARITY_SPACE   (0x7 << UART_LCR_PBE_Pos) /*!< UA_LCR setting to keep parity bit as '0'  */

#define UART_STOP_BIT_1     (0x0 << UART_LCR_NSB_Pos) /*!< UA_LCR setting for one stop bit  */
#define UART_STOP_BIT_1_5   (0x1 << UART_LCR_NSB_Pos) /*!< UA_LCR setting for 1.5 stop bit when 5-bit word length  */
#define UART_STOP_BIT_2     (0x1 << UART_LCR_NSB_Pos) /*!< UA_LCR setting for two stop bit when 6, 7, 8-bit word length */


/*---------------------------------------------------------------------------------------------------------*/
/* UART RTS LEVEL TRIGGER constants definitions                                                            */
/*---------------------------------------------------------------------------------------------------------*/
#define UART_RTS_IS_LOW_LEV_ACTIVE    (0x1 << UART_MCR_LEV_RTS_Pos) /*!< Set RTS is Low Level Active */
#define UART_RTS_IS_HIGH_LEV_ACTIVE   (0x0 << UART_MCR_LEV_RTS_Pos) /*!< Set RTS is High Level Active */

/*---------------------------------------------------------------------------------------------------------*/
/* UA_IRCR constants definitions                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
#define UART_IRCR_TX_SELECT         (0x1 << UART_IRCR_TX_SELECT_Pos) /*!< Set IrDA function Tx mode */
#define UART_IRCR_RX_SELECT         (0x0 << UART_IRCR_TX_SELECT_Pos) /*!< Set IrDA function Rx mode */

/*---------------------------------------------------------------------------------------------------------*/
/* UA_FUNC_SEL constants definitions                                                                       */
/*---------------------------------------------------------------------------------------------------------*/
#define UART_FUNC_SEL_UART    (0x0 << UART_FUN_SEL_FUN_SEL_Pos) /*!< UA_FUNC_SEL setting to set UART Function  (Default) */
#define UART_FUNC_SEL_LIN     (0x1 << UART_FUN_SEL_FUN_SEL_Pos) /*!< UA_FUNC_SEL setting to set LIN Function             */
#define UART_FUNC_SEL_IrDA    (0x2 << UART_FUN_SEL_FUN_SEL_Pos) /*!< UA_FUNC_SEL setting to set IrDA Function            */
#define UART_FUNC_SEL_RS485   (0x3 << UART_FUN_SEL_FUN_SEL_Pos) /*!< UA_FUNC_SEL setting to set RS485 Function           */

/*---------------------------------------------------------------------------------------------------------*/
/* UART BAUDRATE MODE constants definitions                                                                       */
/*---------------------------------------------------------------------------------------------------------*/
#define UART_BAUD_MODE0     (0) /*!< Set UART Baudrate Mode is Mode0 */
#define UART_BAUD_MODE2     (UART_BAUD_DIV_X_EN_Msk | UART_BAUD_DIV_X_ONE_Msk) /*!< Set UART Baudrate Mode is Mode2 */



/*@}*/ /* end of group UART_EXPORTED_CONSTANTS */


/** @addtogroup UART_EXPORTED_FUNCTIONS UART Exported Functions
  @{
*/


/**
*    @brief        Calculate UART baudrate mode0 divider
*
*    @param[in]    u32SrcFreq      UART clock frequency
*    @param[in]    u32BaudRate     Baudrate of UART module
*
*    [url=home.php?mod=space&uid=266161]@return[/url]       UART baudrate mode0 divider
*
*    [url=home.php?mod=space&uid=1543424]@Details[/url]      This macro calculate UART baudrate mode0 divider.
*/
#define UART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate)    ((((u32SrcFreq) + ((u32BaudRate)*8)) / (u32BaudRate) >> 4)-2)

/**
*    @brief        Calculate UART baudrate mode2 divider
*
*    @param[in]    u32SrcFreq      UART clock frequency
*    @param[in]    u32BaudRate     Baudrate of UART module
*
*    @return       UART baudrate mode2 divider
*
*    @details      This macro calculate UART baudrate mode2 divider.
*/
#define UART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate)    ((((u32SrcFreq) + ((u32BaudRate)/2)) / (u32BaudRate))-2)


/**
*    @brief        Write data
*
*    @param[in]    uart    The pointer of the specified UART module
*    @param[in]    u8Data  Data byte to transmit
*
*    @return       None
*
*    @details      This macro write Data to Tx data register.
*/
#define UART_WRITE(uart, u8Data)    ((uart)->THR = (u8Data))


/**
*    @brief        Read data
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @return       The oldest data byte in RX FIFO
*
*    @details      This macro read Rx data register.
*/
#define UART_READ(uart)    ((uart)->RBR)


/**
*    @brief        Get Tx empty
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @retval       0   Tx FIFO is not empty
*    @retval       >=1 Tx FIFO is empty
*
*    @details      This macro get Tx empty register value.
*/
#define UART_GET_TX_EMPTY(uart)    ((uart)->FSR & UART_FSR_TX_EMPTY_Msk)


/**
*    @brief        Get Rx empty
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @retval       0   Rx FIFO is not empty
*    @retval       >=1 Rx FIFO is empty
*
*    @details      This macro get Rx empty register value.
*/
#define UART_GET_RX_EMPTY(uart)    ((uart)->FSR & UART_FSR_RX_EMPTY_Msk)

/**
*    @brief        Check specified uart port transmission is over.
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @retval       0   Transmission is not over.
*    @retval       1   Transmission is over.
*
*    @details      This macro return if Tx FIFO is empty and specified uart port transmission is over nor not.
*/
#define UART_IS_TX_EMPTY(uart)    (((uart)->FSR & UART_FSR_TE_FLAG_Msk) >> UART_FSR_TE_FLAG_Pos)


/**
*    @brief        Wait specified uart port transmission is over
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @return       None
*
*    @details      This macro wait specified uart port transmission is over.
*/
#define UART_WAIT_TX_EMPTY(uart)    while(!((((uart)->FSR) & UART_FSR_TE_FLAG_Msk) >> UART_FSR_TE_FLAG_Pos))

/**
*    @brief        Check RX is ready or not
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @retval       0 The number of bytes in the RX FIFO is less than the RFITL
*    @retval       1 The number of bytes in the RX FIFO equals or larger than RFITL
*
*    @details      This macro check receive data available interrupt flag is set or not.
*/
#define UART_IS_RX_READY(uart)    (((uart)->ISR & UART_ISR_RDA_IF_Msk)>>UART_ISR_RDA_IF_Pos)


/**
*    @brief        Check TX FIFO is full or not
*
*    @param[in]    uart   The pointer of the specified UART module
*
*    @retval       1 TX FIFO is full
*    @retval       0 TX FIFO is not full
*
*    @details      This macro check TX FIFO is full or not.
*/
#define UART_IS_TX_FULL(uart)    (((uart)->FSR & UART_FSR_TX_FULL_Msk)>>UART_FSR_TX_FULL_Pos)

/**
*    @brief        Check RX FIFO is full or not
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @retval       1 RX FIFO is full
*    @retval       0 RX FIFO is not full
*
*    @details      This macro check RX FIFO is full or not.
*/
#define UART_IS_RX_FULL(uart)    (((uart)->FSR & UART_FSR_RX_FULL_Msk)>>UART_FSR_RX_FULL_Pos)


/**
*    @brief        Get Tx full register value
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @retval       0   Tx FIFO is not full.
*    @retval       >=1 Tx FIFO is full.
*
*    @details      This macro get Tx full register value.
*/
#define UART_GET_TX_FULL(uart)    ((uart)->FSR & UART_FSR_TX_FULL_Msk)


/**
*    @brief        Get Rx full register value
*
*    @param[in]    uart   The pointer of the specified UART module
*
*    @retval       0   Rx FIFO is not full.
*    @retval       >=1 Rx FIFO is full.
*
*    @details      This macro get Rx full register value.
*/
#define UART_GET_RX_FULL(uart)    ((uart)->FSR & UART_FSR_RX_FULL_Msk)



/**
*    @brief        Enable specified UART interrupt
*
*    @param[in]    uart        The pointer of the specified UART module
*    @param[in]    u32eIntSel  Interrupt type select
*                              - UART_IER_LIN_RX_BRK_IEN_Msk  : Lin bus Rx break field interrupt
*                              - UART_IER_WAKE_EN_Msk         : Wakeup interrupt
*                              - UART_IER_BUF_ERR_IEN_Msk     : Buffer Error interrupt
*                              - UART_IER_RTO_IEN_Msk         : Rx time-out interrupt
*                              - UART_IER_MODEM_IEN_Msk       : Modem interrupt
*                              - UART_IER_RLS_IEN_Msk         : Rx Line status interrupt
*                              - UART_IER_THRE_IEN_Msk        : Tx empty interrupt
*                              - UART_IER_RDA_IEN_Msk         : Rx ready interrupt
*
*    @return       None
*
*    @details      This macro enable specified UART interrupt.
*/
#define UART_ENABLE_INT(uart, u32eIntSel)    ((uart)->IER |= (u32eIntSel))


/**
*    @brief        Disable specified UART interrupt
*
*    @param[in]    uart        The pointer of the specified UART module
*    @param[in]    u32eIntSel  Interrupt type select
*                              - UART_IER_LIN_RX_BRK_IEN_Msk  : Lin bus Rx break field interrupt
*                              - UART_IER_WAKE_EN_Msk         : Wakeup interrupt
*                              - UART_IER_BUF_ERR_IEN_Msk     : Buffer Error interrupt
*                              - UART_IER_RTO_IEN_Msk         : Rx time-out interrupt
*                              - UART_IER_MODEM_IEN_Msk       : Modem interrupt
*                              - UART_IER_RLS_IEN_Msk         : Rx Line status interrupt
*                              - UART_IER_THRE_IEN_Msk        : Tx empty interrupt
*                              - UART_IER_RDA_IEN_Msk         : Rx ready interrupt
*
*    @return       None
*
*    @details      This macro enable specified UART interrupt.
*/
#define UART_DISABLE_INT(uart, u32eIntSel)    ((uart)->IER &= ~ (u32eIntSel))


/**
*    @brief        Get specified interrupt indicator status
*
*    @param[in]    uart            The pointer of the specified UART module
*    @param[in]    u32eIntTypeFlag Interrupt Type Flag, should be
  *                                 - UART_ISR_LIN_RX_BREAK_INT_Msk : LIN Bus Interrupt Indicator
*                                  - UART_ISR_BUF_ERR_INT_Msk      : Buffer Error Interrupt Indicator
*                                  - UART_ISR_TOUT_INT_Msk         : Rx Time-out Interrupt Indicator
*                                  - UART_ISR_MODEM_INT_Msk        : MODEM Status Interrupt Indicator
*                                  - UART_ISR_RLS_INT_Msk          : Rx Line Status Interrupt Indicator
*                                  - UART_ISR_THRE_INT_Msk         : Tx Empty Interrupt Indicator
*                                  - UART_ISR_RDA_INT_Msk          : Rx Ready Interrupt Indicator
*                                  - UART_ISR_LIN_RX_BREAK_IF_Msk  : LIN Bus Interrupt Flag
*                                  - UART_ISR_BUF_ERR_IF_Msk       : Buffer Error Interrupt Flag
*                                  - UART_ISR_TOUT_IF_Msk          : Rx Time-out Interrupt Flag
*                                  - UART_ISR_MODEM_IF_Msk         : MODEM Status Interrupt Flag
*                                  - UART_ISR_RLS_IF_Msk           : Rx Line Status Interrupt Flag
*                                  - UART_ISR_THRE_IF_Msk          : Tx Empty Interrupt Flag
*                                  - UART_ISR_RDA_IF_Msk           : Rx Ready Interrupt Flag
*
*    @retval       0 The specified interrupt is not happened.
*                  1 The specified interrupt is happened.
*
*    @details      This macro get specified interrupt flag or interrupt indicator status.
*/
#define UART_GET_INT_FLAG(uart,u32eIntTypeFlag)    (((uart)->ISR & (u32eIntTypeFlag))?1:0)


/**
*    @brief        Set RTS pin to low
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @return       None
*
*    @details      This macro set RTS pin to low.
*/
__STATIC_INLINE void UART_CLEAR_RTS(UART_T* uart)
{
    (uart)->MCR |= UART_MCR_LEV_RTS_Msk;
    (uart)->MCR &= ~UART_MCR_RTS_Msk;
}

/**
*    @brief        Set RTS pin to high
*
*    @param[in]    uart    The pointer of the specified UART module
*    @return       None
*
*    @details      This macro set RTS pin to high.
*/
__STATIC_INLINE void UART_SET_RTS(UART_T* uart)
{
    (uart)->MCR |= UART_MCR_LEV_RTS_Msk | UART_MCR_RTS_Msk;
}


/**
*    @brief        Clear RS-485 Address Byte Detection Flag
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @return       None
*
*    @details      This macro clear RS-485 address byte detection flag.
*/
#define UART_RS485_CLEAR_ADDR_FLAG(uart)    ((uart)->FSR = UART_FSR_RS485_ADD_DETF_Msk)


/**
*    @brief        Get RS-485 Address Byte Detection Flag
*
*    @param[in]    uart    The pointer of the specified UART module
*
*    @retval       0 Receiver detects a data that is not an address bit.
*    @retval       1 Receiver detects a data that is an address bit.
*
*    @details      This macro get RS-485 address byte detection flag.
*/
#define UART_RS485_GET_ADDR_FLAG(uart)    (((uart)->FSR  & UART_FSR_RS485_ADD_DETF_Msk) >> UART_FSR_RS485_ADD_DETF_Pos)


void UART_ClearIntFlag(UART_T* uart , uint32_t u32InterruptFlag);
void UART_Close(UART_T* uart);
void UART_DisableFlowCtrl(UART_T* uart);
void UART_DisableInt(UART_T*  uart, uint32_t u32InterruptFlag);
void UART_EnableFlowCtrl(UART_T* uart);
void UART_EnableInt(UART_T*  uart, uint32_t u32InterruptFlag);
void UART_Open(UART_T* uart, uint32_t u32baudrate);
uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes);
void UART_SetLine_Config(UART_T* uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t  u32stop_bits);
void UART_SetTimeoutCnt(UART_T* uart, uint32_t u32TOC);
void UART_SelectIrDAMode(UART_T* uart, uint32_t u32Buadrate, uint32_t u32Direction);
void UART_SelectRS485Mode(UART_T* uart, uint32_t u32Mode, uint32_t u32Addr);
void UART_SelectLINMode(UART_T* uart, uint32_t u32Mode, uint32_t u32BreakLength);
uint32_t UART_Write(UART_T* uart, uint8_t *pu8TxBuf, uint32_t u32WriteBytes);


/*@}*/ /* end of group UART_EXPORTED_FUNCTIONS */

/*@}*/ /* end of group UART_Driver */

/*@}*/ /* end of group Standard_Driver */

#ifdef __cplusplus
}
#endif

#endif //__UART_H__

/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/

使用特权

评论回复
643757107| | 2017-6-26 19:16 | 显示全部楼层
#define UART_IRCR_TX_SELECT         (0x1 << UART_IRCR_TX_SELECT_Pos) /*!< Set IrDA function Tx mode */
#define UART_IRCR_RX_SELECT         (0x0 << UART_IRCR_TX_SELECT_Pos) /*!< Set IrDA function Rx mode */
应该是这两个吧?

使用特权

评论回复
jcdzxh| | 2017-6-26 21:04 | 显示全部楼层
寄存器昨天刚玩过,不需要,开时钟,设af, 波特分频,就可以了

使用特权

评论回复
Harvard| | 2017-6-27 09:23 | 显示全部楼层
不要看手册了 看bsp最新的 3.0库 还有官方出品的: 玩转新唐M0 M4 足够了. 温子琪的书也可以看看

使用特权

评论回复
fuzexinde| | 2017-6-27 09:27 | 显示全部楼层
应该有的把,仔细查看

使用特权

评论回复
qwe12377yu| | 2017-6-27 12:03 | 显示全部楼层
有的,在sys_init()里面

使用特权

评论回复
czw1993| | 2017-6-27 17:09 | 显示全部楼层
学习

使用特权

评论回复
huangcunxiake| | 2017-6-28 09:27 | 显示全部楼层
都是人才,手册加库函数

使用特权

评论回复
fangyi999|  楼主 | 2017-6-29 12:58 | 显示全部楼层
643757107 发表于 2017-6-26 19:16
#define UART_IRCR_TX_SELECT         (0x1

谢谢!这个应该是针对IRDA的,不是普通UART模式

使用特权

评论回复
fangyi999|  楼主 | 2017-6-29 12:59 | 显示全部楼层
qwe12377yu 发表于 2017-6-27 12:03
有的,在sys_init()里面

在这个函数中没有发现,可以把语句贴出来吗?

使用特权

评论回复
fangyi999|  楼主 | 2017-6-29 13:02 | 显示全部楼层
非常感谢各位的回复,不过希望能回复得准确些!在手册中没有发现相应的控制位,在SDK中也没有发现相应函数,到目前为止我觉得这个芯片应该是不支持这个功能的,请专业人士帮忙确认。

使用特权

评论回复
yyglucky| | 2017-6-30 23:41 | 显示全部楼层

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

16

帖子

1

粉丝