[技术问答] M051 UART

[复制链接]
3682|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 | 显示全部楼层
  1. /****************************************************************************
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
  4. * $Revision: 7 $
  5. * $Date: 15/05/22 3:53p $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Transmit and receive data from PC terminal through RS232 interface.
  7. *
  8. * @note
  9. * Copyright (C) 2011 Nuvoton Technology Corp. All rights reserved.
  10. *
  11. ******************************************************************************/
  12. #include <stdio.h>
  13. #include "M051Series.h"


  14. #define PLL_CLOCK           50000000

  15. #define RXBUFSIZE 1024

  16. /*---------------------------------------------------------------------------------------------------------*/
  17. /* Global variables                                                                                        */
  18. /*---------------------------------------------------------------------------------------------------------*/
  19. uint8_t g_u8RecData[RXBUFSIZE]  = {0};

  20. volatile uint32_t g_u32comRbytes = 0;
  21. volatile uint32_t g_u32comRhead  = 0;
  22. volatile uint32_t g_u32comRtail  = 0;
  23. volatile int32_t g_bWait         = TRUE;

  24. /*---------------------------------------------------------------------------------------------------------*/
  25. /* Define functions prototype                                                                              */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. int32_t main(void);
  28. void UART_TEST_HANDLE(void);
  29. void UART_FunctionTest(void);


  30. void SYS_Init(void)
  31. {
  32.     /*---------------------------------------------------------------------------------------------------------*/
  33.     /* Init System Clock                                                                                       */
  34.     /*---------------------------------------------------------------------------------------------------------*/

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

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

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

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

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

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

  47.     /* Enable UART module clock */
  48.     CLK_EnableModuleClock(UART0_MODULE);

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

  51.     /*---------------------------------------------------------------------------------------------------------*/
  52.     /* Init I/O Multi-function                                                                                 */
  53.     /*---------------------------------------------------------------------------------------------------------*/

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

  57. }

  58. void UART0_Init()
  59. {
  60.     /*---------------------------------------------------------------------------------------------------------*/
  61.     /* Init UART                                                                                               */
  62.     /*---------------------------------------------------------------------------------------------------------*/
  63.     /* Reset UART0 */
  64.     SYS_ResetModule(UART0_RST);

  65.     /* Configure UART0 and set UART0 Baudrate */
  66.     UART_Open(UART0, 115200);
  67. }

  68. /*---------------------------------------------------------------------------------------------------------*/
  69. /* UART Test Sample                                                                                        */
  70. /* Test Item                                                                                               */
  71. /* It sends the received data to HyperTerminal.                                                            */
  72. /*---------------------------------------------------------------------------------------------------------*/

  73. /*---------------------------------------------------------------------------------------------------------*/
  74. /* MAIN function                                                                                           */
  75. /*---------------------------------------------------------------------------------------------------------*/

  76. int main(void)
  77. {
  78.     /* Unlock protected registers */
  79.     SYS_UnlockReg();

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

  82.     /* Lock protected registers */
  83.     SYS_LockReg();

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

  86.     /*---------------------------------------------------------------------------------------------------------*/
  87.     /* SAMPLE CODE                                                                                             */
  88.     /*---------------------------------------------------------------------------------------------------------*/

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

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

  91.     /* UART sample function */
  92.     UART_FunctionTest();
  93.    
  94.     while(1);

  95. }

  96. /*---------------------------------------------------------------------------------------------------------*/
  97. /* ISR to handle UART Channel 0 interrupt event                                                            */
  98. /*---------------------------------------------------------------------------------------------------------*/
  99. void UART0_IRQHandler(void)
  100. {
  101.     UART_TEST_HANDLE();
  102. }

  103. /*---------------------------------------------------------------------------------------------------------*/
  104. /* UART Callback function                                                                                  */
  105. /*---------------------------------------------------------------------------------------------------------*/
  106. void UART_TEST_HANDLE()
  107. {
  108.     uint8_t u8InChar = 0xFF;
  109.     uint32_t u32IntSts = UART0->ISR;

  110.     if(u32IntSts & UART_ISR_RDA_INT_Msk)
  111.     {
  112.         printf("\nInput:");

  113.         /* Get all the input characters */
  114.         while(UART_IS_RX_READY(UART0))
  115.         {
  116.             /* Get the character from UART Buffer */
  117.             u8InChar = UART_READ(UART0);

  118.             printf("%c ", u8InChar);

  119.             if(u8InChar == '0')
  120.             {
  121.                 g_bWait = FALSE;
  122.             }

  123.             /* Check if buffer full */
  124.             if(g_u32comRbytes < RXBUFSIZE)
  125.             {
  126.                 /* Enqueue the character */
  127.                 g_u8RecData[g_u32comRtail] = u8InChar;
  128.                 g_u32comRtail = (g_u32comRtail == (RXBUFSIZE - 1)) ? 0 : (g_u32comRtail + 1);
  129.                 g_u32comRbytes++;
  130.             }
  131.         }
  132.         printf("\nTransmission Test:");
  133.     }

  134.     if(u32IntSts & UART_ISR_THRE_INT_Msk)
  135.     {
  136.         uint16_t tmp;
  137.         tmp = g_u32comRtail;
  138.         if(g_u32comRhead != tmp)
  139.         {
  140.             u8InChar = g_u8RecData[g_u32comRhead];
  141.             while(UART_IS_TX_FULL(UART0));  /* Wait Tx is not full to transmit data */            
  142.             UART_WRITE(UART0, u8InChar);
  143.             g_u32comRhead = (g_u32comRhead == (RXBUFSIZE - 1)) ? 0 : (g_u32comRhead + 1);
  144.             g_u32comRbytes--;
  145.         }
  146.     }
  147. }


  148. /*---------------------------------------------------------------------------------------------------------*/
  149. /*  UART Function Test                                                                                     */
  150. /*---------------------------------------------------------------------------------------------------------*/
  151. void UART_FunctionTest()
  152. {
  153.     printf("+-----------------------------------------------------------+\n");
  154.     printf("|  UART Function Test                                       |\n");
  155.     printf("+-----------------------------------------------------------+\n");
  156.     printf("|  Description :                                            |\n");
  157.     printf("|    The sample code will print input char on terminal      |\n");
  158.     printf("|    Please enter any to start     (Press '0' to exit)      |\n");
  159.     printf("+-----------------------------------------------------------+\n");

  160.     /*
  161.         Using a RS232 cable to connect UART0 and PC.
  162.         UART0 is set to debug port. UART0 is enable RDA and RLS interrupt.
  163.         When inputing char to terminal screen, RDA interrupt will happen and
  164.         UART0 will print the received char on screen.
  165.     */

  166.     /* Enable Interrupt and install the call back function */
  167.     UART_ENABLE_INT(UART0, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
  168.     NVIC_EnableIRQ(UART0_IRQn);
  169.     while(g_bWait);

  170.     /* Disable Interrupt */
  171.     UART_DISABLE_INT(UART0, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_RTO_IEN_Msk));
  172.     NVIC_DisableIRQ(UART0_IRQn);
  173.     g_bWait = TRUE;
  174.     printf("\nUART Sample Demo End.\n");

  175. }
643757107 发表于 2017-6-26 19:15 | 显示全部楼层
  1. /**************************************************************************//**
  2. * @file     UART.h
  3. * @version  V3.00
  4. * $Revision: 23 $
  5. * $Date: 15/05/29 4:19p $
  6. * @brief    M051 series UART driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __UART_H__
  12. #define __UART_H__


  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif


  17. /** @addtogroup Standard_Driver Standard Driver
  18.   @{
  19. */

  20. /** @addtogroup UART_Driver UART Driver
  21.   @{
  22. */

  23. /** @addtogroup UART_EXPORTED_CONSTANTS UART Exported Constants
  24.   @{
  25. */

  26. /*---------------------------------------------------------------------------------------------------------*/
  27. /* UART FIFO size constants definitions                                                                    */
  28. /*---------------------------------------------------------------------------------------------------------*/

  29. #define UART0_FIFO_SIZE 16 /*!< UART0 supports separated receive/transmit 16/16 bytes entry FIFO */
  30. #define UART1_FIFO_SIZE 16 /*!< UART1 supports separated receive/transmit 16/16 bytes entry FIFO */   
  31.    
  32. /*---------------------------------------------------------------------------------------------------------*/
  33. /* UA_FCR constants definitions                                                                            */
  34. /*---------------------------------------------------------------------------------------------------------*/

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

  39. #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 */
  40. #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 */
  41. #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 */
  42. #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 */

  43. /*---------------------------------------------------------------------------------------------------------*/
  44. /* UA_LCR constants definitions                                                                            */
  45. /*---------------------------------------------------------------------------------------------------------*/
  46. #define UART_WORD_LEN_5        (0) /*!< UA_LCR setting to set UART word length to 5 bits */
  47. #define UART_WORD_LEN_6        (1) /*!< UA_LCR setting to set UART word length to 6 bits */
  48. #define UART_WORD_LEN_7        (2) /*!< UA_LCR setting to set UART word length to 7 bits */
  49. #define UART_WORD_LEN_8        (3) /*!< UA_LCR setting to set UART word length to 8 bits */

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

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


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

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

  68. /*---------------------------------------------------------------------------------------------------------*/
  69. /* UA_FUNC_SEL constants definitions                                                                       */
  70. /*---------------------------------------------------------------------------------------------------------*/
  71. #define UART_FUNC_SEL_UART    (0x0 << UART_FUN_SEL_FUN_SEL_Pos) /*!< UA_FUNC_SEL setting to set UART Function  (Default) */
  72. #define UART_FUNC_SEL_LIN     (0x1 << UART_FUN_SEL_FUN_SEL_Pos) /*!< UA_FUNC_SEL setting to set LIN Function             */
  73. #define UART_FUNC_SEL_IrDA    (0x2 << UART_FUN_SEL_FUN_SEL_Pos) /*!< UA_FUNC_SEL setting to set IrDA Function            */
  74. #define UART_FUNC_SEL_RS485   (0x3 << UART_FUN_SEL_FUN_SEL_Pos) /*!< UA_FUNC_SEL setting to set RS485 Function           */

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



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


  81. /** @addtogroup UART_EXPORTED_FUNCTIONS UART Exported Functions
  82.   @{
  83. */


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

  95. /**
  96. *    @brief        Calculate UART baudrate mode2 divider
  97. *
  98. *    @param[in]    u32SrcFreq      UART clock frequency
  99. *    @param[in]    u32BaudRate     Baudrate of UART module
  100. *
  101. *    @return       UART baudrate mode2 divider
  102. *
  103. *    @details      This macro calculate UART baudrate mode2 divider.
  104. */
  105. #define UART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate)    ((((u32SrcFreq) + ((u32BaudRate)/2)) / (u32BaudRate))-2)


  106. /**
  107. *    @brief        Write data
  108. *
  109. *    @param[in]    uart    The pointer of the specified UART module
  110. *    @param[in]    u8Data  Data byte to transmit
  111. *
  112. *    @return       None
  113. *
  114. *    @details      This macro write Data to Tx data register.
  115. */
  116. #define UART_WRITE(uart, u8Data)    ((uart)->THR = (u8Data))


  117. /**
  118. *    @brief        Read data
  119. *
  120. *    @param[in]    uart    The pointer of the specified UART module
  121. *
  122. *    @return       The oldest data byte in RX FIFO
  123. *
  124. *    @details      This macro read Rx data register.
  125. */
  126. #define UART_READ(uart)    ((uart)->RBR)


  127. /**
  128. *    @brief        Get Tx empty
  129. *
  130. *    @param[in]    uart    The pointer of the specified UART module
  131. *
  132. *    @retval       0   Tx FIFO is not empty
  133. *    @retval       >=1 Tx FIFO is empty
  134. *
  135. *    @details      This macro get Tx empty register value.
  136. */
  137. #define UART_GET_TX_EMPTY(uart)    ((uart)->FSR & UART_FSR_TX_EMPTY_Msk)


  138. /**
  139. *    @brief        Get Rx empty
  140. *
  141. *    @param[in]    uart    The pointer of the specified UART module
  142. *
  143. *    @retval       0   Rx FIFO is not empty
  144. *    @retval       >=1 Rx FIFO is empty
  145. *
  146. *    @details      This macro get Rx empty register value.
  147. */
  148. #define UART_GET_RX_EMPTY(uart)    ((uart)->FSR & UART_FSR_RX_EMPTY_Msk)

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


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

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


  181. /**
  182. *    @brief        Check TX FIFO is full or not
  183. *
  184. *    @param[in]    uart   The pointer of the specified UART module
  185. *
  186. *    @retval       1 TX FIFO is full
  187. *    @retval       0 TX FIFO is not full
  188. *
  189. *    @details      This macro check TX FIFO is full or not.
  190. */
  191. #define UART_IS_TX_FULL(uart)    (((uart)->FSR & UART_FSR_TX_FULL_Msk)>>UART_FSR_TX_FULL_Pos)

  192. /**
  193. *    @brief        Check RX FIFO is full or not
  194. *
  195. *    @param[in]    uart    The pointer of the specified UART module
  196. *
  197. *    @retval       1 RX FIFO is full
  198. *    @retval       0 RX FIFO is not full
  199. *
  200. *    @details      This macro check RX FIFO is full or not.
  201. */
  202. #define UART_IS_RX_FULL(uart)    (((uart)->FSR & UART_FSR_RX_FULL_Msk)>>UART_FSR_RX_FULL_Pos)


  203. /**
  204. *    @brief        Get Tx full register value
  205. *
  206. *    @param[in]    uart    The pointer of the specified UART module
  207. *
  208. *    @retval       0   Tx FIFO is not full.
  209. *    @retval       >=1 Tx FIFO is full.
  210. *
  211. *    @details      This macro get Tx full register value.
  212. */
  213. #define UART_GET_TX_FULL(uart)    ((uart)->FSR & UART_FSR_TX_FULL_Msk)


  214. /**
  215. *    @brief        Get Rx full register value
  216. *
  217. *    @param[in]    uart   The pointer of the specified UART module
  218. *
  219. *    @retval       0   Rx FIFO is not full.
  220. *    @retval       >=1 Rx FIFO is full.
  221. *
  222. *    @details      This macro get Rx full register value.
  223. */
  224. #define UART_GET_RX_FULL(uart)    ((uart)->FSR & UART_FSR_RX_FULL_Msk)



  225. /**
  226. *    @brief        Enable specified UART interrupt
  227. *
  228. *    @param[in]    uart        The pointer of the specified UART module
  229. *    @param[in]    u32eIntSel  Interrupt type select
  230. *                              - UART_IER_LIN_RX_BRK_IEN_Msk  : Lin bus Rx break field interrupt
  231. *                              - UART_IER_WAKE_EN_Msk         : Wakeup interrupt
  232. *                              - UART_IER_BUF_ERR_IEN_Msk     : Buffer Error interrupt
  233. *                              - UART_IER_RTO_IEN_Msk         : Rx time-out interrupt
  234. *                              - UART_IER_MODEM_IEN_Msk       : Modem interrupt
  235. *                              - UART_IER_RLS_IEN_Msk         : Rx Line status interrupt
  236. *                              - UART_IER_THRE_IEN_Msk        : Tx empty interrupt
  237. *                              - UART_IER_RDA_IEN_Msk         : Rx ready interrupt
  238. *
  239. *    @return       None
  240. *
  241. *    @details      This macro enable specified UART interrupt.
  242. */
  243. #define UART_ENABLE_INT(uart, u32eIntSel)    ((uart)->IER |= (u32eIntSel))


  244. /**
  245. *    @brief        Disable specified UART interrupt
  246. *
  247. *    @param[in]    uart        The pointer of the specified UART module
  248. *    @param[in]    u32eIntSel  Interrupt type select
  249. *                              - UART_IER_LIN_RX_BRK_IEN_Msk  : Lin bus Rx break field interrupt
  250. *                              - UART_IER_WAKE_EN_Msk         : Wakeup interrupt
  251. *                              - UART_IER_BUF_ERR_IEN_Msk     : Buffer Error interrupt
  252. *                              - UART_IER_RTO_IEN_Msk         : Rx time-out interrupt
  253. *                              - UART_IER_MODEM_IEN_Msk       : Modem interrupt
  254. *                              - UART_IER_RLS_IEN_Msk         : Rx Line status interrupt
  255. *                              - UART_IER_THRE_IEN_Msk        : Tx empty interrupt
  256. *                              - UART_IER_RDA_IEN_Msk         : Rx ready interrupt
  257. *
  258. *    @return       None
  259. *
  260. *    @details      This macro enable specified UART interrupt.
  261. */
  262. #define UART_DISABLE_INT(uart, u32eIntSel)    ((uart)->IER &= ~ (u32eIntSel))


  263. /**
  264. *    @brief        Get specified interrupt indicator status
  265. *
  266. *    @param[in]    uart            The pointer of the specified UART module
  267. *    @param[in]    u32eIntTypeFlag Interrupt Type Flag, should be
  268.   *                                 - UART_ISR_LIN_RX_BREAK_INT_Msk : LIN Bus Interrupt Indicator
  269. *                                  - UART_ISR_BUF_ERR_INT_Msk      : Buffer Error Interrupt Indicator
  270. *                                  - UART_ISR_TOUT_INT_Msk         : Rx Time-out Interrupt Indicator
  271. *                                  - UART_ISR_MODEM_INT_Msk        : MODEM Status Interrupt Indicator
  272. *                                  - UART_ISR_RLS_INT_Msk          : Rx Line Status Interrupt Indicator
  273. *                                  - UART_ISR_THRE_INT_Msk         : Tx Empty Interrupt Indicator
  274. *                                  - UART_ISR_RDA_INT_Msk          : Rx Ready Interrupt Indicator
  275. *                                  - UART_ISR_LIN_RX_BREAK_IF_Msk  : LIN Bus Interrupt Flag
  276. *                                  - UART_ISR_BUF_ERR_IF_Msk       : Buffer Error Interrupt Flag
  277. *                                  - UART_ISR_TOUT_IF_Msk          : Rx Time-out Interrupt Flag
  278. *                                  - UART_ISR_MODEM_IF_Msk         : MODEM Status Interrupt Flag
  279. *                                  - UART_ISR_RLS_IF_Msk           : Rx Line Status Interrupt Flag
  280. *                                  - UART_ISR_THRE_IF_Msk          : Tx Empty Interrupt Flag
  281. *                                  - UART_ISR_RDA_IF_Msk           : Rx Ready Interrupt Flag
  282. *
  283. *    @retval       0 The specified interrupt is not happened.
  284. *                  1 The specified interrupt is happened.
  285. *
  286. *    @details      This macro get specified interrupt flag or interrupt indicator status.
  287. */
  288. #define UART_GET_INT_FLAG(uart,u32eIntTypeFlag)    (((uart)->ISR & (u32eIntTypeFlag))?1:0)


  289. /**
  290. *    @brief        Set RTS pin to low
  291. *
  292. *    @param[in]    uart    The pointer of the specified UART module
  293. *
  294. *    @return       None
  295. *
  296. *    @details      This macro set RTS pin to low.
  297. */
  298. __STATIC_INLINE void UART_CLEAR_RTS(UART_T* uart)
  299. {
  300.     (uart)->MCR |= UART_MCR_LEV_RTS_Msk;
  301.     (uart)->MCR &= ~UART_MCR_RTS_Msk;
  302. }

  303. /**
  304. *    @brief        Set RTS pin to high
  305. *
  306. *    @param[in]    uart    The pointer of the specified UART module
  307. *    @return       None
  308. *
  309. *    @details      This macro set RTS pin to high.
  310. */
  311. __STATIC_INLINE void UART_SET_RTS(UART_T* uart)
  312. {
  313.     (uart)->MCR |= UART_MCR_LEV_RTS_Msk | UART_MCR_RTS_Msk;
  314. }


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


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


  336. void UART_ClearIntFlag(UART_T* uart , uint32_t u32InterruptFlag);
  337. void UART_Close(UART_T* uart);
  338. void UART_DisableFlowCtrl(UART_T* uart);
  339. void UART_DisableInt(UART_T*  uart, uint32_t u32InterruptFlag);
  340. void UART_EnableFlowCtrl(UART_T* uart);
  341. void UART_EnableInt(UART_T*  uart, uint32_t u32InterruptFlag);
  342. void UART_Open(UART_T* uart, uint32_t u32baudrate);
  343. uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes);
  344. void UART_SetLine_Config(UART_T* uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t  u32stop_bits);
  345. void UART_SetTimeoutCnt(UART_T* uart, uint32_t u32TOC);
  346. void UART_SelectIrDAMode(UART_T* uart, uint32_t u32Buadrate, uint32_t u32Direction);
  347. void UART_SelectRS485Mode(UART_T* uart, uint32_t u32Mode, uint32_t u32Addr);
  348. void UART_SelectLINMode(UART_T* uart, uint32_t u32Mode, uint32_t u32BreakLength);
  349. uint32_t UART_Write(UART_T* uart, uint8_t *pu8TxBuf, uint32_t u32WriteBytes);


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

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

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

  353. #ifdef __cplusplus
  354. }
  355. #endif

  356. #endif //__UART_H__

  357. /*** (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

粉丝
快速回复 在线客服 返回列表 返回顶部