energia / msp430-lg-core

15 stars 12 forks source link

attachInterrupt() doesn't work on MSP430FR5994 #83

Closed rei-vilo closed 5 years ago

rei-vilo commented 5 years ago

Consider the following minimalistic code:

volatile bool flag = false;

void HWI()
{
    flag = true;
}

void setup()
{
    pinMode(GREEN_LED, OUTPUT);
    digitalWrite(GREEN_LED, LOW);

    pinMode(PUSH1, INPUT_PULLUP);
    attachInterrupt(PUSH1, HWI, FALLING);
}

void loop()
{
    if (flag) {
        digitalWrite(GREEN_LED, HIGH);
        sleep(200);                   
        digitalWrite(GREEN_LED, LOW);
        flag = false;
    }
}

Pressing PUSH1 doesn't raise the interrupt and doesn't light the LED.

However, the following code polling PUSH1 works fine.

volatile bool flag = false;

void setup()
{
    pinMode(GREEN_LED, OUTPUT);
    digitalWrite(GREEN_LED, LOW);

    pinMode(PUSH1, INPUT_PULLUP);
}

void loop()
{
    flag = (digitalRead(PUSH1) == LOW);

    if (flag) {
        digitalWrite(GREEN_LED, HIGH);
        sleep(200);
        digitalWrite(GREEN_LED, LOW);
        flag = false;
    }
}
StefanSch commented 5 years ago

fixed with pull request on branch issue_83: https://github.com/energia/msp430-lg-core/pull/84 and merged to master.

rei-vilo commented 5 years ago

Thanks! It works fine now.