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.

从Zigbee协议栈底层添加自己的按键配置

Other Parts Discussed in Thread: CC2530

CC2530 基于home 1.2.2例程,按照下面的方法添加自己的按键

我的按键是P0.0,P0.1和P0.2三个,按照下面的方法,查询模式是可以的

但是改为中断模式后,就没反应了,不知是哪里问题

//也开启了中断模式,就是不行

else  // !OB_COLD
  {
    /* Initialize Key stuff */
    #if defined (ISR_KEYINTERRUPT)
    HalKeyConfig(HAL_KEY_INTERRUPT_ENABLE , OnBoard_KeyCallback);
    #else
    HalKeyConfig(HAL_KEY_INTERRUPT_ENABLE , OnBoard_KeyCallback);
    #endif
  }

 

  • 調試一下HalKeyConfig()看看是否真的進入中斷模式

  • HalKeyConfig 如下,三个按键有一个是可以中断的,另外两个不行,即SW6可以,SW7和SW8不行
    
    
    void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
    {
      /* Enable/Disable Interrupt or */
      Hal_KeyIntEnable = interruptEnable;
    
      /* Register the callback fucntion */
      pHalKeyProcessFunction = cback;
    
      /* Determine if interrupt is enable or not */
      if (Hal_KeyIntEnable)
      {
        /* Rising/Falling edge configuratinn */
    
        PICTL &= ~(HAL_KEY_SW_6_EDGEBIT);    /* Clear the edge bit */
        /* For falling edge, the bit must be set. */
      #if (HAL_KEY_SW_6_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_6_EDGEBIT;
      #endif
    
    
        /* Interrupt configuration:
         * - Enable interrupt generation at the port
         * - Enable CPU interrupt
         * - Clear any pending interrupt
         */
        HAL_KEY_SW_6_ICTL |= HAL_KEY_SW_6_ICTLBIT;
        HAL_KEY_SW_6_IEN |= HAL_KEY_SW_6_IENBIT;
        HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT);
    ////////////////////////////////////////////////////////////////////////////////
        /* Rising/Falling edge configuratinn */
    
        PICTL &= ~(HAL_KEY_SW_7_EDGEBIT);    /* Clear the edge bit */
        /* For falling edge, the bit must be set. */
      #if (HAL_KEY_SW_7_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_7_EDGEBIT;
      #endif
    
    
        /* Interrupt configuration:
         * - Enable interrupt generation at the port
         * - Enable CPU interrupt
         * - Clear any pending interrupt
         */
        HAL_KEY_SW_7_ICTL |= HAL_KEY_SW_7_ICTLBIT;
        HAL_KEY_SW_7_IEN |= HAL_KEY_SW_7_IENBIT;
        HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT);
    ////////////////////////////////////////////////////////////////////////////////
        /* Rising/Falling edge configuratinn */
    
        PICTL &= ~(HAL_KEY_SW_8_EDGEBIT);    /* Clear the edge bit */
        /* For falling edge, the bit must be set. */
      #if (HAL_KEY_SW_8_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_8_EDGEBIT;
      #endif
    
    
        /* Interrupt configuration:
         * - Enable interrupt generation at the port
         * - Enable CPU interrupt
         * - Clear any pending interrupt
         */
        HAL_KEY_SW_8_ICTL |= HAL_KEY_SW_8_ICTLBIT;
        HAL_KEY_SW_8_IEN |= HAL_KEY_SW_8_IENBIT;
        HAL_KEY_SW_8_PXIFG = ~(HAL_KEY_SW_8_BIT);
    ////////////////////////////////////////////////////////////////////////////////    
    
    
        /* Rising/Falling edge configuratinn */
    
        HAL_KEY_JOY_MOVE_ICTL &= ~(HAL_KEY_JOY_MOVE_EDGEBIT);    /* Clear the edge bit */
        /* For falling edge, the bit must be set. */
      #if (HAL_KEY_JOY_MOVE_EDGE == HAL_KEY_FALLING_EDGE)
        HAL_KEY_JOY_MOVE_ICTL |= HAL_KEY_JOY_MOVE_EDGEBIT;
      #endif
    
    
        /* Interrupt configuration:
         * - Enable interrupt generation at the port
         * - Enable CPU interrupt
         * - Clear any pending interrupt
         */
        HAL_KEY_JOY_MOVE_ICTL |= HAL_KEY_JOY_MOVE_ICTLBIT;
        HAL_KEY_JOY_MOVE_IEN |= HAL_KEY_JOY_MOVE_IENBIT;
        HAL_KEY_JOY_MOVE_PXIFG = ~(HAL_KEY_JOY_MOVE_BIT);
    
    
        /* Do this only after the hal_key is configured - to work with sleep stuff */
        if (HalKeyConfigured == TRUE)
        {
          osal_stop_timerEx(Hal_TaskID, HAL_KEY_EVENT);  /* Cancel polling if active */
        }
      }
      else    /* Interrupts NOT enabled */
      {
        HAL_KEY_SW_6_ICTL &= ~(HAL_KEY_SW_6_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_6_IEN &= ~(HAL_KEY_SW_6_IENBIT);   /* Clear interrupt enable bit */
        
        HAL_KEY_SW_7_ICTL &= ~(HAL_KEY_SW_7_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_7_IEN &= ~(HAL_KEY_SW_7_IENBIT);   /* Clear interrupt enable bit */
        
        HAL_KEY_SW_8_ICTL &= ~(HAL_KEY_SW_8_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_8_IEN &= ~(HAL_KEY_SW_8_IENBIT);   /* Clear interrupt enable bit */
    
        osal_set_event(Hal_TaskID, HAL_KEY_EVENT);
      }
    
      /* Key now is configured */
      HalKeyConfigured = TRUE;
    }

  • 你的SW7和SW8設置是什麼?
  • 如果你想用中断类型的按键,可以直接用参考下面的原始DEMO.
    www.ti.com.cn/.../getliterature.tsp
  • //按键1
    #define PUSH1_BV BV(0)
    #define PUSH1_SBIT P0_0

    //按键2
    #define PUSH3_BV BV(1)
    #define PUSH3_SBIT P0_1

    //按键3
    #define PUSH4_BV BV(2)
    #define PUSH4_SBIT P0_2
  • 我指的是HAL_KEY_SW_7_ICTL/HAL_KEY_SW_7_ICTLBIT/HAL_KEY_SW_7_IEN/HAL_KEY_SW_7_IENBIT...這些有設置好嗎?
  • 按键1(P0.0)可以中断,按键2(P0.1)和3(p0.2)不行
    //按键1
    #define HAL_KEY_SW_6_PORT   P0
    #define HAL_KEY_SW_6_BIT    BV(0)
    #define HAL_KEY_SW_6_SEL    P0SEL
    #define HAL_KEY_SW_6_DIR    P0DIR
    
    /* edge interrupt */
    #define HAL_KEY_SW_6_EDGEBIT  BV(0)
    #define HAL_KEY_SW_6_EDGE     HAL_KEY_FALLING_EDGE
    
    
    /* SW_6 interrupts */
    #define HAL_KEY_SW_6_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_6_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_6_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_6_ICTLBIT  BV(0) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_6_PXIFG    P0IFG /* Interrupt flag at source */
    ////////////////////////////////////////////////////////////////////////////////
    //按键2
    #define HAL_KEY_SW_7_PORT   P0
    #define HAL_KEY_SW_7_BIT    BV(1)
    #define HAL_KEY_SW_7_SEL    P0SEL
    #define HAL_KEY_SW_7_DIR    P0DIR
    
    /* edge interrupt */
    #define HAL_KEY_SW_7_EDGEBIT  BV(0)
    #define HAL_KEY_SW_7_EDGE     HAL_KEY_FALLING_EDGE
    
    
    /* SW_6 interrupts */
    #define HAL_KEY_SW_7_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_7_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_7_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_7_ICTLBIT  BV(1) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_7_PXIFG    P0IFG /* Interrupt flag at source */
    ////////////////////////////////////////////////////////////////////////////////
    //按键3
    #define HAL_KEY_SW_8_PORT   P0
    #define HAL_KEY_SW_8_BIT    BV(2)
    #define HAL_KEY_SW_8_SEL    P0SEL
    #define HAL_KEY_SW_8_DIR    P0DIR
    
    /* edge interrupt */
    #define HAL_KEY_SW_8_EDGEBIT  BV(0)
    #define HAL_KEY_SW_8_EDGE     HAL_KEY_FALLING_EDGE
    
    
    /* SW_6 interrupts */
    #define HAL_KEY_SW_8_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_8_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_8_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_8_ICTLBIT  BV(2) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_8_PXIFG    P0IFG /* Interrupt flag at source */

  • 看看有沒有其他程序佔用了P0.1/P0.2