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.

CCS/MSP-EXP430F5529LP: CCS/MSP-EXP430F5529LP

Part Number: MSP-EXP430F5529LP

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

}

  • Your symptom sounds very much like switch bounce. Google will find a number of strategies for debouncing. A very simple one is just to wait a while and look again. Since you're detecting button release, this might look something like:

    __delay_cycles(1000); // 1ms delay to let the button finish bouncing
    if ((P1IN & BIT4) == BIT4) {    // P1.4 still high?
     // do something
    }
    P1IFG &= ~BIT4;   // Clear IFG in any case

  • Hey Bruce Mckenney47,

    Thanks for your response and yeah it worked. 

               I did know about switch bounce  and use of delay function but i was looking for alternate solution because i was not planning to use delay function in ISR routine because of timing accuracy required   but i think 1ms is okay to use and please let me know if there is another way without using delay function , and also about entering and and exiting low power mode on count of 3 and 1, yes i have referred data sheets for that and seen sample code also but i didn`t get much idea how it actually works, so you can show me by modifying in my code so i can get better understanding of how to implement in code . 

  • Hi Nilesh,

    a better possibility to address de-bouncing, is to disable the GPIO interrupt on occurrence, and start at the same time a timer, which would expire after the desired de-bounce time (dependent on the used switches), then throw an interrupt, based on which you would re-enable the GPIO interrupt again.

    In terms of exiting the LPM on certain interrupts, please check our code examples. You can find an exit instruction for LPM exit after return from interrupt. This basically manipulates the control bits in the SR on the stack, to be in active mode after return from interrupt.

    Best regards

    Peter

**Attention** This is a public forum