njlz0707mm 发表于 2011-4-3 13:12:54

为何进不了ARM的串口中断?(有注释)

为什么进不了ARM的串口中断
编译工具:IAR For ARM
芯片:LPC2103
ps:程序中的
UART0_GetChar() UART0_GetString() UART0_PutChar() UART0_PutString()这些函数都是可以正常使用,可以正常串口接收发送程序。但就是进不了串口接收中断

#include "iolpc2103.h"
#include "config.h"
#include "lpc2103.h"
#define UART_BPS 9600   //波特率9600
unsigned char   rcv_new=0;

//---------------------串口0的中断服务程序------------------
void Uart0Handler(void)
{
rcv_new = 1;             //将自定义的串口中断标志变量置1(在主函数中用到此变量)
VICVectAddr0 = 0;    //清除中断地址向量
}


//-------------------串口0的中断初始化-----------------
void UART0_Interrupt_Init(void)
{   
VICIntSelect = 0x00000000;    //将所有的中断选择为IRQ模式
VICVectCntl0 = 0x26;         //向量IRQ使能且选择对应的UART0中断号 0x26 = 0x02|0x06;
VICVectAddr0 = (unsigned int)Uart0Handler;   //将中断服务程序的地址装载到VICVectAddr0地址向量中
VICIntEnable = 1<<6;   //UART0串口中断使能
}



//-------------------------------------------------------
#pragma vector=IRQV
__irq __arm void irq_handler (void)
{
void (*interrupt_function)();
unsigned int vector;
vector = VICVectAddr0;   
interrupt_function = (void(*)())vector;
if(interrupt_function != '\0')
{
    interrupt_function();
}
else
{
    VICVectAddr = 0;
}
}



//-------------------串口0初始化-------------------
void UART0_Init ()               
{
   U16 Fdiv;
   U0LCR = 0x83;//打开“除数修改”
   Fdiv = (Fpclk / 16)/ UART_BPS;
   U0DLM = Fdiv / 256;                                                       
   U0DLL = Fdiv % 256;       
   U0LCR = 0x03;//关闭“除数修改”
   U0FCR = 0x81;//选择触发点0(1个字符或0x01h)+FIFO使能                     
   U0IER = 0x01;//RBR(串口接收中断)使能
}


//----------------串口0发送1个byte----------------------
void UART0_PutChar ( chardata)
{
U0THR = data;       
while( (U0LSR&0x40)==0 );
}



//----------------串口0发送字符串----------------
UART0_PutString(unsigned char *str)
{
while(*str!='\0')
{
    UART0_PutChar(*str++);
}
}

//-----------------串口0接收1个byte---------------
char UART0_GetChar ( void )
{
unsigned char Rcv_Data;

while((U0LSR&0x01)==0);
Rcv_Data=U0RBR;                        
return(Rcv_Data);
}


//----------------串口0接收字符串---------------
void UARt0_GetString(unsigned char *str, unsigned char n)
{
for(;n>0;n++)
{
      *str++=UART0_GetChar();
      
}
}

//------------PLL(锁相环)初始化-----------------
void PLL_Init(void)//PLL init function
{
           PLLCON = 1;// PLL enable
        #if ((Fcclk / 4) / Fpclk) == 1//
                VPBDIV = 0;
        #endif
        #if ((Fcclk / 4) / Fpclk) == 2
                VPBDIV = 2;
        #endif
        #if ((Fcclk / 4) / Fpclk) == 4
                VPBDIV = 1;
        #endif
        #if (Fcco / Fcclk) == 2
                PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
        #endif
        #if (Fcco / Fcclk) == 4
                PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
        #endif
        #if (Fcco / Fcclk) == 8
                PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
        #endif
        #if (Fcco / Fcclk) == 16
                PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
        #endif
                PLLFEED = 0xaa;//fixed don't change
                PLLFEED = 0x55;//fixed don't change
                while((PLLSTAT & (1 << 10)) == 0);//when PLOCK=1,PLL is locked
                PLLCON = 3;//when PLLFEED is ok, PLL works
                PLLFEED = 0xaa;//fixed don't change.
                PLLFEED = 0x55;        //fixed don't change
}

//---------------------主函数--------------------
void main(void)
{
char temp = '0';
PINSEL0 = (PINSEL0 & (~0x03))|(0x01);
PINSEL0 = (PINSEL0 & (~(0x03<<2))|(0x01<<2));            
PLL_Init();
UART0_Init();
UART0_Interrupt_Init();
UART0_PutString("Init success");
   
while(1)
{
       if(rcv_new == 1)//程序运行后,无论用串口调试助手怎么发送数据,都进不了串口接收中断,程序总是停留在这一行
    {
      UART0_PutString("I success,haha~!");
      rcv_new = 0;
    }
}
}

njlz0707mm 发表于 2011-4-3 22:10:15

kkking 发表于 2011-4-3 23:30:09

弱弱的问句楼主,LPC21**的外部中断你会吗,我今天弄了一天快要疯了,要是会的话,求留个QQ讨论下,我QQ923996994,最好能讨论下才有结果嘛

njlz0707mm 发表于 2011-4-5 13:12:34

linyinhai 发表于 2011-9-11 09:48:02

可能是你的串口0中断服务函数的名字取的不对,好像有 专门的格式,你改成void __irq IRQ_UART0()
或者void UART0_IRQHandler() 试一下
页: [1]
查看完整版本: 为何进不了ARM的串口中断?(有注释)