Go Down

Topic: Arduino Due and attachInterrupt (Read 1 time) previous topic - next topic

maximej

Hi,

I have a big problem only with my attachInterrupt on arduino Due.
When i add this line :

Code: [Select]
attachInterrupt(6, message, FALLING );

The message function is directly called even if I use other operating mode like LOW, RISING, etc

I tried my code on Arduino MKR1000 and i don't have this problem.

I give you the code below :

Code: [Select]
int val = 0;
 
void setup()
{
  Serial.begin(115200);
  delay(2000);
      Serial.println(digitalRead(6));
  pinMode(6, INPUT_PULLUP);
 attachInterrupt(6, message(), FALLING );
     Serial.println(digitalRead(6));
}
 
void loop()
{
    Serial.print("LOOP:");
    Serial.println(val);
    delay(100);
    val++;
}
 
void message()
{
    Serial.print("INT:");
    Serial.println(val);
}


Do you have any solution ?

ard_newbie

#1
Jan 24, 2018, 01:42 pm Last Edit: Jan 24, 2018, 01:45 pm by ard_newbie
It might be due to EMI on pin 6 seen as a falling edge. Do you have a pull down or pull up resistor on this pin ?

ard_newbie


Don't use the weak internal pullups, use external pullup résistors like 1KOhms or more.

GolamMostafa

#3
Jan 25, 2018, 06:25 pm Last Edit: Jan 25, 2018, 07:29 pm by GolamMostafa
My experiment also reveals that the MCU is interrupted once during the execution of this instruction: attachInterrupt(digitalPinToInterrupt(6), message, FALLING);.


One may proceed to program the interrupt using ASF Strategy in order to make an authentic declaration that the above-mentioned instruction is really not compatible with DUE though it works fine with UNO.

Help is being sought to get the link for ZIP version of the asf.h file.

maximej

i tried on different pin but there are the same problem on each pin.
and using external pullups don't solve the problem.

In fact it's a software problem.

ard_newbie


This snippet works as expected (I hook a pull_up resistor on pin 6 = PC24). I tested it with a button switch without a debounce( there should be a debounce either software or hardware):

Code: [Select]

// Hook a pull-up resistor of 1K or more between pin 6 and 3.3V

volatile boolean Flag;     

void setup()
{
  Serial.begin(250000);
  pinMode(6, INPUT);
  PIOC->PIO_ISR;                    // Clear status register
  NVIC_ClearPendingIRQ(PIOC_IRQn);  // Clear pending ISR
  attachInterrupt(6, message, LOW);
}

void loop()
{

  if ((Flag == true)){
    Serial.println(" pin 6 is low ");
    Flag = false;
  }
}

void message()
{
  Flag = true;
}






GolamMostafa

Unfortunately, the setup of Post#5 is not working in my case!

Go Up