最近在做有关N76E003的项目,使用到双串口。串口的配置没有特殊要求,最基本的配置
void Uart0_Init(void)
{
//—————————串口0引脚初始化————————
set_P06;
set_P07;
set_ES; //enable uart0 interrupt
InitialUART0_Timer1(9600); //UART0 Baudrate initial,T1M=0,SMOD=0
}
void Uart1_Init(void)
{
//—————————串口1引脚初始化————————
set_P02;
set_P16;
set_ES_1; //enable uart1 interrupt
InitialUART1_Timer3(9600);
}
并配置了中断函数
void SerialPort0_ISR(void) interrupt 4
{
if(RI)
{ /* if reception occur */
clr_RI; /* clear reception flag for next reception */
uart_receive_input(SBUF);
}
}
void SerialPort1_ISR(void) interrupt 15
{
if(RI_1)
{
clr_RI_1;
uart1_receive_input(SBUF);
}
}
运行程序发现无法进入串口1中断,在使用串口1又没办法debug的情况下(UART1的TX_1/RX_1脚也分别是ICP的SDA/LCK脚),只能在网上找资料调试。
发现了两篇博客非常有用,附上两篇博客的原文链接。
博客1:https://blog.csdn.net/u014798590/article/details/82560796
博客2:https://blog.csdn.net/a1031238455/article/details/85382595
第一篇提出是中断优先级的原因,并提供了源代码。在测试之后发现并不是这样。第二篇是在第一篇的基础上找出了问题的根本原因。
N76E003的中断机制是中断产生之后对应的中断标志位都会被置1。

所以问题出在了发送中断标志位未清零,导致串口0一直处于中断状态,而串口0的中断优先级是高于串口1的,所以根本无法进入串口1中断。

因此,在中断函数中加上清发送标志位程序
void SerialPort0_ISR(void) interrupt 4
{
if(RI)
{ /* if reception occur */
clr_RI; /* clear reception flag for next reception */
uart_receive_input(SBUF);
}
if(TI)
{
clr_TI; /* if emission occur */
}
}
void SerialPort1_ISR(void) interrupt 15
{
if(RI_1)
{
clr_RI_1;
uart1_receive_input(SBUF);
}
if(TI_1)
{
clr_TI_1; /* if emission occur */
}
}
问题解决!