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.

Mapping SW2 to Bit 2 of Port 2

Other Parts Discussed in Thread: CC2540

Hi,

I have the CC2540 Mini DK with the two pushbutton switches.  One of the switches (SW2 - HAL_KEY_SW_2) is mapped to P0.1and functions as the discover/advertize button (among other things).

But I need to use the OPAMP which uses pins  P0.0, P0.1, P0.2 in conjunction with the ADC.  How do I map SW2 to Port  P0.2 and still retain it's functionality?  By the way, in my project, SW1 (mapped to P0.0) will be remove.

I hope somebody can help me here.

Regards,

Luis

  • Hi again,

    I need to make a correction on my previous post.  I wanted to map SW2 to Port P1.2 (not P0.2).  Sorry about that.

    Luis

  • First, you will need to find the file that declares the pin direction and selection. In the KeyFobDemo project, this would be under keyfobdemo.c. In the HeartRate project, it's under heartrate.c and so forth. Currently, all Port 1 pins are declared as outputs, so to set Pin 1.2 to an input, you would need to declare P1DIR = 0xFB. You may also want to declare P1 = 0x04 if you plan to use a similar push button topology (active high). Finally, you will need to go to "hal_key.c" and change the #define for Switch 2.

    #if defined ( CC2540_MINIDK )

    ...

    #define HAL_KEY_SW_2_PORT   P1
    #define HAL_KEY_SW_2_BIT    BV(2)
    #define HAL_KEY_SW_2_SEL    P1SEL
    #define HAL_KEY_SW_2_DIR    P1DIR

    I believe that should work.

  • Hi Misael,

    Thanks for your reply.

    I did the code changes in heartrate.c & hal_key.c but the remapped switch doesn't work.  It seems that the associated interrupt register & bits also needs to be changed which I tried to do  (as shown in the code snippet below from hal_key.c) without success. 

    #define HAL_KEY_SW_2_IEN IEN1 /* CPU interrupt mask register */
    #define HAL_KEY_SW_2_ICTL P1IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_2_ICTLBIT BV(2) /* P0IEN - P1.2 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 */

    Am I missing something else?