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.

cc2541怎么在simpleBLEPeripheral 示例工程中修改按键的io口?

Other Parts Discussed in Thread: CC2540

在simpleBLEPeripheral 示例工程中,是以P0.1口作为按键,按键后会广播,现在想把io口改为p1.4口作为按键脚可以吗?怎么改呀,请各位大神指点

  • 只要你的电路支持,可以改。

    找代码中关于P0.1的部分就行

  • 我修改了 hal_key.c 里的关于p0.1的部分, 还是不行的,代码如下 

    /* CPU port interrupt */
    #define HAL_KEY_CPU_PORT_0_IF P0IF       //改成了 P1IF

    #define HAL_KEY_CPU_PORT_2_IF P2IF

    #if defined ( CC2540_MINIDK )
    /* SW_1 is at P0.0 */
    #define HAL_KEY_SW_1_PORT P0
    #define HAL_KEY_SW_1_BIT BV(0)
    #define HAL_KEY_SW_1_SEL P0SEL
    #define HAL_KEY_SW_1_DIR P0DIR

    /* SW_2 is at P0.1 */
    #define HAL_KEY_SW_2_PORT P0      //改成了 P1
    #define HAL_KEY_SW_2_BIT BV(1)      //改成了BV(4)
    #define HAL_KEY_SW_2_SEL P0SEL  //改成了 P1SEL
    #define HAL_KEY_SW_2_DIR P0DIR   //改成了 P1DIR 

    #define HAL_KEY_SW_1_IEN            IEN1 /* CPU interrupt mask register */           //改成了 IEN2
    #define HAL_KEY_SW_1_ICTL          P0IEN /* Port Interrupt Control register */      //改成了 P1IEN
    #define HAL_KEY_SW_1_ICTLBIT    BV(0) /* P0IEN - P0.0 enable/disable bit */
    #define HAL_KEY_SW_1_IENBIT      BV(5) /* Mask bit for all of Port_0 */

    #define HAL_KEY_SW_1_PXIFG       P0IFG /* Interrupt flag at source */                 //改成了 P1IENFG
    #define HAL_KEY_SW_2_ICTL          P0IEN /* Port Interrupt Control register */     //改成了 P1IEN
    #define HAL_KEY_SW_2_ICTLBIT    BV(1) /* P0IEN - P0.1 enable/disable bit */  //改成了BV(4)
    #define HAL_KEY_SW_2_IENBIT      BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_2_PXIFG       P0IFG /* Interrupt flag at source */                 //改成了 P1IENFG

    还有其它地方需要改吗? 或者你们有没有相关资料的,我还不是很清楚这些配置要怎么改?谢谢回答

  • /* S2 is at P1.4 */
    #define HAL_KEY_SW_2_PORT P1
    #define HAL_KEY_SW_2_BIT BV(4)
    #define HAL_KEY_SW_2_SEL P1SEL
    #define HAL_KEY_SW_2_DIR P1DIR

    #define HAL_KEY_SW_2_IEN IEN2 /* CPU interrupt mask register */

    #define HAL_KEY_SW_2_ICTL P1IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_2_ICTLBIT BV(4) /* P0IEN - P1.4 enable/disable bit */
    #define HAL_KEY_SW_2_IENBIT BV(4) /* Mask bit for all of Port_1 */
    #define HAL_KEY_SW_2_PXIFG P1IFG /* Interrupt flag at source */

    #define HAL_KEY_SW_2_EDGEBIT BV(2)

    按照如上更改,你只改一个按键,不需要对HAL_KEY_SW1部分进行修改。#define HAL_KEY_CPU_PORT_0_IF P0IF   这句话是定位cpu的P0口中断的,不需要修改

  • 请问一下,我在从机程序中也是这样修改了,添加了CC2540_MINIDK 宏定义,但是没有反应,你是怎么解决的?

  • 不是很清楚了,你要注意当改变IO口的时候,对应的要 中断控制寄存器PxIEN、中断源PxIFG、中断使能寄存器 IENx、端口输入方向PxDIR的相应的位要改变,我只能帮你到此了。你可以下载CC254x user guide 或者中文版的CC253x用户指南 ,里边有CPU的详细配置说明,两者用的一个CPU。

    正常情况下,上述修改就可以的,我的按键端口改动就是这么干的,还有你可以参考sensortag的按键,人家是用的P1.7和P1.6