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.
大家好、
今天、我订购了 CC2530器件、在我的项目中用作开关遥控器、它还将与第三方器件(EFR32MG12芯片实验室协调员)一起加入我的 ZigBee 网络。
我可以在这里为 CC2530器件提供任何用于开关(按钮)操作的预定义代码(示例代码)。
我想知道 IDE 中是否有任何代码 可用于使用适用于 CC2530器件的 ZigBee 3.0进行开关按钮操作?
请告诉我、谢谢您。
您好!
请 下载 Z-Stack 3.0.2软件、并参阅 Z-Stack 3.0.2\projects\Zstack\HomeAutomation 文件夹、了解要导入到 IAR EW8051 10.20.1中的示例项目
此致、
Ryan
尊敬的 Ryan、
感谢您提供即时 回复和 信息。
如上所述、我使用第三方器件作为协调器 EFR32MG12。
我将 CC2530或 CC2531添加 到由协调器(EFR32MG12)创建的 ZigBee 网络中。
我如何从协调器接收 ZCL 命令或向正在 使用或正在使用另一个 IDE 的协调器或路由器发送开/关命令。
如何使用 ZCL 命令通过协调器(EFR32MG12)将此 CC2530 (交换机)添加到 ZigBee 网络中?
请告诉我、谢谢您。
此致
SRI
您好、Sri、
请参阅 "Documents"文件夹中的"Z-Stack 3.0 Developer's Guide"和"Sample Application User's Guide"。 我建议您从 CC2530 ZC 开始、了解默认示例的工作原理。 您还可以使用监听器器件并使用数据包监听器2或 Ubiqua 软件查看无线数据包。 您可以参考几篇类似的 E2E 帖子。
此致、
Ryan
尊敬的:
感谢您提供相关信息。 如您所述、我下载了 Z-Stack 3.0.2、并将采样开关和采样光导入了 IAR 10.20.1版本 EW。
稍后、通过使用 CC 调试器、我将固件分别下载并调试到我的 CC2530 (光协调器)和 CC2530 (开关端器件)器件中。 我的 CC2530开关和光源器件都没有显示屏。
我下载了智能 RF7 闪存编程器 、 以便在按下开关器件中的按钮时检查协调器和终端设备之间的 OTA 和数据包监听器。
但我首先不了解如何使用 ZCL 命令在器件之间创建网络。
请告诉我如何使用开/关按钮的 ZCL 命令和切换 LED (创建、绑定和发送)在该协调器和终端设备之间形成网状网络。
感谢你的帮助。
不建议将 CC2530用于新的 Zigbee 3.0产品。 我建议您购买 LAUNCHXL-CC2652R1并将其用于新的 Zigbee 3.0设计。
尊敬的 Yk:
感谢您提供相关信息。
是否有任何示例说明如何 通过修改 zcl_samplesw.c 文件来手动调用 bdb_StartCommissioning? 用于不使用 SMARTRF05EBK 的 CC2530或 CC2531的按钮和 LED 操作。
我曾看到过以下 E2E 帖子:
但我不理解如何手动执行它。 请帮助并告诉我、谢谢您。
我假设您可以在 zclSampleSw_Init 结束时调用 bdb_StartCommissing。 如果您的 EVB 上有按钮、则可以在 zclSampleSw_HandleKeys 中调用 bdb_StartCommissing、该操作将在按下按钮时触发。
尊敬的:
在 CC2531器件中、我有2个按钮 S1和 S2。
我能否使用 该 S1和 S2中的任何一个按钮、我是否可以将它们用于我的操作。 我现在能否将它们用于该测试。 或者我是否需要使用任何外部按钮?
请告诉我、 谢谢您
如果您正确配置这些按钮的 GPI、我认为使用它们没有问题。
尊敬的:
在光协调 器器件中、我调用了:
"bDB_StartCommissioning (BDB_TUSITING_MODE_NWK_formation); in zclSampleLight_Init();
在开关终端设备中、我调用了:
BDB_StartCommissioning (BDB_commissioning_mode_NWK_Steering);in zclSampleSw_Init();
在两个开关和灯中、我都为手键调用了以下函数。
静态空 zclSample_HandleKeys (字节移位、字节键)
{
IF (键和 HAL_KEY_SW_2)
{
BDB_StartCommissioning (BDB_commissioning_modes);
HalLedSet (LED2_BV、HAL_LED_MODE_BLINK);//闪烁硬件 LED
}
IF (键和 HAL_KEY_SW_1)
{
BDB_StartCommissioning (BDB_commissioning_modes);
HalLedSet (LED2_BV、HAL_LED_MODE_OFF);//闪烁硬件 LED
}
}
我没有机会使用任何用于按钮的硬件引脚、我只使用了默认 值、而对于 LED、我还添加了任何称为 LED2_BV 的 LED。
但它不起作用、我在两个器件中都看不到任何响应。
请告诉我发生了什么错误。 谢谢你
尊敬的:
在 hal_board_cfg.h 中可以看到我的按钮
在开关器件中不按任何按钮、在轻量器件中进行调试后、我可以看到 LED 闪烁自动打开/关闭。 请帮助解决此问题。 谢谢你。
(我在事故中按下了您之前的消息"TI 认为已解决")
如果您有 CC 调试器和 CC2531EMK、请使用 IAR 调试器设置断点并暂停您的程序操作以查看调用堆栈。 如果器件是 ZC、闪烁仅持续三分钟、则这可能是网络加入过程。 否则 、您的代码可能卡在 HAL 断言中。
此致、
Ryan
您应该修改 hal_key.c 以使用 S1和 S2。
尊敬的:
感谢您提供相关信息。
正如您提到的、我在 hal_key.c 中进行了更改
根据 CC2531原理图:
S1按钮为 P1_2
S2按钮为 P1_3
正如我在 hal_board_cfg.h 中的按钮中提到的、
#define ACTIVE_LOW!
#define ACTIVE_HIGH!! /*双重否定强制结果为'1'*/
/* S1 */
#define PUSH1_BV BV (2)
#define PUSH1_SBIT P1_2
#IF 定义(HAL_Board_CC2530EB_REV17)
#define PUSH1_POLARITY ACTIVE_HIGH
定义了#Elif (HAL_Board_CC2530EB_REV13)
#define PUSH1_POLARITY ACTIVE_LOW
其他
#ERROR 未知电路板标识符
#endif
/* S2 */
#define PUSH2_BV BV (3)
#define PUSH2_SBIT P1_3
#define PUSH2_POLARITY ACTIVE_HIGH
稍后、
现在、我进行了更改、正如您在 hal_key.c 文件中提到的、如下所示。
/* SW_6位于 P1.2 *
#define HAL_KEY_SW_6_PORT P1
#define HAL_KEY_SW_6_BIT BV (2)
#define HAL_KEY_SW_6_SEL P1SEL
#define HAL_KEY_SW_6_DIR P1DIR
/*边沿中断*/
#define HAL_KEY_SW_6_EDGEBIT BV (2)
#define HAL_KEY_SW_6_EDGE HAL_KEY_FALLING_EDGE
/* SW_6中断*/
#define HAL_KEY_SW_6_IEN IEN1 /* CPU 中断屏蔽寄存器*
#define HAL_KEY_SW_6_IENBIT BV (5)/*所有 Port_0的掩码位*/
#define HAL_KEY_SW_6_ICTL P1IEN //端口中断控制寄存器*/
#define HAL_KEY_SW_6_ICTLBIT BV (2)/* P0IEN - P0.1启用/禁用位*
#define HAL_KEY_SW_6_PXIFG P1IFG //源中断标志*
我没有在 P1.3上使用过// Joy Stick 移动我的按钮 s2 P1.3。 因为我在其他一些 E2E 帖子中阅读了您的答案、 因为 Joystick 使用 P2.0和 ADC 读数、因此不适合更改。
我克隆 SW6 P1.2并针对 P1.3 -s2按钮进行了修订。
/* SW_6位于 P1.3中*/
#define HAL_KEY_SW_6_PORT P1
#define HAL_KEY_SW_6_BIT BV (3)
#define HAL_KEY_SW_6_SEL P1SEL
#define HAL_KEY_SW_6_DIR P1DIR
/*边沿中断*/
#define HAL_KEY_SW_6_EDGEBIT BV (3)
#define HAL_KEY_SW_6_EDGE HAL_KEY_FALLING_EDGE
/* SW_6中断*/
#define HAL_KEY_SW_6_IEN IEN1 /* CPU 中断屏蔽寄存器*
#define HAL_KEY_SW_6_IENBIT BV (5)/*所有 Port_0的掩码位*/
#define HAL_KEY_SW_6_ICTL P1IEN //端口中断控制寄存器*/
#define HAL_KEY_SW_6_ICTLBIT BV (3)/* P0IEN - P0.1启用/禁用位*
#define HAL_KEY_SW_6_PXIFG P1IFG //源中断标志*
但它仍然不起作用、请帮我、谢谢您。
要将 P1.2用作 GPI 来触发按钮中断、您无法正确配置寄存器。 您应该修改 P1.2的以下寄存器。 您可以参考 CC253x 用户指南 了解正确的寄存器设置。
/* edge interrupt */ #define HAL_KEY_SW_6_EDGEBIT BV(1) #define HAL_KEY_SW_6_EDGE HAL_KEY_FALLING_EDGE /* SW_6 interrupts */ #define HAL_KEY_SW_6_IEN IEN2 /* CPU interrupt mask register */ #define HAL_KEY_SW_6_IENBIT BV(4) /* Mask bit for all of Port_0 */ #define HAL_KEY_SW_6_ICTL P1IEN /* Port Interrupt Control register */ #define HAL_KEY_SW_6_ICTLBIT BV(2) /* P1IEN - P1.2 enable/disable bit */ #define HAL_KEY_SW_6_PXIFG P1IFG /* Interrupt flag at source */
尊敬的 YK,
非常感谢您的帮助。
正如我对 按钮 S1 - P1.2所做的那样、 我对按钮 S2 -P1.3也做了同样的操作。
但对于按钮 P1.3、我收到了警告、表示宏的重新定义不兼容。
我是否需要考虑该警告? 还是可以忽略它。
请告诉我。 谢谢你。
这是明显的警告。 您已定义 HAL_KEY_SW_6_BIT 和 HAL_KEY_SW_6_ICTLBIT 两次。 我不是说讲座、但这在 C 编程中非常基础。
尊敬的:
正如我提到的, 我在 zclSampleSw_Init()中添加了 bdb_StartCommissioning (BDB_commissioning_mode_NWK_Steering);
我使用 S1和 S2作为开关 P1.2和 P1.3。
根据以下宏 、我在 zclSampleSw.c 中使用了它们
#define HAL_KEY_SW_6 0x20 //按钮 S1 (如果可用)
#define HAL_KEY_SW_7 0x40 //按钮 S2 (如果可用)
我在 zclSampleSw.c 文件的函数中使用了它们。
静态空 zclSampleSw_HandleKeys (字节移位、字节键)
{
IF (键和 HAL_KEY_SW_7)
{
BDB_StartCommissioning (BDB_commissioning_modes);
HalLedSet (LED2_BV、HAL_LED_MODE_BLINK);//闪烁硬件 LED
}
IF (键和 HAL_KEY_SW_6)
{
BDB_StartCommissioning (BDB_commissioning_modes);
HalLedSet (LED2_BV、HAL_LED_MODE_OFF);//闪烁硬件 LED
}
}
稍后、我按照您提到的如下代码对 hal_key.c 进行了更改。 我甚至还尝试通过设置断点来查找问题、但 我 不理解问题。
我在 hal_key.c 中进行了更改、如上所述。 但我不明白为什么它不起作用。
请帮我、谢谢。
#include "hal_mcu.h" #include "hal_defs.h" #include "hal_types.h" #include "hal_board.h" #include "hal_drivers.h" #include "hal_adc.h" #include "hal_key.h" #include "osal.h" #if (defined HAL_KEY) && (HAL_KEY == TRUE) /************************************************************************************************** * MACROS **************************************************************************************************/ /************************************************************************************************** * CONSTANTS **************************************************************************************************/ #define HAL_KEY_RISING_EDGE 0 #define HAL_KEY_FALLING_EDGE 1 #define HAL_KEY_DEBOUNCE_VALUE 25 /* CPU port interrupt */ #define HAL_KEY_CPU_PORT_0_IF P0IF #define HAL_KEY_CPU_PORT_1_IF P0IF #define HAL_KEY_CPU_PORT_2_IF P2IF /* SW_6 is at P0.1 */ #define HAL_KEY_SW_6_PORT P1 #define HAL_KEY_SW_6_BIT BV(2) #define HAL_KEY_SW_6_SEL P1SEL #define HAL_KEY_SW_6_DIR P1DIR /* edge interrupt */ #define HAL_KEY_SW_6_EDGEBIT BV(1) #define HAL_KEY_SW_6_EDGE HAL_KEY_FALLING_EDGE /* SW_6 interrupts */ #define HAL_KEY_SW_6_IEN IEN2 /* CPU interrupt mask register */ #define HAL_KEY_SW_6_IENBIT BV(4) /* Mask bit for all of Port_0 */ #define HAL_KEY_SW_6_ICTL P1IEN /* Port Interrupt Control register */ #define HAL_KEY_SW_6_ICTLBIT BV(2) /* P0IEN - P0.1 enable/disable bit */ #define HAL_KEY_SW_6_PXIFG P1IFG /* Interrupt flag at source */ /* SW_2 is at P1.3 */ #define HAL_KEY_SW_7_PORT P1 #define HAL_KEY_SW_7_BIT BV(3) #define HAL_KEY_SW_7_SEL P1SEL #define HAL_KEY_SW_7_DIR P1DIR /* edge interrupt */ #define HAL_KEY_SW_7_EDGEBIT BV(1) #define HAL_KEY_SW_7_EDGE HAL_KEY_RISING_EDGE /* SW_6 interrupts */ #define HAL_KEY_SW_7_IEN IEN2 /* CPU interrupt mask register */ #define HAL_KEY_SW_7_IENBIT BV(4) /* Mask bit for all of Port_0 */ #define HAL_KEY_SW_7_ICTL P1IEN /* Port Interrupt Control register */ #define HAL_KEY_SW_7_ICTLBIT BV(3) /* P0IEN - P0.1 enable/disable bit */ #define HAL_KEY_SW_7_PXIFG P1IFG /* Interrupt flag at source */ /* Joy stick move at P2.0 */ #define HAL_KEY_JOY_MOVE_PORT P2 #define HAL_KEY_JOY_MOVE_BIT BV(0) #define HAL_KEY_JOY_MOVE_SEL P2SEL #define HAL_KEY_JOY_MOVE_DIR P2DIR /* edge interrupt */ #define HAL_KEY_JOY_MOVE_EDGEBIT BV(3) #define HAL_KEY_JOY_MOVE_EDGE HAL_KEY_FALLING_EDGE /* Joy move interrupts */ #define HAL_KEY_JOY_MOVE_IEN IEN2 /* CPU interrupt mask register */ #define HAL_KEY_JOY_MOVE_IENBIT BV(1) /* Mask bit for all of Port_2 */ #define HAL_KEY_JOY_MOVE_ICTL P2IEN /* Port Interrupt Control register */ #define HAL_KEY_JOY_MOVE_ICTLBIT BV(0) /* P2IENL - P2.0<->P2.3 enable/disable bit */ #define HAL_KEY_JOY_MOVE_PXIFG P2IFG /* Interrupt flag at source */ #define HAL_KEY_JOY_CHN HAL_ADC_CHANNEL_6 /************************************************************************************************** * TYPEDEFS **************************************************************************************************/ /************************************************************************************************** * GLOBAL VARIABLES **************************************************************************************************/ static uint8 halKeySavedKeys; /* used to store previous key state in polling mode */ static halKeyCBack_t pHalKeyProcessFunction; static uint8 HalKeyConfigured; bool Hal_KeyIntEnable; /* interrupt enable/disable flag */ /************************************************************************************************** * FUNCTIONS - Local **************************************************************************************************/ void halProcessKeyInterrupt(void); uint8 halGetJoyKeyInput(void); /************************************************************************************************** * FUNCTIONS - API **************************************************************************************************/ /************************************************************************************************** * @fn HalKeyInit * * @brief Initilize Key Service * * @param none * * @return None **************************************************************************************************/ void HalKeyInit( void ) { /* Initialize previous key to 0 */ halKeySavedKeys = 0; HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT); /* Set pin function to GPIO */ HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT); #if ! defined ENABLE_LED4_DISABLE_S1 HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT); /* Set pin direction to Input */ #endif #if ! defined ENABLE_LED4_DISABLE_S1 HAL_KEY_SW_7_DIR &= ~(HAL_KEY_SW_7_BIT); /* Set pin direction to Input */ #endif HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT ); /* Set pin function to GPIO */ HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT ); /* Set pin direction to Input */ /* Initialize callback function */ pHalKeyProcessFunction = NULL; /* Start with key is not configured */ HalKeyConfigured = FALSE; } /************************************************************************************************** * @fn HalKeyConfig * * @brief Configure the Key serivce * * @param interruptEnable - TRUE/FALSE, enable/disable interrupt * cback - pointer to the CallBack function * * @return None **************************************************************************************************/ 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_RISING_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);; /* 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 */ osal_set_event(Hal_TaskID, HAL_KEY_EVENT); } /* Key now is configured */ HalKeyConfigured = TRUE; } /************************************************************************************************** * @fn HalKeyRead * * @brief Read the current value of a key * * @param None * * @return keys - current keys status **************************************************************************************************/ uint8 HalKeyRead ( void ) { uint8 keys = 0; if (HAL_PUSH_BUTTON1()) { keys |= HAL_KEY_SW_6; } if (HAL_PUSH_BUTTON2()) { keys |= HAL_KEY_SW_7; } if ((HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT)) /* Key is active low */ { keys |= halGetJoyKeyInput(); } if ((HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low */ { keys |= halGetJoyKeyInput(); } return keys; } /************************************************************************************************** * @fn HalKeyPoll * * @brief Called by hal_driver to poll the keys * * @param None * * @return None **************************************************************************************************/ void HalKeyPoll (void) { uint8 keys = 0; if ((HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT)) /* Key is active Low */ { keys = halGetJoyKeyInput(); } if ((HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active High */ { keys = halGetJoyKeyInput(); } /* If interrupts are not enabled, previous key status and current key status * are compared to find out if a key has changed status. */ if (!Hal_KeyIntEnable) { if (keys == halKeySavedKeys) { /* Exit - since no keys have changed */ return; } /* Store the current keys for comparation next time */ halKeySavedKeys = keys; } else { /* Key interrupt handled here */ } if (HAL_PUSH_BUTTON1()) { keys |= HAL_KEY_SW_6; } if (HAL_PUSH_BUTTON2()) { keys |= HAL_KEY_SW_7; } /* Invoke Callback if new keys were depressed */ if (pHalKeyProcessFunction #ifdef HAL_LEGACY_KEYS && keys //in legacy modes, only report key presses and do not report when a key is released #endif ) { (pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL); } } /************************************************************************************************** * @fn halGetJoyKeyInput * * @brief Map the ADC value to its corresponding key. * * @param None * * @return keys - current joy key status **************************************************************************************************/ uint8 halGetJoyKeyInput(void) { /* The joystick control is encoded as an analog voltage. * Read the JOY_LEVEL analog value and map it to joy movement. */ uint8 ksave0 = 0; uint8 ksave1; /* Keep on reading the ADC until two consecutive key decisions are the same. */ do { ksave1 = ksave0; /* save previouse key reading */ if (HAL_PUSH_BUTTON1()) { ksave0 |= HAL_KEY_SW_6; } else if(HAL_PUSH_BUTTON2()) { ksave0 |= HAL_KEY_SW_7; } } while (ksave0 != ksave1); return ksave0; } /************************************************************************************************** * @fn halProcessKeyInterrupt * * @brief Checks to see if it's a valid key interrupt, saves interrupt driven key states for * processing by HalKeyRead(), and debounces keys by scheduling HalKeyRead() 25ms later. * * @param * * @return **************************************************************************************************/ void halProcessKeyInterrupt (void) { bool valid=FALSE; if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT) /* Interrupt Flag has been set */ { HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT); /* Clear Interrupt Flag */ valid = TRUE; } if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) /* Interrupt Flag has been set */ { HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT); /* Clear Interrupt Flag */ valid = TRUE; } if (HAL_KEY_JOY_MOVE_PXIFG & HAL_KEY_JOY_MOVE_BIT) /* Interrupt Flag has been set */ { HAL_KEY_JOY_MOVE_PXIFG = ~(HAL_KEY_JOY_MOVE_BIT); /* Clear Interrupt Flag */ valid = TRUE; } if (valid) { osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_DEBOUNCE_VALUE); } } /************************************************************************************************** * @fn HalKeyEnterSleep * * @brief - Get called to enter sleep mode * * @param * * @return **************************************************************************************************/ void HalKeyEnterSleep ( void ) { } /************************************************************************************************** * @fn HalKeyExitSleep * * @brief - Get called when sleep is over * * @param * * @return - return saved keys **************************************************************************************************/ uint8 HalKeyExitSleep ( void ) { /* Wake up and read keys */ return ( HalKeyRead () ); } /*************************************************************************************************** * INTERRUPT SERVICE ROUTINE ***************************************************************************************************/ /************************************************************************************************** * @fn halKeyPort0Isr * * @brief Port0 ISR * * @param * * @return **************************************************************************************************/ HAL_ISR_FUNCTION( halKeyPort1Isr, P0INT_VECTOR ) { HAL_ENTER_ISR(); if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT) { halProcessKeyInterrupt(); } if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) { halProcessKeyInterrupt(); } /* Clear the CPU interrupt flag for Port_0 PxIFG has to be cleared before PxIF */ HAL_KEY_SW_6_PXIFG = 0; HAL_KEY_SW_7_PXIFG = 0; HAL_KEY_CPU_PORT_1_IF = 0; CLEAR_SLEEP_MODE(); HAL_EXIT_ISR(); } /************************************************************************************************** * @fn halKeyPort2Isr * * @brief Port2 ISR * * @param * * @return **************************************************************************************************/ HAL_ISR_FUNCTION( halKeyPort2Isr, P2INT_VECTOR ) { HAL_ENTER_ISR(); if (HAL_KEY_JOY_MOVE_PXIFG & HAL_KEY_JOY_MOVE_BIT) { halProcessKeyInterrupt(); } /* Clear the CPU interrupt flag for Port_2 PxIFG has to be cleared before PxIF Notes: P2_1 and P2_2 are debug lines. */ HAL_KEY_JOY_MOVE_PXIFG = 0; HAL_KEY_CPU_PORT_2_IF = 0; CLEAR_SLEEP_MODE(); HAL_EXIT_ISR(); } #else void HalKeyInit(void){} void HalKeyConfig(bool interruptEnable, halKeyCBack_t cback){} uint8 HalKeyRead(void){ return 0;} void HalKeyPoll(void){} #endif /* HAL_KEY */
您在调试过程中发现了什么? 代码是否经过 zclSampleSw_Init 和 HalKeyInit/HalKeyConfig? 您是否正在使用 CC530或 CC2531、是否在 IAR 中选择了正确的型号?
此致、
Ryan
您是否尝试在“HAL_ISR_function (halKeyPort1Isr,P1INT_vector)”中设置断点,并在按下 Button 时检查它是否成功?
大家好,我在定制板上添加2个按钮时遇到了类似的问题,我发现我的主要问题是在 HalKeyPoll()函数下。
我已经使用 HAL_PUSH_Button1 (HAL_KEY_SW_6 - 0x20)和 HAL_PUSH_Button2 (HAL_KEY_SW_7 -0x40)。 当我设置断点时,我观察到两个按钮同时到达 ,之后键值为0x60。 发生这种情况时、我的器件会同时打开或关闭两个 LED 和 PINT 相关的 OnOff 电路。 我的n´t 无法看到 HAL_push_Button1或 HAL_push_ Button2之间的差异。
注意:中断的第一个步骤运行良好、我可以使用 HAL_KEY_SW_6_PXIFG 和 HAL_KEY_SW_6_BIT 或 HAL_KEY_SW_7_PXIFG 和 HAL_KEY_SW_7_BIT 上的断点来查看中断。 当按下 S1或 S2时!
是否确定在按下 S1或 S2时触发了“HAL_ISR_function (halKeyPort1Isr、P1INT_vector)”?
尊敬的:
感谢您提供相关信息。
是的,正如您提到的那样,我通过 在 “HAL_ISR_function (halKeyPort1Isr,P1INT_vector)”中设置断点进行了检查。
按下按钮或运行时按下下一条语句时、我无法到达断点。
我看到我的代码在 osal_run_system()处是结构;
请告诉我如何解决 此问题。 谢谢你。
您是否在项目的"定义的符号"中定义了 ISR_KEYINTERRUPT?
尊敬的:
我了解您的项目中的"定义的符号"是什么意思?
在 zcsampleSw.c 中、我创建了
静态空 zclSampleSw_HandleKeys (字节移位、字节键)
{
IF (键和 HAL_KEY_SW_7)
{
BDB_StartCommissioning (BDB_commissioning_modes);
HalLedSet (LED2_BV、HAL_LED_MODE_BLINK);//闪烁硬件 LED
}
IF (键和 HAL_KEY_SW_6)
{
BDB_StartCommissioning (BDB_commissioning_modes);
HalLedSet (LED2_BV、HAL_LED_MODE_OFF);//闪烁硬件 LED
}
}
我在 zcsamplesw.c 中添加了所有相关的 include 文件
定义符号意味着什么? 我在 zcsampleSW 中定义。 C 还是 ZMAIN.C?
请告诉我。
您可以参阅我的屏幕截图。
尊敬的:
感谢屏幕截图、但我 在我定义的符号中有选项 ISR_KEYINTERRUPT:(每行一行)。
我可以做到 以下几点:
SECURE=1
TC_LINKKEY_JOIN
NV_INIT
NV_RESTORE
xPOWER_Saving
NWK_AUTO_POLL
xZTOOL_P1
XMT_TASK
XMT_APP_FUNC
XMT_SYS_FUNC
XMT_ZDO_FUNC
XMT_ZDO_MGMT
XMT_APP_CNF_FUNC
LCD_supported=调试
组播启用=假
ZCL_READ
ZCL_discover
ZCL_WRITE
ZCL_BASIC
ZCL_Identify
ZCL_ON_OFF
ZCL_GROUP。
但我的示例开关项目中的 I DINT 有 IAR_KEYINTERRUPT。 请告诉我、谢谢您。
您必须将 ISR_KEYINTERRUPT (不是 IAR_KEYINTERRUPT)添加到项目的"已定义符号"中、以使关键中断起作用。
尊敬的 YK,
在我想我需要从 已定义符号的可用对话框中添加 IAR_KEYINTERRUPT 之前。 但现在我手动添加了它。
现在,在 HAL_ISR_function (halKeyPort1Isr、P1INT_vector)上放置断点后, 在添加 IAR_KEYINTERRUPT 后按 run (F5)时,我可以看到断点命中
但 当我按下 Device 中的按钮 S1或 S2时,它不会达到 HAL_ISR_function (halKeyPort1Isr、P1INT_vector)。
请告诉我、谢谢 您。
这意味着您没有为 hal_key.c 中的 S1和 S2按钮正确设置寄存器
黄´ll 先生,我打开一个新的论坛帖子。 防止我和 Sri Naga 怀疑之间的混淆!
您好,Sri 先生,正如 Y.K 先生告诉您的,我是说您没有完成密钥配置,包括密钥初始化和密钥配置。 您能在下面的 key.c 文件中看到我的密钥配置了什么。 在本例中、我使用了 P0.1和 P0.4。
注意:在我的情况 下,对于 HAL_KEY_SW_6_PXIFG 和 HAL_KEY_SW_6_BIT 以及 HAL_KEY_SW_7_PXIFG 和 HAL_KEY_SW_7_BIT 的每个通信器行,在 HAL_ISR_Function (halKeyPort1Isr、P0INT_vector)中都有断点命中。
/* SW_6 settings at P0.4 */ //- Definitions #define HAL_KEY_SW_6_ENABLE #define HAL_KEY_SW_6_PORT P0 #define HAL_KEY_SW_6_BIT BV(4) #define HAL_KEY_SW_6_SEL P0SEL #define HAL_KEY_SW_6_DIR P0DIR #define HAL_KEY_SW_6_EDGEBIT BV(0) #define HAL_KEY_SW_6_EDGE HAL_KEY_RISING_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(4) /* P0IEN - P0.4 enable/disable bit */ #define HAL_KEY_SW_6_PXIFG P0IFG /* Interrupt flag at source */ /* SW_7 settings at P0.1 */ // - Definitions #define HAL_KEY_SW_7_ENABLE #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 #define HAL_KEY_SW_7_EDGEBIT BV(0) #define HAL_KEY_SW_7_EDGE HAL_KEY_RISING_EDGE /* SW_7 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 */ /************************************************************************************************** * @fn HalKeyInit * * @brief Initilize Key Service * * @param none * * @return None **************************************************************************************************/ void HalKeyInit( void ) { /* Initialize previous key to 0 */ halKeySavedKeys = 0; HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT); /* Set pin function to GPIO */ HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT); /* Set pin direction to Input */ HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT); /* Set pin function to GPIO */ HAL_KEY_SW_7_DIR &= ~(HAL_KEY_SW_7_BIT); /* Set pin direction to Input */ /* Initialize callback function */ pHalKeyProcessFunction = NULL; /* Start with key is not configured */ HalKeyConfigured = FALSE; } /************************************************************************************************** * @fn HalKeyConfig * * @brief Configure the Key serivce * * @param interruptEnable - TRUE/FALSE, enable/disable interrupt * cback - pointer to the CallBack function * * @return None **************************************************************************************************/ 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 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 */ /* Interrupt configuration: * - Enable interrupt generation at the port * - Enable CPU interrupt * - Clear any pending interrupt */ /* 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 */ osal_set_event(Hal_TaskID, HAL_KEY_EVENT); } /* Key now is configured */ HalKeyConfigured = TRUE; }
尊敬的 Alexander Argollo:
非常感谢您的友好帮助。
尊敬的:
我想我根据您上面的参考文献、使用正确的寄存器设置了开关6p1.2。
* SW_6位于 P1.2 */
#define HAL_KEY_SW_6_PORT P1
#define HAL_KEY_SW_6_BIT BV (2)
#define HAL_KEY_SW_6_SEL P1SEL
#define HAL_KEY_SW_6_DIR P1DIR
/*边沿中断*/
#define HAL_KEY_SW_6_EDGEBIT BV (2)
#define HAL_KEY_SW_6_EDGE HAL_KEY_FALLING_EDGE
/* SW_6中断*/
#define HAL_KEY_SW_6_IEN IEN1 /* CPU 中断屏蔽寄存器*
#define HAL_KEY_SW_6_IENBIT BV (4)/*所有 Port_1的掩码位*/
#define HAL_KEY_SW_6_ICTL P1IEN //端口中断控制寄存器*/
#define HAL_KEY_SW_6_ICTLBIT BV (2)/* P0IEN - P1.2启用/禁用位*
#define HAL_KEY_SW_6_PXIFG P1IFG //源中断标志*
/* SW_7位于 P1.3中*/
#define HAL_KEY_SW_7_PORT P1
#define HAL_KEY_SW_7_BIT BV (3)
#define HAL_KEY_SW_7_SEL P1SEL
#define HAL_KEY_SW_7_DIR P1DIR
/*边沿中断*/
#define HAL_KEY_SW_7_EDGEBIT BV (2)
#define HAL_KEY_SW_7_EDGE HAL_KEY_RISE_EDGE
/* SW_7中断*/
#define HAL_KEY_SW_7_IEN IEN2 /* CPU 中断屏蔽寄存器*
#define HAL_KEY_SW_7_IENBIT BV (4)/*所有 Port_1的掩码位*/
#define HAL_KEY_SW_7_ICTL P1IEN //端口中断控制寄存器*/
#define HAL_KEY_SW_7_ICTLBIT BV (3)/* P0IEN - P1.3启用/禁用位*
#define HAL_KEY_SW_7_PXIFG P1IFG //源中断标志*
但 s1和 s2没有响应。 s1和 s2寄存器配置中或其他位置中的问题。
请告诉我、谢谢您。
尊敬的:
在下面您可以看到我 的“HAL_ISR_function (halKeyPort1Isr,P1INT_vector)”;
HAL_ISR_function (halKeyPort1Isr、P1INT_vector)
{
HAL_ENTER_ISR ();
IF (HAL_KEY_SW_6_PXIFG 和 HAL_KEY_SW_6_BIT)
{
halProcessKeyInterrupt();
}
IF (HAL_KEY_SW_7_PXIFG 和 HAL_KEY_SW_7_BIT)
{
halProcessKeyInterrupt();
}
/*
清除 Port_0的 CPU 中断标志
PxIFG 必须在 PxIF 前被清零
*
HAL_KEY_SW_6_PXIFG;
HAL_KEY_SW_7_PXIFG;
HAL_KEY_CPU_PORT_1_IF;
CLEAR_SLEEP_MODE();
HAL_EXIT_ISR();
}
void halProcessKeyInterrupt (空)
{
bool 有效=false;
如果(HAL_KEY_SW_6_PXIFG 和 HAL_KEY_SW_6_BIT)/*中断标志已设置
{
HAL_KEY_SW_6_PXIFG =~μ A (HAL_KEY_SW_6_BIT);//清除中断标志*
有效=真;
}
如果(HAL_KEY_SW_7_PXIFG 和 HAL_KEY_SW_7_BIT)/*中断标志已设置
{
HAL_KEY_SW_7_PXIFG =~μ A (HAL_KEY_SW_7_BIT);//清除中断标志*
有效=真;
}
如果(有效)
{
OSAL_START_TIMEREx (HAL_TaskID、HAL_KEY_EVENT、HAL_KEY_debounce_value);
}
}
很高兴让我知道我出错了、谢谢您。
SRI 先生、您能否将其视为 hal_board_cfg.h 配置的参考(根据 P0端口)。 请根据您使用的 P1.2和 P1.3检查您的配置!
/* S1 */ #define PUSH1_BV BV(4) #define PUSH1_SBIT P0_4 #define PUSH1_POLARITY ACTIVE_HIGH /* S2 */ #define PUSH2_BV BV(1) #define PUSH2_SBIT P0_1 #define PUSH2_POLARITY ACTIVE_HIGH
尊敬的 Alexander Argollo:
感谢您的回复和 帮助。
是的、但我也以相同的方式执行了。
* S1 */ p1.2
#define PUSH1_BV BV (2)
#define PUSH1_SBIT P1_2
#IF 定义(HAL_Board_CC2530EB_REV17)
#define PUSH1_POLARITY ACTIVE_HIGH
定义了#Elif (HAL_Board_CC2530EB_REV13)
#define PUSH1_POLARITY ACTIVE_LOW
其他
#ERROR 未知电路板标识符
#endif
/* S2 * / P1.3
#define PUSH2_BV BV (3)
#define PUSH2_SBIT P1_3
#define PUSH2_POLARITY ACTIVE_HIGH
斯里先生,
您是否可以观察到在 预定义符号 HAL_Board_CC2530EB_REV17之间使用 S1 / PUSH1_POLARITY。 如果 您未在编译器选项符号中使用它、请取出(#define PUSH1_POLARITY ACTIVE_HIGH)并按照 您在 S2中定义的方式执行操作、或者如果您使用时包含内部的所有这些行。
* S1 */ p1.2 #define PUSH1_BV BV(2) #define PUSH1_SBIT P1_2 #define PUSH1_POLARITY ACTIVE_HIGH /* S2 */ P1.3 #define PUSH2_BV BV(3) #define PUSH2_SBIT P1_3 #define PUSH2_POLARITY ACTIVE_HIGH
尊敬的 Alexander Argollo:
是的,当 我按下按钮 S1 和 S2时,即使我的 s1或 s2没有到达断点 HAL_ISR_function (halKeyPort1Isr、P1INT_vector),我也会删除该宏。
始终感谢您 提供的友好帮助和信息。
对于 SW6 (P1.2)、我在 hal_key.c 中使用以下代码
#define HAL_KEY_CPU_PORT_1_IF P1IF /* SW_6 is at P1.2 */ #define HAL_KEY_SW_6_PORT P1 #define HAL_KEY_SW_6_BIT BV(2) #define HAL_KEY_SW_6_SEL P1SEL #define HAL_KEY_SW_6_DIR P1DIR /* edge interrupt */ #define HAL_KEY_SW_6_EDGEBIT BV(1) #define HAL_KEY_SW_6_EDGE HAL_KEY_FALLING_EDGE /* SW_6 interrupts */ #define HAL_KEY_SW_6_IEN IEN2 /* CPU interrupt mask register */ #define HAL_KEY_SW_6_IENBIT BV(4) /* Mask bit for all of Port_0 */ #define HAL_KEY_SW_6_ICTL P1IEN /* Port Interrupt Control register */ #define HAL_KEY_SW_6_ICTLBIT BV(2) /* P1IEN - P1.2 enable/disable bit */ #define HAL_KEY_SW_6_PXIFG P1IFG /* Interrupt flag at source */ HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR ) { HAL_ENTER_ISR(); if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT) { halProcessKeyInterrupt(); } /* Clear the CPU interrupt flag for Port_0 PxIFG has to be cleared before PxIF */ HAL_KEY_SW_6_PXIFG = 0; HAL_KEY_CPU_PORT_1_IF = 0; CLEAR_SLEEP_MODE(); HAL_EXIT_ISR(); }
我还将 hal_board_cfg.h 中 P1.2的以下代码修改为 HAL_push_Button1
#define PUSH1_BV BV(2) #define PUSH1_SBIT P1_2
通过按 CC2531 USB 软件狗中的 S1来触发 zclSampleSw_HandleKeys 没有问题。
SRI、
正如 Y.K 先生所说、您需要在代码中更改 以下行中的 SW6/P1.2设置:
发件人:
#define HAL_KEY_SW_6_EDGEBIT BV (2)
#define HAL_KEY_SW_6_IEN IEN1 /* CPU 中断屏蔽寄存器*
至:
#define HAL_KEY_SW_6_EDGEBIT BV (1)
#define HAL_KEY_SW_6_IEN IEN2 /* CPU 中断屏蔽寄存器*
我相信、之后您将很好地触发以下行 (HAL_KEY_SW_6_PXIFG 和 HAL_KEY_SW_6_BIT)。
请告诉我们您的进度!
尊敬的 YK,
感谢您提供的信息和帮助。
是的,我按照 与您相同的方式设置寄存器和 HAL_ISR_function (halKeyPort1Isr、P1INT_vector)。
我使用 您和 Alexander 在此处提供的参考信息更改了 p1.2和 p1.3在 hal_board_cfg.h 中的配置。
但是、当我按下 S1或 S2时、仍然无法触发 zclsampleSw_Handlekeys。
在下面、您可以看到 我的静态 void zclSampleSw_HandleKeys 函数。
静态空 zclSampleSw_HandleKeys (字节移位、字节键)
{
IF (键和 HAL_KEY_SW_7)
{
HalLedSet (LED2_BV、HAL_LED_MODE_TOGGLE);//闪烁硬件 LED
}
IF (键和 HAL_KEY_SW_6)
{
HalLedSet (LED2_BV、HAL_LED_MODE_OFF);//闪烁硬件 LED
}
}
在 void zclSampleSw_Init( byte task_id )的末尾,我调用 了 bdb_StartCommissioning();如下所示:
BDB_StartCommissioning (BDB_commissioning_mode_NWK_Steering);
请告诉我出错了、谢谢。
尊敬的 Sri:
我希望您在之前检查一下 :您是否成功在 hal_key.c 中触发(HAL_key_sw_6_PXIFG 和 HAL_key_sw_6_bit)和(HAL_key_sw_7_PXIFG 和 HAL_key_sw_7_bit)?
如果您有,请检查 HalKeyPoll(),如果 您在按下 S1或 S2时成功地触发 HAL_push_Button1和 HAL_push_Button2,以及相应的 Keys 值。 当按下 S1时、您需要获得 SW6 Key = 0x20、当按下 S2时、您需要获得 SW7 Key = 0x40。 根据您在 hal_key.h 中的定义
if (HAL_PUSH_BUTTON1()) { keys |= HAL_KEY_SW_6; } if (HAL_PUSH_BUTTON2()) { keys |= HAL_KEY_SW_7; }
尊敬的 Alexander:
是的、我使用了
#define HAL_KEY_SW_6 0x20 //按钮 S1 (如果可用)
#define HAL_KEY_SW_7 0x40 //按钮 S2 (如果可用)。
没有如您所述、即使在 hal_key.c 中也无法成功触发 i dint。
按下 s1或 s2时、我知道为什么不触发它。 我仍在尝试解决这个问题。
感谢您的帮助和帮助。
您是否尝试使用 SW6 (P1.2)的步骤? 我在 CC2530 USB 软件狗上验证了它。
尊敬的:
在 hal_key.c 中,当我在 HAL_ISR_function (halKeyPort1Isr、P1INT_vector)放置断点时,当我按下 run (F5)时可以到达。
但按下器件 CC2531中的按钮 S1或 S2时无法到达。
#define HAL_KEY_SW_6 0x20 //按钮 S1 (如果可用)
#define HAL_KEY_SW_7 0x40 //按钮 S2 (如果可用)
CC2531:
按钮 S1 - P1.2
按钮 S2 - P1.3
我 按照 您的代码为 S1正确设置寄存器。
请告诉我哪里出错了。 谢谢你。
In zclsamplesw.c void zclSampleSw_Init( byte task_id ) { bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_STEERING); } static void zclSampleSw_HandleKeys( byte shift, byte keys ) { if (keys & HAL_KEY_SW_6) { bdb_StartCommissioning(BDB_COMMISSIONING_MODES); HalLedSet(LED2_BV, HAL_LED_MODE_OFF); //blink hardware LED } if (keys & HAL_KEY_SW_7) { bdb_StartCommissioning(BDB_COMMISSIONING_MODES); HalLedSet(LED2_BV, HAL_LED_MODE_ON); //blink hardware LED } In hal_board_cfg.c #define ACTIVE_LOW ! #define ACTIVE_HIGH !! /* double negation forces result to be '1' */ /* S1 */ #define PUSH1_BV BV(1) #define PUSH1_SBIT P1_2 #define PUSH1_POLARITY ACTIVE_HIGH /* S2 */ #define PUSH2_BV BV(3) #define PUSH2_SBIT P1_3 #define PUSH2_POLARITY ACTIVE_HIGH In hal_key.c #define HAL_KEY_CPU_PORT_1_IF P1IF /* SW_6 is at P1.2 */ #define HAL_KEY_SW_6_PORT P1 #define HAL_KEY_SW_6_BIT BV(2) #define HAL_KEY_SW_6_SEL P1SEL #define HAL_KEY_SW_6_DIR P1DIR /* edge interrupt */ #define HAL_KEY_SW_6_EDGEBIT BV(1) #define HAL_KEY_SW_6_EDGE HAL_KEY_FALLING_EDGE /* SW_6 interrupts */ #define HAL_KEY_SW_6_IEN IEN2 /* CPU interrupt mask register */ #define HAL_KEY_SW_6_IENBIT BV(4) /* Mask bit for all of Port_1 */ #define HAL_KEY_SW_6_ICTL P1IEN /* Port Interrupt Control register */ #define HAL_KEY_SW_6_ICTLBIT BV(2) /* P0IEN - P1.2 enable/disable bit */ #define HAL_KEY_SW_6_PXIFG P1IFG /* Interrupt flag at source */ /* SW_7 is at P1.3 */ #define HAL_KEY_SW_7_PORT P1 #define HAL_KEY_SW_7_BIT BV(3) #define HAL_KEY_SW_7_SEL P1SEL #define HAL_KEY_SW_7_DIR P1DIR /*S7-edge interrupt */ #define HAL_KEY_SW_7_EDGEBIT BV(1) #define HAL_KEY_SW_7_EDGE HAL_KEY_FALLING_EDGE /* SW_7interrupts */ #define HAL_KEY_SW_7_IEN IEN2 /* CPU interrupt mask register */ #define HAL_KEY_SW_7_IENBIT BV(4) /* Mask bit for all of Port_1 */ #define HAL_KEY_SW_7_ICTL P1IEN /* Port Interrupt Control register */ #define HAL_KEY_SW_7_ICTLBIT BV(3) /* P0IEN - P1.3 enable/disable bit */ #define HAL_KEY_SW_7_PXIFG P1IFG /* Interrupt flag at source */ static uint8 halKeySavedKeys; /* used to store previous key state in polling mode */ static halKeyCBack_t pHalKeyProcessFunction; static uint8 HalKeyConfigured; bool Hal_KeyIntEnable; void halProcessKeyInterrupt(void); uint8 halGetJoyKeyInput(void); uint8 halGetSWKeyInput(void); void HalKeyInit( void ) { /* Initialize previous key to 0 */ halKeySavedKeys = 0; HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT); /* Set pin function to GPIO */ HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT); /* Set pin direction to Input */ HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT); /* Set pin function to GPIO */ HAL_KEY_SW_7_DIR &= ~(HAL_KEY_SW_7_BIT); /* Set pin direction to Input */ /* Initialize callback function */ pHalKeyProcessFunction = NULL; /* Start with key is not configured */ HalKeyConfigured = FALSE; } 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 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); /* 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 */ osal_set_event(Hal_TaskID, HAL_KEY_EVENT); //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 */ osal_set_event(Hal_TaskID, HAL_KEY_EVENT); } /* Key now is configured */ HalKeyConfigured = TRUE; } uint8 HalKeyRead ( void ) { uint8 keys = 0; if (HAL_PUSH_BUTTON1()) { keys |= HAL_KEY_SW_6; } if (HAL_PUSH_BUTTON2()) /* Key is active low */ { keys |= HAL_KEY_SW_7; } return keys; } void HalKeyPoll (void) { uint8 keys = 0; /* If interrupts are not enabled, previous key status and current key status * are compared to find out if a key has changed status. */ if (!Hal_KeyIntEnable) { if (keys == halKeySavedKeys) { /* Exit - since no keys have changed */ return; } /* Store the current keys for comparation next time */ halKeySavedKeys = keys; } else { /* Key interrupt handled here */ } if (HAL_PUSH_BUTTON1()) { keys |= HAL_KEY_SW_6; } if (HAL_PUSH_BUTTON2()) { keys |= HAL_KEY_SW_7; } /* Invoke Callback if new keys were depressed */ if (keys && pHalKeyProcessFunction) { (pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL); } } uint8 halGetSWKeyInput(void) { /* The joystick control is encoded as an analog voltage. * Read the JOY_LEVEL analog value and map it to joy movement. */ uint8 ksave0 = 0; uint8 ksave1; /* Keep on reading the ADC until two consecutive key decisions are the same. */ do { ksave1 = ksave0; /* save previouse key reading */ if (HAL_PUSH_BUTTON1()) { ksave0 |= HAL_KEY_SW_6; } else if(HAL_PUSH_BUTTON2()) { ksave0 |= HAL_KEY_SW_7; } } while (ksave0 != ksave1); return ksave0; } void halProcessKeyInterrupt (void) { bool valid=FALSE; if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT) /* Interrupt Flag has been set */ { HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT); /* Clear Interrupt Flag */ valid = TRUE; } if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) /* Interrupt Flag has been set */ { HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT); /* Clear Interrupt Flag */ valid = TRUE; } if (valid) { osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_DEBOUNCE_VALUE); } } void HalKeyEnterSleep ( void ) { } uint8 HalKeyExitSleep ( void ) { /* Wake up and read keys */ return ( HalKeyRead () ); } HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR ) { HAL_ENTER_ISR(); if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT) { halProcessKeyInterrupt(); /* Clear the CPU interrupt flag for Port_0 PxIFG has to be cleared before PxIF */ HAL_KEY_SW_6_PXIFG = 0; HAL_KEY_CPU_PORT_1_IF = 0; } if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) { halProcessKeyInterrupt(); /* Clear the CPU interrupt flag for Port_0 PxIFG has to be cleared before PxIF */ HAL_KEY_SW_7_PXIFG = 0; HAL_KEY_CPU_PORT_1_IF = 0; } CLEAR_SLEEP_MODE(); HAL_EXIT_ISR(); } #else void HalKeyInit(void){} void HalKeyConfig(bool interruptEnable, halKeyCBack_t cback){} uint8 HalKeyRead(void){ return 0;} void HalKeyPoll(void){} #endif /* HAL_KEY */