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.

Compiler/MSP430FR6989: Digital Input (PxIN) does not work as expected (MSP430FR6989)

Part Number: MSP430FR6989

Tool/software: TI C/C++ Compiler

Hey,

I'm struggeling with reading the input of the I/O pins of the Launchpad with the MSP430 FR6989.

If I use the following code, everything works as expected. I can turn on and off the LED if I press the button:

#include <driverlib.h>

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD; /* stop watchdog timer */
    PM5CTL0 &= ~LOCKLPM5;

    // Set P1.0 to output direction
    P1DIR |= BIT0; /* P1.0 (LED1: P1DIR.0 = 1) -> output*/
    P1OUT &= ~BIT0; /* clear P1.0 (LED1 off) */

    GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);

    while (1)
    {
        if (!(P1IN & BIT1)) /* test P1.1 (pressed?) */
        {
            P1OUT |= BIT0; /* set*/

        }
        else
        {
            P1OUT &= ~BIT0; /* clear*/
        }
    }
}

But if I just change the line GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1) and set the register to work as an input port (P1REN.1=1 and P1DIR.1=0), it doesn't work any more. Or more accurate, it will work after I compile it and flash it for the first time. But if I unconnect the board from the PC (no USB connection. no power) and power it up again, it just does not recognise any input at the specific port. I can even reflash the code, i doesn't help, the input register will not change if I press the buttion

Here is the modified code:

#include <msp430fr6989.h>

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD; /* stop watchdog timer */
    PM5CTL0 &= ~LOCKLPM5;

    // Set P1.0 to output direction
    P1DIR |= BIT0; /* P1.0 (LED1: P1DIR.0 = 1) -> output */
    P1OUT &= ~BIT0; /* clear P1.0 (LED1 off) */

    P1DIR &= ~BIT1; /* P1.1 (S2: P1DIR.1 = 0) -> input*/
    P1REN |= BIT1; /* enable P1.1 Pull-Up: P1REN.1=1 */

    while (1)
    {
        if (!(P1IN & BIT1)) /* test P1.1 (pressed?) */
        {
            P1OUT |= BIT0; /* set*/

        }
        else
        {
            P1OUT &= ~BIT0; /* clear*/
        }
    }
}

Any idea what's wrong in my modified code?

Stefan

  • I don't see your updated code but from your description my guess is that you didn't set P1OUT.1=1 to specify pull-up (not pull-down).
  • Okay, something went wrong. Here is the modified code:

    #include <msp430fr6989.h>
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD; /* stop watchdog timer */
        PM5CTL0 &= ~LOCKLPM5;
    
        // Set P1.0 to output direction
        P1DIR |= BIT0; /* P1.0 (LED1: P1DIR.0 = 1) -> output */
        P1OUT &= ~BIT0; /* clear P1.0 (LED1 off) */
    
        P1DIR &= ~BIT1; /* P1.1 (S2: P1DIR.1 = 0) -> input*/
        P1REN |= BIT1; /* enable P1.1 Pull-Up: P1REN.1=1 */
    
        while (1)
        {
            if (!(P1IN & BIT1)) /* test P1.1 (pressed?) */
            {
                P1OUT |= BIT0; /* set*/
    
            }
            else
            {
                P1OUT &= ~BIT0; /* clear*/
            }
        }
    }

    If I try the code with the FR5969, every thing works fine. Could I have broken the MC?

  • you didn't set P1OUT.1=1 to specify pull-up (not pull-down). See also SLAU367N Table 12-1.

    [Edit: Fixed table number typo]

  • Thanks a lot! I also checked the user guide. There are all the information I need ;-)

**Attention** This is a public forum