Part Number: MSP430FR6989
Tool/software: Code Composer Studio
I am trying to get my MSP430 to use the output of 1 pin as the input to another pin. However, I can't seem to make the code work. My very simple program is below. Not shown is a simple delay loop, for debouncing purposes, and the external circuit, which is just a button connecting P8.4 to P2.1. When I press it, since 8.4 is high, 2.1 becomes high. I then have an ISR which should trigger when 2.1 goes high (or, strictly speaking, goes from high to low, since I selected falling edge interrupts). This ISR should toggle the onboard LED. However, the LED does not turn on. I am unsure if I am using the input functionality for pins correctly, or if there is a mistake elsewhere.
void main(void)
{
WDTCTL = WDTPW | WITHOLD;
P1DIR |= BIT0;
P1OUT = 0x00;//no output until called
P2DIR |= BIT6 | BIT7; // P2.6 and P2.7 set as output
P2OUT = 0x00;//ensure no ouput from them until desired.
P3OUT = 0x00;
P8OUT = 0x00;
P8DIR |= BIT4 | BIT5 | BIT6 | BIT7;
P8REN |= BIT4 | BIT5 | BIT6 | BIT7;
P8OUT |= BIT4 | BIT5 | BIT6 | BIT7;
P2DIR &= ~(BIT1 | BIT2 | BIT3 | BIT4);
P2REN |= BIT1 | BIT2 | BIT3 | BIT4;
P2IN &= ~(BIT1 | BIT2 | BIT3 | BIT4);//
P2IE |= BIT1 | BIT2 | BIT3 | BIT4;//interrupts on 1-4
P2IES |= BIT1 | BIT2 | BIT3 | BIT4;//falling edge
P2IFG &= 0x00f;//clear interrupt flags
PM5CTL0 &= ~LOCKLPM5;
while (1){}//go forever
}
#pragma vector = PORT2_VECTOR // associate funct. w/ interrupt vector
__interrupt void Port_2(void) // name of ISR
{
switch(__even_in_range(P2IV,P2IV_P2IFG7))
{
//I'm using P2.1-2.4 as inputs.
case P2IV_NONE: break; // Vector 0: no interrupt
case P2IV_P2IFG0: break; // Vector 2: P2.0
case P2IV_P2IFG1:
P1OUT ^= BIT0;//toggle led
P2IFG &= ~BIT1;//clear flag
P2IE &= ~(BIT1 | BIT2 | BIT3 | BIT4);//disable interrupts
delay();
P2IE |= BIT1 | BIT2 | BIT3 | BIT4;//enable interrupts
break;
case P2IV_P2IFG2:
break;
case P2IV_P2IFG3:
break;
case P2IV_P2IFG4:
break;
case P2IV_P2IFG5: break; // Vector 12: P2.5
case P2IV_P2IFG6: break; // Vector 14: P2.6
case P2IV_P2IFG7: break; // Vector 16: P2.7
default: break;
}
}