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.

MSP430FR6047: Key not detecting in MSP430FR6047 EVM using MSP API

Part Number: MSP430FR6047
Other Parts Discussed in Thread: EVM430-FR6047

Hi

I'm using EVM430-FR6047 and tried below code for key detection, both edge as well as level detection of keys. Once detected, LEDs are toggled or stopped. Let me know what is going wrong here

Find code below.

   // Stop watchdog timer
    WDT_A_hold(WDT_A_BASE);


    // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
    PMM_unlockLPM5();


    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN6);                      // S1 P5.6: PxDIR, PxOUT and PxREN registers
    GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN6,GPIO_HIGH_TO_LOW_TRANSITION);      // S1 P5.6: PxIES register

    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN5);                      // S2 P5.5: PxDIR, PxOUT and PxREN registers
    GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION);      // S2 P5.5: PxIES register


    SW1 = GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN6);

    SW2 = GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN5);


    //SW1_state = SW1 & 0x08;

    // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
    //PMM_unlockLPM5();

    // Set all P5IFG to zero
    P2IFG = 0x00;


    GPIO_enableInterrupt(GPIO_PORT_P2, GPIO_PIN6);
    GPIO_enableInterrupt(GPIO_PORT_P2, GPIO_PIN5);

    __bis_SR_register(GIE);  // Enable all interrupts

    GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN6);
    GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN5);

    SW1_interrupt_pre= GPIO_getInterruptStatus(GPIO_PORT_P2, GPIO_PIN6);
    SW2_interrupt_pre= GPIO_getInterruptStatus(GPIO_PORT_P2, GPIO_PIN5);

    while(1)
    {

        if (SW1_interrupt_pre != GPIO_getInterruptStatus(GPIO_PORT_P2, GPIO_PIN6))
        {
            if (SW1_interrupt == 1)
            {
                SW1_interrupt = 0 ;
            }
            else
            {
                SW1_interrupt = 1 ;
            }

            //GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN6);
        }
        if (SW2_interrupt_pre != GPIO_getInterruptStatus(GPIO_PORT_P2, GPIO_PIN5))
        {
            if (SW2_interrupt == 1)
            {
                SW2_interrupt = 0 ;
            }
            else
            {
                SW2_interrupt = 1 ;
            }
            //GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN5);
        }

        SW1 = GPIO_getInputPinValue(GPIO_PORT_P2,
                              GPIO_PIN6);

        SW2 = GPIO_getInputPinValue(GPIO_PORT_P2,
                                  GPIO_PIN5);

        //if  (GPIO_getInputPinValue(GPIO_PORT_P5,GPIO_PIN6) == GPIO_INPUT_PIN_HIGH)
        if (SW2_state == 1)
        {
            if (flag1 == 0)
            {
                flag1 = 10;
                GPIO_toggleOutputOnPin( GPIO_PORT_P1,GPIO_PIN1);
            }
            else
            {
                flag1 = flag1--;

            }
        }


        if  (GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN6) == GPIO_INPUT_PIN_HIGH)
        {
            if (flag2 == 0)
            {
                flag2 = 4;
                GPIO_toggleOutputOnPin(GPIO_PORT_P1,GPIO_PIN0);
            }
            else
            {
                flag2 = flag2--;

            }
        }



        // Delay
        for(i=100000; i>0; i--);
        delay = 0xFFFFFFF;

    }

    //return 0;
}




#pragma vector=PORT2_VECTOR //0xFFC6
__interrupt void Port_2(void)
{
//P5.5 = toggle


    switch (P2IFG)
    {
        case 0b01000000: // S1 P5.6 = 64: toggle red LED
        {
            //P1OUT ^= BIT0;          // Toggle P1.0
            //P5IFG &= ~BIT6;         // P5.6 clear interrupt flag
            GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN6);
            if (SW1_state == 1)
            {
                SW1_state = 0;
            }
            else
            {
                SW1_state = 1;
            }

        }
        break;
        case 0b00100000: // S2 P5.5 = 32: toggle green LED
        {
            //P1OUT ^= BIT1;          // Toggle P1.1
            //P5IFG &= ~BIT5;         // P5.5 clear interrupt flag
            GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN5);
            if (SW2_state == 1)
            {
                SW2_state = 0;
            }
            else
            {
                SW2_state = 1;
            }

        }
        break;
        default: // should not be here!
        {
          //printf("Put an error message here. \n");
        }
        break;
    }

}


SW1_state, and SW2_state are not toggling. Schematic of EVM attached.

slar138b.pdf

Kindly review.

  • Hi  Bivin,

    You can refer to this example code if you want to using GPIO interrupt function:

    https://dev.ti.com/tirex/explore/node?node=AMCIDHZtV5UqTvI38IJoaQ__IOGqZri__LATEST

    Thanks!

    Best Regards

    Johnson

  • Hi johnson

    Thanks for the reply.

    But as you see, i'm trying to use API provided by MSP430 library.

    Can you comment on the same, what is wrong with the above.

    As per the same, i'm not getting interrupt, please review.

  • Hi Bivin,

    Actually, we also provide the example code based on Library.

    You can install MSPWARE(search in ti.com), and then you can find the example code in the below floder:

    You can run example code firstly, this will help you find issue quickly.

    Thanks!

    Best Regards

    Johnson

  • Hi Johnson

    As mentioned earlier, i have referred the above codes and have made mine, but still i'm not able to detect key hit.

    Can you review the code i shared. Is the pragma vector code written in the right manner.

    Refer below

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #pragma vector=PORT2_VECTOR //0xFFC6
    __interrupt void Port_2(void)
    {
    //P5.5 = toggle
    switch (P2IFG)
    {
    case 0b01000000: // S1 P5.6 = 64: toggle red LED
    {
    //P1OUT ^= BIT0; // Toggle P1.0
    //P5IFG &= ~BIT6; // P5.6 clear interrupt flag
    GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN6);
    if (SW1_state == 1)
    {
    SW1_state = 0;
    }
    else
    {
    SW1_state = 1;
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Bivin,

    I think you can add a breakpoint in Line 7.

    And yo can refer to this code:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    // Port 1 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=PORT1_VECTOR
    __interrupt void port1_isr_handler(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(PORT1_VECTOR))) port1_isr_handler (void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(P1IV, P1IV__P1IFG7))
    {
    case P1IV__NONE: break; // Vector 0: No interrupt
    case P1IV__P1IFG0: break; // Vector 2: P1.0 interrupt flag
    case P1IV__P1IFG1: // Vector 4: P1.1 interrupt flag
    P1IES ^= BIT1; // Toggle interrupt edge
    P1OUT ^= BIT1; // Toggle between pull-up vs pull-down R
    __bic_SR_register_on_exit(LPM4_bits); // Exit LPM4
    break;
    case P1IV__P1IFG2: break; // Vector 6: P1.2 interrupt flag
    case P1IV__P1IFG3: break; // Vector 8: P1.3 interrupt flag
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    This is for P1.7, the button of FR6047 should P2.6 thus you can change those below items:

    Don't to check P2IFG directly, there are maybe affect by other P2 pin flag.

    Thanks!

    Best Regards

    Johnson

**Attention** This is a public forum