最近在作有关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脚),只能在网上找资料调试。spa
发现了两篇博客很是有用,附上两篇博客的原文连接。.net
博客1:https://blog.csdn.net/u014798590/article/details/82560796debug
博客2:https://blog.csdn.net/a1031238455/article/details/85382595调试
第一篇提出是中断优先级的缘由,并提供了源代码。在测试以后发现并非这样。第二篇是在第一篇的基础上找出了问题的根本缘由。code
N76E003的中断机制是中断产生以后对应的中断标志位都会被置1。blog
因此问题出在了发送中断标志位未清零,致使串口0一直处于中断状态,而串口0的中断优先级是高于串口1的,因此根本没法进入串口1中断。get
所以,在中断函数中加上清发送标志位程序input
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 */ } }
问题解决!