[技术问答] N76E003串口1Demo不能够正常发送,求解???

[复制链接]
 楼主| 小白flame 发表于 2018-2-6 17:12 | 显示全部楼层 |阅读模式
N76E003串口1Demo不能够正常发送,求解???,验证串口0的2个接口都可以使用,我看了串口1的demo配置也没有什么问题,但是就是发送不出来.
zhuotuzi 发表于 2018-2-6 17:32 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2017
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 UART-1 Mode1 demo code
  14. //***********************************************************************************************************
  15. #include "N76E003.h"
  16. #include "Common.h"
  17. #include "Delay.h"
  18. #include "SFR_Macro.h"
  19. #include "Function_define.h"

  20. #define BUFFER_SIZE                16
  21. UINT8  UART_BUFFER[BUFFER_SIZE],temp;
  22. UINT16 u16CNT=0,u16CNT1=0;
  23. bit riflag;

  24. /******************************************************************************
  25. * FUNCTION_PURPOSE: Serial port 1 interrupt, echo received data.
  26. * FUNCTION_INPUTS : P0.2(RXD) serial input
  27. * FUNCTION_OUTPUTS: P1.6(TXD) serial output
  28. * Following setting in Common.c
  29. ******************************************************************************/
  30. #if 0
  31. //void InitialUART1_Timer3(UINT32 u32Baudrate) //use timer3 as Baudrate generator
  32. //{
  33. //                P02_Quasi_Mode;                //Setting UART pin as Quasi mode for transmit
  34. //                P16_Quasi_Mode;                //Setting UART pin as Quasi mode for transmit
  35. //       
  36. //          SCON_1 = 0x50;           //UART1 Mode1,REN_1=1,TI_1=1
  37. //    T3CON = 0x08;           //T3PS2=0,T3PS1=0,T3PS0=0(Prescale=1), UART1 in MODE 1
  38. //                clr_BRCK;
  39. //       
  40. //#ifdef FOSC_160000
  41. //                RH3    = HIBYTE(65536 - (1000000/u32Baudrate)-1);                  /*16 MHz */
  42. //                RL3    = LOBYTE(65536 - (1000000/u32Baudrate)-1);                        /*16 MHz */
  43. //#endif
  44. //#ifdef FOSC_166000
  45. //                RH3    = HIBYTE(65536 - (1037500/u32Baudrate));                          /*16.6 MHz */
  46. //                RL3    = LOBYTE(65536 - (1037500/u32Baudrate));                                /*16.6 MHz */
  47. //#endif
  48. //    set_TR3;         //Trigger Timer3
  49. //}
  50. #endif

  51. void SerialPort1_ISR(void) interrupt 15
  52. {
  53.     if (RI_1==1)
  54.     {                                       /* if reception occur */
  55.         clr_RI_1;                             /* clear reception flag for next reception */
  56.         UART_BUFFER[u16CNT] = SBUF_1;
  57.         u16CNT ++;
  58.                                 riflag =1;
  59.     }
  60.     if(TI_1==1)
  61.     {
  62.         clr_TI_1;                             /* if emission occur */
  63.     }
  64. }


  65. /****************************************************************************************************************
  66. * FUNCTION_PURPOSE: Main function
  67.   
  68. !!! N76E003 UART1 pin also occupied by debug pin,
  69. please remove Nu-link or not in debug mode to test UART1 function.

  70. External UART1 connect also disturb debug download

  71. ***************************************************************************************************************/
  72. void main (void)
  73. {
  74.         P12_PushPull_Mode;                // For I/O toggle display
  75.        
  76. #if 0       
  77. //for Simple use UART1 transmit out
  78.                 InitialUART1_Timer3(115200);               
  79.     while(1)
  80.     Send_Data_To_UART1(0x55);
  81.                
  82. #else                       
  83. // For interrupt setting check receive
  84.                 InitialUART1_Timer3(115200);
  85.                 set_ES_1;                                        //For interrupt enable
  86.                 set_EA;
  87.                
  88.                 while(1)
  89.                 {
  90.                         if (riflag)
  91.                         {
  92.                                         P12 = ~ P12;                        //Receive each byte P12 toggle, never work under debug mode
  93.                                         riflag = 0;
  94.                         }
  95.                 }

  96. #endif
  97.                        
  98.        
  99.                
  100. }
  101.   

评论

复制粘贴这么好用啊。。。。  发表于 2019-1-15 12:01
zhuotuzi 发表于 2018-2-6 17:32 | 显示全部楼层
试试你这个最新版。
xuanhuanzi 发表于 2018-2-6 18:47 | 显示全部楼层
没这个板子测试。
antusheng 发表于 2018-2-7 13:49 | 显示全部楼层
有的版本可能有错误,库函数写的不是很对。
xinpian101 发表于 2018-2-8 19:12 | 显示全部楼层
怎么样了?
huangcunxiake 发表于 2018-2-14 16:15 来自手机 | 显示全部楼层
调试通了吗,这个是只能发送不能接受?
643757107 发表于 2018-2-27 18:21 | 显示全部楼层
可以发送啊,我试过
jiekou001 发表于 2018-2-27 19:12 | 显示全部楼层
如何不正常,是一点都收不到,还是乱码,还是部分错误。。。
jiekou001 发表于 2018-2-27 19:13 | 显示全部楼层
波特率上位机跟下位机设置一致了吗
近道 发表于 2019-1-3 11:29 | 显示全部楼层
本帖最后由 近道 于 2019-1-3 11:35 编辑

问题原因找到了。uart1和下载口ice_data和ice_clk复用了,断开ice_data和ice_clk即可我之前用其它家工业级单片机做汽车电子产品方案,现在试用和替换成N76E003,21ic是很好平台,和大家一起快速学习。
小灵通2018 发表于 2019-1-18 23:48 | 显示全部楼层
近道 发表于 2019-1-3 11:29
问题原因找到了。uart1和下载口ice_data和ice_clk复用了,断开ice_data和ice_clk即可我之前用其它家 ...

多谢大神分享。原来如此啊。太感谢了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

20

帖子

1

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