Tool/software: Code Composer Studio
HI,
I am using MSP-EXP430F5529LP launchpad and i am totally new to it, I am using port interrupt to receive button state and i need to count 3 pulse and then put MCU in power saving mode and one count to again start active mode , and to taste my code i have toggled the pin p4.7(LED) to observe the change but the problem i am facing is the counter gets incremented by 5 or 7 time while i have only pressed button single time and LED does not even get toggle. When i put break point, every time it works fine but in run time it is not giving proper response. I have used multiple configuration and sample code given in resource explorer but the problem remains same, so i used external push button on p1.4 but same response i am getting by it also. For note, I am using Code Composer studio 9.0.
I have attached waveform`s screenshot here , channel 1(yellow color ) is button state and channel 2 is LED`s response.
here is my code,In this code i haven`t decided which low power mode should be used for my application, but i have to use RTC in calendar mode and store some temperature reading on some particular interval so please any one can help which low power mode I should use to get minimum current consumption and fulfill my requirement and also can show me how to put in low power mode after 3 time pressed p1.4 and again exit from it in single press, any response will be appreciated.
#include <msp430.h>
unsigned int counter=0,flag_wake=0,flag_sleep =0,i=0;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; // Set P1.0 to output direction
P1OUT &= ~BIT0;
P1REN |= BIT4; // Enable P1.4 internal resistance
P1OUT |= BIT4; // Set P1.4 as pull-Up resistance
P1IES &= ~BIT4; // P1.4 Lo/Hi edge
P1IFG &= ~BIT4; // P1.4 IFG cleared
P1IE |= BIT4; // P1.4 interrupt enabled
P4DIR |= BIT7; // Set P1.0 to output direction//LED
P4OUT &= ~BIT7;
flag_wake=1;
__bis_SR_register(GIE);
while(1)
{
if(counter == 1 && flag_sleep == 1)
{
flag_sleep =0;
flag_wake =1;
counter =0;
P4OUT ^= BIT7; // P4.7 = toggle
}
if (counter >= 3 && flag_wake== 1)
{
flag_sleep=1;
flag_wake =0;
counter =0;
P4OUT ^= BIT7; // P4.7 = toggle
}
}
}
// Port 1 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT1_VECTOR))) Port_1 (void)
#else
#error Compiler not supported!
#endif
{
if((P1IFG & BIT4) == BIT4)
{
counter++;
P1IFG &= ~BIT4; // Clear P1.4 IFG
}