Home > Uncategorized > MSP430 Interrupt Rising and Falling Edge

MSP430 Interrupt Rising and Falling Edge

In previous post we have seen how interrupt works in MSP430 and we saw that how interrupt is generate on rising edge. What if we need to generate interrupt on falling edge ?

We can specify the edge using the following statement

For low to high
P1IES &= ~0x02 ;

For High to low
P1IES |= 0x02 ;

If you do not specify anything, the value of the corresponding bit is 0, so , by default it is is low to high edge. Here is the full code for high to low interrupt.

 

#include <msp430x14x.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;  // Stop Watch Dog Timer
P3DIR |= 0x10; // P3.4 set to output
P1IE |= 0x02 ; // Interrupt on Input Pin P1.1
P1IES |= 0x02 ; //  High to Low Edge
_BIS_SR(GIE);
}

#pragma vector = PORT1_VECTOR
__interrupt void InterruptVectorPort1()
{
P3OUT ^= 0x10; // Toggle P3.4
P1IFG &= ~0x02; // Clear Interrupt Flag
}

Here is how the screen shot looks like with this code

 

Finally, if you want to cause interrupt on falling as well as rising edge, there is a trick for it. What you is - toggle the edge sensitivity inside the interrupt service routine using a statement like.

P1IES ^= 0x02 ;

Here is how the screen shot looks like when interrupt is triggered at rising as well as falling edge.

The code in the interrupt service routine should be as follows.

#pragma vector = PORT1_VECTOR
__interrupt void InterruptVectorPort1()
{
P3OUT ^= 0x10; // Toggle P3.4
P1IES ^= 0x02 ; // Toggle Edge sensitivity
P1IFG &= ~0x02; // Clear Interrupt Flag
}

Uncategorized

  1. praveen
    September 22nd, 2015 at 04:20 | #1

    its really a nice tutorial. i want count individually count the number of rising and falling edges

  2. December 29th, 2015 at 20:56 | #2

    How do I code a service routine that do things different on falling and rising? Please help and thank you very much in advance.

  1. No trackbacks yet.