我在使用16c2550b时,可以发送,并且也可以产生发送中断,但在接收时,老是不能产生接收中断,以下是我的代码,能帮我看看,是不是有什么问题,谢谢
/* SC16C2550通用异步串行口0(UART0)的特殊寄存器 */
我使用的cpu是lpc2214,器件cs0的基地址是0x81000020 ,cs1:0x81000028
//接收保寄存器 #define SC16C2550_U0RBR (*((volatile unsigned char *)0x81000020)) //发送保寄存器 #define SC16C2550_U0THR (*((volatile unsigned char *)0x81000020)) //中断使能寄存器 #define SC16C2550_U0IER (*((volatile unsigned char *)0x81000021)) //中断状态寄存器 #define SC16C2550_U0ISR (*((volatile unsigned char *)0x81000022)) //中断状态寄存器 与zlg定义兼容 #define SC16C2550_U0IIR (*((volatile unsigned char *)0x81000022)) //FIFO控制寄存器 #define SC16C2550_U0FCR (*((volatile unsigned char *)0x81000022)) //线控制寄存器 #define SC16C2550_U0LCR (*((volatile unsigned char *)0x81000023)) //Modem控制寄存器 #define SC16C2550_U0MCR (*((volatile unsigned char *)0x81000024)) //线状态寄存器 #define SC16C2550_U0LSR (*((volatile unsigned char *)0x81000025)) //Modem状态寄存器 #define SC16C2550_U0MSR (*((volatile unsigned char *)0x81000026)) //暂存寄存器 #define SC16C2550_U0SPR (*((volatile unsigned char *)0x81000027)) //除数LSB保存 #define SC16C2550_U0DLL (*((volatile unsigned char *)0x81000020)) //除数MSB保存 #define SC16C2550_U0DLM (*((volatile unsigned char *)0x81000021))
void SC16C2550Uart0Init(uint32 baud,uint8 datab,float stopb,uint8 check,uint8 rev_num) { uint32 Bak; SC16C2550_U0LCR = 0X80; //设置U0LCR.7=1 Bak = SC16C2550_Fpclk/(16*baud); //设置波特率 SC16C2550_U0DLM = Bak >> 8; SC16C2550_U0DLL = Bak & 0XFF; SC16C2550_U0LCR = 0; //设置U0LCR.7=0 Bak = datab - 5; //字长 if(stopb==2 || stopb==1.5) Bak |= 0X04; if(check!=None && check!=Space) Bak = Bak + (1<<3) + (check<<4); //xxxxxxxx if(check==Space) Bak = Bak + (1<<3); SC16C2550_U0LCR = Bak; Bak = 1; switch (rev_num) { case 1: Bak = Bak + 0X00; break; case 4: Bak = Bak + 0X40; break; case 8: Bak = Bak + 0X80; break; case 14: Bak = Bak + 0XC0; break; } SC16C2550_U0FCR = Bak; SC16C2550_U0IER = 0X03; //串口0中断使能 SC16C2550_U0MCR = 0x08;//(1<<3); //外部中断使能 PINSEL1 = (PINSEL1 & 0xFFFFFFFC)|0x00000001; //设置p0.16脚为外部中断0 EXTINT |= 0x01; //清除EINT0中断标志 EXTMODE |= 0x01; //使用边延激活方式 EXTPOLAR &= 0x06; //低电平有效 VICIntSelect &= 0XFFFFBFFF; //设置外部中断0为irq中断 VICVectCntl1 = 0X20 | 0X06; //外部中断0为14号中断 VICVectAddr1 =(uint32)SC16C2550_Uart0_IRQ; //外部中断0设置在通道一 VICIntEnable |= (1<<0X0E); //使能外部中断0 } |