Jump to content
Sign in to follow this  
Jakki

attachInterrupt/Interrupt doesn't work inside ISR

Recommended Posts

MSP Launchpad Exp430G2 with Exp430G2553 Rev 1.5

Energia 1.6.10E18

MacOS Sierra 10.12.6

Hello friends, 

Is it possible to use the functions "attachInterrupt" or "Interrupts" inside an Interrupt Service Routine?

For me, it doesn't seem to work. I made a little example:

I have to pins with momentary switches attached to them. One is externally configured with a PullUp-Resistor, and the other is externally configured with a PullDown-Resistor.

Both switches should be attached to another ISR. But I need to turn off the ISR that is not used, if one ISR is entered, because in both ISR's I need to listen for both switches.

I can successfully detach the remaining ISR from the other pin when I enter one ISR, but when I try to re-attach it to the other pin at the end of the ISR with attachInterrupt oder with the combination "noInterrupts" and "interrupts" , the program crashes or stops for at least 3 seconds.
 

volatile int switchPin = P2_3;
volatile int espPin = P2_6;
volatile int ledPin = P2_7;

void ToggleFast(volatile int pinu)
{
    volatile unsigned long n = 100000;
    digitalWrite(pinu,HIGH);
    do{n--;}
    while(n>0);
    digitalWrite(pinu,LOW);
    n = 100000;
    do{n--;}
    while(n>0);
    digitalWrite(pinu,HIGH);
    n = 100000;
    do{n--;}
    while(n>0);
    digitalWrite(pinu,LOW);
    n = 100000;
    do{n--;}
    while(n>0);
  
}

void setup() {
    pinMode(ledPin, OUTPUT);
    attachInterrupt(switchPin, myISR, FALLING);
    attachInterrupt(espPin, myISR2, RISING);
}

void loop() {
  //toggle slow
  digitalWrite(ledPin, LOW);
  delay(400);
  digitalWrite(ledPin, HIGH);
  delay(400);

}

void myISR()
{
  detachInterrupt(espPin);
  ToggleFast(ledPin);
  // if I uncomment this, the program crashes or stops for at least 3 seconds.
. It is the same when using "noInterrupts" and "interrupts"
  //attachInterrupt(espPin, myISR2, RISING);
}

void myISR2()
{
  ToggleFast(ledPin);
  ToggleFast(ledPin);
  ToggleFast(ledPin);
  ToggleFast(ledPin);
}

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×