[Resolu] Interupt avec front sur Attiny85

Bonjour,

J’ai trouvé un code qui permet de gérer un rising sur Attiny85 pour sortir d’un mode sleep et y retourner.

Mais si la pin PB2 qui sert a réaliser le rising reste active après le delay KEEP_RUNNING le programme contenu dans le loop ne s’excute plus.

Auriez-vous une idée ? Et merci d’avance.

#include <avr/sleep.h>

#define LED 4                      //LED on pin 4, PB4, DIP pin 3
#define KEEP_RUNNING 10000         //milliseconds
#define BODS 7                     //BOD Sleep bit in MCUCR
#define BODSE 2                    //BOD Sleep enable bit in MCUCR

void setup(void)
{
    //to minimize power consumption while sleeping, output pins must not source
    //or sink any current. input pins must have a defined level; a good way to
    //ensure this is to enable the internal pullup resistors.

    for (byte i=0; i<5; i++) {     //make all pins inputs with pullups enabled
        pinMode(i, INPUT);
        digitalWrite(i, HIGH);
    }

    pinMode(LED, OUTPUT);          //make the led pin an output
    digitalWrite(LED, LOW);        //drive it low so it doesn't source current
}

void loop(void)
{
    goToSleep();

    for (byte i=0; i<5; i++) {     //wake up, flash the LED
        digitalWrite(LED, HIGH);
        delay(100);
        digitalWrite(LED, LOW);
        delay(100);
    }
    delay(KEEP_RUNNING);           //opportunity to measure active supply current 
}

void goToSleep(void)
{
    byte adcsra, mcucr1, mcucr2;

    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    MCUCR &= ~(_BV(ISC01) | _BV(ISC00));      //INT0 on low level
    GIMSK |= _BV(INT0);                       //enable INT0
    adcsra = ADCSRA;                          //save ADCSRA
    ADCSRA &= ~_BV(ADEN);                     //disable ADC
    cli();                                    //stop interrupts to ensure the BOD timed sequence executes as required
    mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE);  //turn off the brown-out detector
    mcucr2 = mcucr1 & ~_BV(BODSE);            //if the MCU does not have BOD disable capability,
    MCUCR = mcucr1;                           //  this code has no effect
    MCUCR = mcucr2;
    sei();                                    //ensure interrupts enabled so we can wake up again
    sleep_cpu();                              //go to sleep
    sleep_disable();                          //wake up here
    ADCSRA = adcsra;                          //restore ADCSRA
}

//external interrupt 0 wakes the MCU
ISR(INT0_vect)
{
    GIMSK = 0;                     //disable external interrupts (only need one to wake up)
}

[Resolu]
J’ai utilisé un autre code

/*
  ATtiny85 sleep mode and wake on pin change
  Author: Davide Gariselli
  Original version made by Nick Gammon https://goo.gl/62b0Im
  // ATMEL ATTINY 25/45/85 / ARDUINO
  //
  //                  +- \/-+
  // Ain0 (D 5) PB5  1|*    |8  Vcc
  // Ain3 (D 3) PB3  2|     |7  PB2 (D 2) Ain1
  // Ain2 (D 4) PB4  3|     |6  PB1 (D 1) pwm1
  //            GND  4|     |5  PB0 (D 0) pwm0
  //                  +-----+
  
  It's works with 3,3V (8Mhz) or 5V (8Mhz or 16Mhz)
*/

// PinChangeInterrupt ( attachPCINT ) Library 1.2.4 https://goo.gl/WhlCwl
#include <PinChangeInterrupt.h>

#include <avr/sleep.h>    // Sleep Modes https://goo.gl/WJUszs
#include <avr/power.h>    // Power management https://goo.gl/58Vdvv

#define LED 3 // D3
#define SWITCH 4 // D4

int Count = 0;
int Circle = 0;

void setup () {
  pinMode (LED, OUTPUT);
  digitalWrite(LED, HIGH);
  pinMode (SWITCH, INPUT_PULLUP); // internal pull-up
  // Valid interrupt modes are: RISING, FALLING or CHANGE
  attachPCINT(digitalPinToPinChangeInterrupt(SWITCH), wakeUpNow, FALLING);
}

void loop () {
  delay(100);

  Circle = 0;
  Count = 0;

  while (Circle!=1)

  {
   if (digitalRead (SWITCH) == HIGH)
   {
    Circle = 1;
   }
   
   // Timer Count
   delay(1000);

   Count++; 
       
   // Send message after 30s, 60s and 120s
   if (Count == 10 || Count == 20)
   {
    digitalWrite (LED, LOW);
    delay (4000);
    digitalWrite (LED, HIGH);
   }

  if (Count == 30)
   {
    Circle = 1;
    digitalWrite (LED, LOW);
    delay (4000);
    digitalWrite (LED, HIGH);
   }
   
  }

 
  goToSleep ();
  
  
}  // end of loop

void wakeUpNow() {
  // execute code here after wake-up before returning to the loop() function
  // timers and code using timers (serial.print and more...) will not work here.
  // we don't really need to execute any special functions here, since we
  // just want the thing to wake up
}

void goToSleep () {
  //    * The 5 different modes are:
  //     *     SLEEP_MODE_IDLE         -the least power savings
  //     *     SLEEP_MODE_ADC
  //     *     SLEEP_MODE_PWR_SAVE
  //     *     SLEEP_MODE_STANDBY
  //     *     SLEEP_MODE_PWR_DOWN     -the most power savings
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // <avr/sleep.h>
  ADCSRA = 0;            // turn off ADC
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface <avr/power.h>
  sleep_enable(); // <avr/sleep.h>
  sleep_cpu(); // <avr/sleep.h>
  //---------------  THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP ---------------
  sleep_disable();// <avr/sleep.h>
  power_all_enable();    // power everything back on <avr/power.h>
}

Et j’ai du faire un pulldown pour éviter une détection sur les 2 fronts.