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