Go Down

Topic: attachInterrupt() makes due halt? (Read 140 times) previous topic - next topic

zzang941115

Hi I've got my first DUE (before, I had UNO)

and trying "UPGRADE" my gizmo that uses ISR.

However it seems attachInterrupt() makes due board stop.

and this is my code

Code: [Select]
#include <Wire.h>

void setup()
{
  Serial.begin(9600);
  Serial.println("11");
    pinMode(12, OUTPUT);
  Serial.println("22");
    pinMode(13, OUTPUT);
  Serial.println("33");
    digitalWrite(13, HIGH);
  Serial.println("44");
  //pinMode(22, INPUT_PULLUP);
  Serial.println("55");
    attachInterrupt(22, inter, RISING);  
  Serial.println("SETUP 66");
}

void loop() {}

void blinking()
{
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
}

void inter()
{
  blinking();  
}


I put hell lot of Serial.println() in my code for Test Purpose

and I've got this in my Serial Monitor

Code: [Select]
1

Looks weird... I will look for your response.

Thank you in advance!

ard_newbie


Inside an ISR, a good practice is to avoid any length such as Serial.print or delay, just set a flag or clear/set a register.

Try the example sketch in Arduino Playground for attachinterrupt(), it should work.

zzang941115

Many Thanks !

I'd never try code on playground directly.

How ironic that I've read that post whole day.

Haha Thank you for your kind help.

BTW that code works fine on UNO

what difference make that happening?

MorganS

Quote
delay(200);
That's why it breaks. The millis() timer which drives delay() doesn't update properly inside an interrupt.

Turn the LED on in the interrupt and record the value of millis() at that time. The main loop can check if the LED is on and turn it off if the time is up.
"The problem is in the code you didn't post."

Go Up