TI中文支持网
TI专业的中文技术问题搜集分享网站

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

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
  }

 

YiKai Chen:

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

user5367314:

回复 YiKai Chen:

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;
}

YiKai Chen:

回复 user5367314:

你的SW7和SW8設置是什麼?

Alvin Chen:

回复 user5367314:

如果你想用中断类型的按键,可以直接用参考下面的原始DEMO.
www.ti.com.cn/…/getliterature.tsp

user5367314:

回复 YiKai Chen:

//按键1
#define PUSH1_BVBV(0)
#define PUSH1_SBITP0_0

//按键2
#define PUSH3_BVBV(1)
#define PUSH3_SBITP0_1

//按键3
#define PUSH4_BVBV(2)
#define PUSH4_SBITP0_2

YiKai Chen:

回复 user5367314:

我指的是HAL_KEY_SW_7_ICTL/HAL_KEY_SW_7_ICTLBIT/HAL_KEY_SW_7_IEN/HAL_KEY_SW_7_IENBIT…這些有設置好嗎?

user5367314:

回复 YiKai Chen:

按键1(P0.0)可以中断,按键2(P0.1)和3(p0.2)不行
//按键1
#define HAL_KEY_SW_6_PORTP0
#define HAL_KEY_SW_6_BITBV(0)
#define HAL_KEY_SW_6_SELP0SEL
#define HAL_KEY_SW_6_DIRP0DIR/* edge interrupt */
#define HAL_KEY_SW_6_EDGEBITBV(0)
#define HAL_KEY_SW_6_EDGEHAL_KEY_FALLING_EDGE/* SW_6 interrupts */
#define HAL_KEY_SW_6_IENIEN1/* CPU interrupt mask register */
#define HAL_KEY_SW_6_IENBITBV(5) /* Mask bit for all of Port_0 */
#define HAL_KEY_SW_6_ICTLP0IEN /* Port Interrupt Control register */
#define HAL_KEY_SW_6_ICTLBITBV(0) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_6_PXIFGP0IFG /* Interrupt flag at source */
////////////////////////////////////////////////////////////////////////////////
//按键2
#define HAL_KEY_SW_7_PORTP0
#define HAL_KEY_SW_7_BITBV(1)
#define HAL_KEY_SW_7_SELP0SEL
#define HAL_KEY_SW_7_DIRP0DIR/* edge interrupt */
#define HAL_KEY_SW_7_EDGEBITBV(0)
#define HAL_KEY_SW_7_EDGEHAL_KEY_FALLING_EDGE/* SW_6 interrupts */
#define HAL_KEY_SW_7_IENIEN1/* CPU interrupt mask register */
#define HAL_KEY_SW_7_IENBITBV(5) /* Mask bit for all of Port_0 */
#define HAL_KEY_SW_7_ICTLP0IEN /* Port Interrupt Control register */
#define HAL_KEY_SW_7_ICTLBITBV(1) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_7_PXIFGP0IFG /* Interrupt flag at source */
////////////////////////////////////////////////////////////////////////////////
//按键3
#define HAL_KEY_SW_8_PORTP0
#define HAL_KEY_SW_8_BITBV(2)
#define HAL_KEY_SW_8_SELP0SEL
#define HAL_KEY_SW_8_DIRP0DIR/* edge interrupt */
#define HAL_KEY_SW_8_EDGEBITBV(0)
#define HAL_KEY_SW_8_EDGEHAL_KEY_FALLING_EDGE/* SW_6 interrupts */
#define HAL_KEY_SW_8_IENIEN1/* CPU interrupt mask register */
#define HAL_KEY_SW_8_IENBITBV(5) /* Mask bit for all of Port_0 */
#define HAL_KEY_SW_8_ICTLP0IEN /* Port Interrupt Control register */
#define HAL_KEY_SW_8_ICTLBITBV(2) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_8_PXIFGP0IFG /* Interrupt flag at source */

YiKai Chen:

回复 user5367314:

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

赞(0)
未经允许不得转载:TI中文支持网 » 从Zigbee协议栈底层添加自己的按键配置
分享到: 更多 (0)