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.

MSP430F1122 Positive to Negative Edge detection program error

Prodigy 65 points

Replies: 3

Views: 443

Below find code for which I have written for detection of positive to negative edge for MSP430F1122.

#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
__enable_interrupt(); //Enable interrupt
P1DIR |= 0x01;
P2DIR &= ~0x01; //P2.0 as input port
P2SEL &= ~0x01;// P2.0 as I/O pin for detection of falling edge
P2IE |= 0x01; // P2.0 INTERRUPT ENABLE
P2IES |= 0x01; //P2.0 port will detect pos to neg edge
for (;;) // polling P2.0
{
volatile unsigned int i;
if (P2IFG == 1 )
{
P2IFG &= ~0x01; //Clear Interrupt after trigger.
P1OUT |= 0x01; // P1.0 LED Will be ON for a while

i = 500; // Delay
do (i--);
while (i != 0);


}
else
{
P1OUT &= ~0x01; // P1.0 LED remains off

}
}

return 0;
}

But it does not give me result. Why this simple detection of edge is not

giving me output ?

3 Replies

  • Aakash Patel
    Why this simple

    Well I think you wants to make it simple for yourself by not reading the datasheet, user manuals or studying the examples and expect the compiler/MCU will do this for you but sorry they wouldn’t!

    Aakash Patel
    P2IE |= 0x01; // P2.0 INTERRUPT ENABLE

    Enabling the port interrupt without ISR is danger but lucky you are not setting the GIE bit.

    Aakash Patel

    LED Will be ON for a while

    i = 500; // Delay
    do (i--);
    while (i != 0);

    You might have sharp eyes but probably not that fast, a delay of 500 cycles is about 500uS and then the LED goes off again.

  • In reply to Leo Bosch:

    Its done by writing ISR :

     

    #pragma vector=PORT2_VECTOR

    __interrupt void PORT2_ISR(void)

    {

           P2IFG &= ~0x01;                     //Clear Interrupt after trigger.

           P1OUT ^= 0x01;                          // Toggle P1.0 using exclusive-OR

    }

    Thank you

  • In reply to Jehan Patel:

    Hey you two Patels :-)


    Same last name - same problem?

    http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/356708.aspx


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.