打印
[技术问答]

N76E003串口1无法进入接收中断怎么解决?

[复制链接]
2193|11
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jueduilingdu|  楼主 | 2019-2-12 16:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 jueduilingdu 于 2019-2-13 16:48 编辑

N76E003串口1无法进入接收中断怎么解决?
void SerialPort1_ISR(void) interrupt 15
{
    if (RI_1==1)
    {                                       /* if reception occur */
        clr_RI_1;                             /* clear reception flag for next reception */
        UART_BUFFER[u16CNT] = SBUF_1;
        u16CNT ++;
                                Send_Data_To_UART0(0x33);
                                riflag =1;
    }
    if(TI_1==1)
    {
        clr_TI_1;                             /* if emission occur */
    }
}
这个中断不会触发是什么问题呢?
主函数配置如下
void main (void)
{
        P12_PushPull_Mode;                // For I/O toggle display
        
                                InitialUART1_Timer3(115200);
                                set_ES_1;                                        //For interrupt enable
                                set_EA;
                                
                                while(1)
                                {
                                                                if (riflag)
                                                                {
                                                                                                                                P12 = ~ P12;                        //Receive each byte P12 toggle, never work under debug mode
                                                                                                                                riflag = 0;
                                                                }
                                }
         
}
沙发
huangcunxiake| | 2019-2-12 20:45 | 只看该作者
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

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

//***********************************************************************************************************
//  File Function: N76E003 UART-1 Mode1 demo code
//***********************************************************************************************************
#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_define.h"

#define BUFFER_SIZE                16
UINT8  UART_BUFFER[BUFFER_SIZE],temp;
UINT16 u16CNT=0,u16CNT1=0;
bit riflag;

/******************************************************************************
* FUNCTION_PURPOSE: Serial port 1 interrupt, echo received data.
* FUNCTION_INPUTS : P0.2(RXD) serial input
* FUNCTION_OUTPUTS: P1.6(TXD) serial output
* Following setting in Common.c
******************************************************************************/
#if 0
//void InitialUART1_Timer3(UINT32 u32Baudrate) //use timer3 as Baudrate generator
//{
//                P02_Quasi_Mode;                //Setting UART pin as Quasi mode for transmit
//                P16_Quasi_Mode;                //Setting UART pin as Quasi mode for transmit
//       
//          SCON_1 = 0x50;           //UART1 Mode1,REN_1=1,TI_1=1
//    T3CON = 0x08;           //T3PS2=0,T3PS1=0,T3PS0=0(Prescale=1), UART1 in MODE 1
//                clr_BRCK;
//       
//#ifdef FOSC_160000
//                RH3    = HIBYTE(65536 - (1000000/u32Baudrate)-1);                  /*16 MHz */
//                RL3    = LOBYTE(65536 - (1000000/u32Baudrate)-1);                        /*16 MHz */
//#endif
//#ifdef FOSC_166000
//                RH3    = HIBYTE(65536 - (1037500/u32Baudrate));                          /*16.6 MHz */
//                RL3    = LOBYTE(65536 - (1037500/u32Baudrate));                                /*16.6 MHz */
//#endif
//    set_TR3;         //Trigger Timer3
//}
#endif

void SerialPort1_ISR(void) interrupt 15
{
    if (RI_1==1)
    {                                       /* if reception occur */
        clr_RI_1;                             /* clear reception flag for next reception */
        UART_BUFFER[u16CNT] = SBUF_1;
        u16CNT ++;
                                riflag =1;
    }
    if(TI_1==1)
    {
        clr_TI_1;                             /* if emission occur */
    }
}


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

External UART1 connect also disturb debug download

***************************************************************************************************************/
void main (void)
{
        P12_PushPull_Mode;                // For I/O toggle display
       
#if 0       
//for Simple use UART1 transmit out
                InitialUART1_Timer3(115200);               
    while(1)
    Send_Data_To_UART1(0x55);
               
#else                       
// For interrupt setting check receive
                InitialUART1_Timer3(115200);
                set_ES_1;                                        //For interrupt enable
                set_EA;
               
                while(1)
                {
                        if (riflag)
                        {
                                        P12 = ~ P12;                        //Receive each byte P12 toggle, never work under debug mode
                                        riflag = 0;
                        }
                }

#endif
                       
       
               
}
  

使用特权

评论回复
板凳
jasontu| | 2019-2-13 08:29 | 只看该作者
如果代码是BSP,那可能是串口接线错了,或uart rx没有收到任何的封包

使用特权

评论回复
地板
huangcunxiake| | 2019-2-13 10:03 | 只看该作者
试试官方的例子

使用特权

评论回复
5
mintspring| | 2019-2-22 23:49 | 只看该作者
看看串口线有没有接错。另外要宫地

使用特权

评论回复
6
21mengnan| | 2019-2-23 09:09 | 只看该作者
?跑官方例子肯定行啊

使用特权

评论回复
7
天灵灵地灵灵| | 2019-2-23 20:02 | 只看该作者
楼主哪儿出错了。

使用特权

评论回复
8
643757107| | 2019-2-24 09:02 | 只看该作者
这个没遇到啥难题,注意使用头文件和例子里的框架。
中断函数的名字最好使用例子里那样的

使用特权

评论回复
9
dongnanxibei| | 2019-4-9 23:04 | 只看该作者
串口中断是啥情况,如果不设置中断串口没法接受数据?

使用特权

评论回复
10
dongnanxibei| | 2019-4-9 23:04 | 只看该作者
只是收满了数据通知用户吧

使用特权

评论回复
11
天灵灵地灵灵| | 2019-4-13 22:52 | 只看该作者
上面那个例子就是串口1中断。

使用特权

评论回复
12
643757107| | 2019-4-18 00:17 | 只看该作者
串口中断的例子可以参考。

使用特权

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

本版积分规则

3

主题

6

帖子

0

粉丝