[技术问答] NUC029串口通讯FIFO问题

[复制链接]
1856|9
 楼主| jheng 发表于 2018-9-12 10:43 | 显示全部楼层 |阅读模式
每次传输的数据,最后一个数据就出问题,这是芯片问题吗 微信截图_20180912104048.png

Harvard 发表于 2018-9-12 11:12 | 显示全部楼层
程序问题...
稳稳の幸福 发表于 2018-9-12 15:04 | 显示全部楼层
你到最后一个发送的时候判断一下是不是0x38,再发出去。
你的串口助手分享一下用用。
小灵通2018 发表于 2018-9-12 18:28 | 显示全部楼层
以前我遇到过类似的,后来我重新写了代码不知道怎么回事好了。
zhuomuniao110 发表于 2018-9-12 21:18 | 显示全部楼层
不用FIFO呢?
幸福小强 发表于 2018-9-12 22:18 | 显示全部楼层
试试Print函数。
幸福小强 发表于 2018-9-12 22:19 | 显示全部楼层
  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: 14/01/28 11:45a $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    NUC029 Series UART Interface Controller Driver Sample Code
  7. *
  8. * @note
  9. * Copyright (C) 2011 Nuvoton Technology Corp. All rights reserved.
  10. *
  11. ******************************************************************************/
  12. #include <stdio.h>
  13. #include "NUC029xAN.h"


  14. #define PLL_CLOCK           50000000

  15. #define RXBUFSIZE 1024


  16. /*---------------------------------------------------------------------------------------------------------*/
  17. /* Define functions prototype                                                                              */
  18. /*---------------------------------------------------------------------------------------------------------*/
  19. extern char GetChar(void);
  20. int32_t main(void);
  21. void AutoFlow_FunctionTxTest(void);


  22. void SYS_Init(void)
  23. {
  24.     /*---------------------------------------------------------------------------------------------------------*/
  25.     /* Init System Clock                                                                                       */
  26.     /*---------------------------------------------------------------------------------------------------------*/

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

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

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

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

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

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

  39.     /* Enable UART module clock */
  40.     CLK_EnableModuleClock(UART0_MODULE);
  41.     CLK_EnableModuleClock(UART1_MODULE);

  42.     /* Select UART module clock source */
  43.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));
  44.     CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));

  45.     /*---------------------------------------------------------------------------------------------------------*/
  46.     /* Init I/O Multi-function                                                                                 */
  47.     /*---------------------------------------------------------------------------------------------------------*/

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

  51.     /* Set P1 multi-function pins for UART1 RXD and TXD */
  52.     SYS->P1_MFP &= ~(SYS_MFP_P12_Msk | SYS_MFP_P13_Msk);
  53.     SYS->P1_MFP |= (SYS_MFP_P12_RXD1 | SYS_MFP_P13_TXD1);

  54.     /* Set P0 multi-function pins for UART1 CTS */
  55.     SYS->P0_MFP = SYS->P0_MFP & (~SYS_MFP_P00_Msk) | SYS_MFP_P00_CTS1;

  56. }

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

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

  67. void UART1_Init()
  68. {
  69.     /*---------------------------------------------------------------------------------------------------------*/
  70.     /* Init UART                                                                                               */
  71.     /*---------------------------------------------------------------------------------------------------------*/
  72.     /* Reset UART1 module */
  73.     SYS_ResetModule(UART1_RST);

  74.     /* Configure UART1 and set UART1 Baudrate */
  75.     UART_Open(UART1, 115200);
  76. }

  77. /*---------------------------------------------------------------------------------------------------------*/
  78. /* MAIN function                                                                                           */
  79. /*---------------------------------------------------------------------------------------------------------*/

  80. int main(void)
  81. {

  82.     /* Unlock protected registers */
  83.     SYS_UnlockReg();

  84.     /* Init System, IP clock and multi-function I/O */
  85.     SYS_Init();

  86.     /* Lock protected registers */
  87.     SYS_LockReg();

  88.     /* Init UART0 for printf */
  89.     UART0_Init();

  90.     /* Init UART1 for testing */
  91.     UART1_Init();

  92.     /*---------------------------------------------------------------------------------------------------------*/
  93.     /* SAMPLE CODE                                                                                             */
  94.     /*---------------------------------------------------------------------------------------------------------*/

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

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

  97.     /* UART auto flow sample master function */
  98.     AutoFlow_FunctionTxTest();

  99.     while(1);

  100. }

  101. /*---------------------------------------------------------------------------------------------------------*/
  102. /*  AutoFlow Function Tx Test                                                                                 */
  103. /*---------------------------------------------------------------------------------------------------------*/
  104. void AutoFlow_FunctionTxTest()
  105. {
  106.     uint32_t u32i;

  107.     printf("\n");
  108.     printf("+-----------------------------------------------------------+\n");
  109.     printf("|     Pin Configure                                         |\n");
  110.     printf("+-----------------------------------------------------------+\n");
  111.     printf("|    _______                                    _______     |\n");
  112.     printf("|   |       |                                  |       |    |\n");
  113.     printf("|   |Master |---TXD1(P1.3) <====> RXD1(P1.2)---| Slave |    |\n");
  114.     printf("|   |       |---CTS1(P0.0) <====> RTS1(P0.1)---|       |    |\n");
  115.     printf("|   |_______|                                  |_______|    |\n");
  116.     printf("|                                                           |\n");
  117.     printf("+-----------------------------------------------------------+\n");

  118.     printf("\n");
  119.     printf("+-----------------------------------------------------------+\n");
  120.     printf("|       AutoFlow Function Test (Master)                     |\n");
  121.     printf("+-----------------------------------------------------------+\n");
  122.     printf("|  Description :                                            |\n");
  123.     printf("|    The sample code needs two boards. One is Master and    |\n");
  124.     printf("|    the other is slave. Master will send 1k bytes data     |\n");
  125.     printf("|    to slave.Slave will check if received data is correct  |\n");
  126.     printf("|    after getting 1k bytes data.                           |\n");
  127.     printf("|    Press any key to start...                              |\n");
  128.     printf("+-----------------------------------------------------------+\n");
  129.     GetChar();

  130.     /* Enable RTS and CTS autoflow control */
  131.     UART_EnableFlowCtrl(UART1);

  132.     /* Send 1k bytes data */
  133.     for(u32i = 0; u32i < RXBUFSIZE; u32i++)
  134.     {
  135.         /* Send 1 byte data */
  136.         UART_WRITE(UART1, u32i & 0xFF);

  137.         /* Wait if Tx FIFO is full */
  138.         while(UART_IS_TX_FULL(UART1));
  139.     }

  140.     printf("\n Transmit Done\n");

  141. }
捉虫天师 发表于 2018-9-12 22:35 | 显示全部楼层
用库试试,是不是有什么特别要求。
jasontu 发表于 2018-9-13 08:21 | 显示全部楼层
在送出串口资料出去前,先去看一下uart fifo full flag是不是有起来。
如果有起来的话,表示串口资料是满的。

while(uart fifo full flag==1);
send uart data...
643757107 发表于 2018-9-14 14:28 | 显示全部楼层
不太懂,不知道其他系列是不是这样。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

35

主题

98

帖子

0

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