Interrupt low mode problem

Hi there,

Interrupts are working fine for me when the mode is set to RISING and FALLING. However, if i set the mode to LOW and then apply ground to the same pin, then nothing happens.

Does anyone know where i am going wrong with this?

Thanks

A bit of your code would help, otherwise I am guessing it is on line 43 where the boolean Do_int function is called.

The Atmel chip documentation says

the INT0 or INT1 interrupts are enabled and are configured as level triggered, the interrupts will trigger as long as the pin is held low. Low level interrupt on INT0 and INT1 is detected asynchronously. This implies that this interrupt can be used for waking the part also from sleep modes other than Idle mode. : if a level triggered interrupt is used for wake-up from Power-down, the required level must be held long enough for the MCU to complete the wake-up to trigger the level interrupt. If the level disappears before the end of the Start-up Time, the MCU will still wake up, but no interrupt will be generated.

I am puzzled why one would want to use a LOW interrupt, as it would constantly interrupt until it went high again (as I read it). Unless one simply increments a counter and it is ony low for short periods of time. The external interrupts takes precendence over most other interrupts so it could stop other interrupts being called. (But it does not interrupt an interrupt routine)

I do not use userdefined interrupts in my Arduino code. I have worked with real interrupts on real machinery in my past life and they are slippery/tricky things to get 100% right.

Thanks for your response.

What i am essentially trying to achieve is wake up and put to sleep my Arduino using a single pin (pin 2). For initial testing, i can set the Arduino to sleep in the main loop after 5 seconds and wake it up again by setting pin 2 LOW. Below is my sleep function. 'wakeUpNow' is an empty function.

void sleepNow()         // here we put the arduino to sleep
{
    Serial.println("sleepNow");
    attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
    delay(100);     
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
    sleep_enable();          // enables the sleep bit in the mcucr register
    sleep_mode();            // here the device is actually put to sleep!!
                             // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
    sleep_disable();         // first thing after waking from sleep:
    
    detachInterrupt(0); 
}

Can i use this same pin to put the Arduino to sleep if it is awake and vice versa?

Thanks

http://www.gammon.com.au/interrupts

[quote author=Nick Gammon link=topic=195718.msg1444196#msg1444196 date=1382866557] http://www.gammon.com.au/interrupts [/quote]

Somewhere 60% down that page, you say "I shone a cheap 1W laser pointer onto the LDR".

Do you really have such a thing?

Ah, I think I might have meant 1 mW. I'll correct the page.

PedroA: What i am essentially trying to achieve is wake up and put to sleep my Arduino using a single pin (pin 2). For initial testing, i can set the Arduino to sleep in the main loop after 5 seconds and wake it up again by setting pin 2 LOW. Below is my sleep function. 'wakeUpNow' is an empty function.

A simple fix is to detach the interrupt in the wakeUpNow function. You will re-attach it next time you are about to put the mcu into sleep mode.

Which is what I suggested on my interrupts page:

// interrupt service routine in sleep mode
void wake ()
{
  sleep_disable ();         // first thing after waking from sleep:
  detachInterrupt (0);      // stop LOW interrupt
}  // end of wake