This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

管脚中断



HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
{

EA=0;
{
halProcessCANInterrupt();
}
EA=1;
/*
Clear the CPU interrupt flag for Port_0
PxIFG has to be cleared before PxIF
*/
CLEAR_SLEEP_MODE();

return;
}

我在程序里面用到管脚中断,但是每次程序开始运行的时候前两三次可以进入中断,之后就进不去了。请问这可能是什么原因啊

  • 有几种原因,可能导致此问题的发生:

    1.P1口的中断被无意禁止。建议你查一下有没有别的地方,将P1口的中断被禁止,比如样例程序Simpleperipheral工程中,按键程序回调函数就有开关中断的操作。

    2. 主程序不稳定,跑飞了。可以用调试器CC-debuger看看不进入中断的时候,代码是不是停在一个地方。如果还可以跟踪,那么看看和P1口相关的寄存器的值是否是正确的值,这样就可以验证第一条。

    寄存器配置参考cc254x用户手册

  • 没有采用睡眠模式,可以参考的程序:

      #include "ioCC2540.h"
     void delay(void)
           {unsigned long i;
             for(i=0;i<100000;i++)
             asm(" nop ");
           }
    #pragma vector   = P1INT_VECTOR 

    __interrupt void P1INT_ISR(void)
    {P1IFG=0;
    P1IF=0;
     
     P0=0;
               
                 delay();
                 delay();
                 delay();
                 P0=0xff;
                
                 delay();
                 delay();
                 delay();
     
    }
        
      void  main()
        {
                 P0SEL =0;
               P1SEL =0x0;
               P0DIR=0xff;
               P1DIR=0x02;
               PICTL = 0x02;
    P1IEN=0x0c;
               IEN2=0x10;
               EA=1;
      
                while(1)
                 {
                 }
        }