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.

Hardware interrupt

Other Parts Discussed in Thread: MSP430F2274

Hi,

    I wanna implement hardware interrupt say using a switch 

  requirement: say I wanna presss switch n hold it for 5 seconds specinfic function is activated and press it for 10 seconds another function is generated 

same switch must activate multi functions but with variable  holding time of button say 5secs,10 secs,20 secs ......

ex: mp3 player has only 2 to 3 buttons but if u press it n hold it continiously then it genrates different functions in that way I want to know that 

1.Do I need an external hardware for such functionality or

2.Is that enough if we can use timers n interrupt serive routines in the programm but I need some Idea to do so in programming

I m working on msp430f2274 which has high to low detection on port 1 n port 2 say if a switch is implemented on port 1.2 if I press it high to low is selected then a flag is genrated and it goes to ISR directly n executes the function as I have shown in the  code below

#include "msp430x22x4.h"

 

void main(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer

 

  P1DIR |= 0x03;   

  P1OUT |= 0x00;                    // Set P1.0 to output direction

  //P1IN |= 0x04;

  P1REN |= 0x04; //Enable  the Resistor otherwise the Port pin will be Floating  between high n LOW states this setup is very important while using with switch. 

  P1IE |= 0x04;                             // P1.2 interrupt enabled

   P1IES |= 0x04;                           // P1.2 Hi/lo edge

  P1IFG &= ~0x04;                           // P1.2 IFG cleared

 

while(1)

{

   //for(unsigned int i =0;i<600;i++)

 

     __bis_SR_register(LPM3_bits + GIE);        // Enter LPM4 w/interrupt

}}

 

//##########################// Port 1 interrupt service routine  ###########################################################

#pragma vector=PORT1_VECTOR

__interrupt void Port_1(void)

      for(unsigned int i =0;i<600;i++) 

      {P1OUT ^= 0x01; P1OUT ^= 0x002;                           // P1.0 = toggle

 

                 // for(unsigned int i =0;i<6000;i++);

      P1IFG &= ~0x04; 

      for(unsigned int i =0;i<6000;i++);

      }                      // P1.2 IFG cleared}

}

 

//#############################// Port 1 interrupt service routine #########################################################

 

  • Your code has many flaws. The major one is, you did not use
    __bic_SR_register_on_exit(LPM3_bits);
    at the end of your ISR and you spend too much time inside the ISR.


    You should have only do the essentials inside ISR and do those time consuming loops after it wakes up main (or whichever routing that was suspended in LPM3).

    You could start a timer to determine the 5, 10, 15 seconds and use software to decide how long the switch is being pressed.

    Note that the switch usually bounces for tens of msec. Your software could handle that too.

    You have the right idea and a good start. But there is a long way ahead of you.

  • thanks for ur reply,

                                    do u have any idea about the Real time Clock using I2C to interface it with Msp430F2274 I have actually posted that code in the forums

     if u have idea and knowledge then please help me out I am using RTC RX8025 sa

    this is a sample code this is not exactly the full code but I am able to write this much

    //******************************************************************************
    #include "msp430x22x4.h"
    #define _bv(n) 1<<n


      void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      P1DIR |= 0x03;                            // P1.0 output
      P3SEL |= 0x36;                            // Assign I2C pins to USCI_B0
      UCB0CTL1 |= UCSWRST;                      // Enable SW reset
      UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
      UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
      UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz
      UCB0BR1 = 0;UCB0I2COA = 0x48;
     // UCB0I2CSA = 0x64;                         // Set slave address
      UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
      IE2 |= UCB0RXIE;                          // Enable RX interrupt
      TACTL = TASSEL_2 + MC_2;                  // SMCLK, contmode
    //###########################################################################################
      UCA0CTL1 |= UCSSEL_1; //CLK=32Khz
     
      UCA0BR0 = 0x3;                           // 32kHz/9600 = 3.41
      UCA0BR1 = 0x0;                           //
      UCA0MCTL = UCBRS1 + UCBRS0;
     
      UCA0CTL1 &= ~UCSWRST; 
      //IE2 |= UCA0RXIE; 
      IE2 |= UCB0RXIE;                          // Enable RX interrupt
      RXCompare = 0;                            // Used to check incoming data

      BCSCTL3 |= 0x00;                      // LFXT1 = VLO
      TACCTL0 = CCIE;                           // TACCR0 interrupt enabled
      TACCR0 = 12000;                           // ~ 1 sec
      TACTL = TASSEL_1 + MC_1;                  // ACLK, upmode
      // UCB0CTL1 |= UCTXSTT;                     // **Initialize USCI state machine**
                                                // IE2 |= UCA0RXIE;                       // sice both the USCA0RXIE n USCB0RXIE share
     //__bic_SR_register(CPUOFF);                                             //  the same vetor address this
                                                //  is not enable but check out the data
      //########################################################################################### 
      while (1)
      {
         while((UCB0CTL1&_bv(UCTXSTP)));
               // Ensure stop condition got sent
        UCB0CTL1 |= UCTXSTT;                    // I2C start condition
        while((UCB0CTL1&_bv(UCTXSTT)));
              // Start condition sent?
        UCB0CTL1 |= UCTXSTP;                    // I2C stop condition
       // __bis_SR_register(CPUOFF + GIE);        // Enter LPM0 w/ interrupts

          RXCompare++;                            // Increment correct RX value
     
       //UCB0CTL1 |=UCTR+UCTXSTT;
          UCB0I2CSA = 0x64;
         while((UCB0CTL1&_bv(UCTXSTT)));
     
         UCB0CTL1 |=UCTXSTT;
          while((UCB0CTL1&_bv(UCTXSTT)));
     
      UCB0TXBUF =0x0E;//<<4;//for(unsigned int i=0;i<60;i++);UCA0TXBUF='S';
                               // Load RX byte counter
        UCB0CTL1 |= UCTXSTT;
        UCB0CTL1 |=~UCTR;
      UCB0CTL1 |= UCTXSTT;
      UCB0I2CSA = 0x65;
      UCB0TXBUF=0x65;
      while((UCB0CTL1&_bv(UCTXSTT)));
     
      RxByteCtr--;                              // Decrement RX byte counter
      UCA0TXBUF = UCB0RXBUF;

**Attention** This is a public forum