Currently, I am playing with the external interrupt of ATtiny85 using Digispark Dev Board (Fig-1). The board is installed, and it is working under IDE 1.8.19, which has been verified by uploading a blink sketch.
Figure-1:
The following sketch does not acknowledge external interrupt signal (FALLING edge triggered) on the INT0-pin of the ATtiny85 MCU. The source of interrupting signal is an 1 Hz square wave signal. Any help will be highly appreciated.
#define LED 1
#define INT0 2
volatile bool flag = false;
void setup()
{
pinMode(INT0, INPUT_PULLUP);
pinMode(1, OUTPUT); //onboard LED at PB1
attachInterrupt(INT0, ISRINTZ, FALLING);//digitalPinToInterrupt() is not accepted
sei(); //global interrupt enable bit is active
}
void loop()
{
if (flag == true) //iindication of INT0 interrupt
{
digitalWrite(1, HIGH);
delay(200);
digitalWrite(1, LOW);
delay(200);
flag = false;
}
}
void ISRINTZ()
{
flag = true;
}
4. The onboard ATtiny85 MCU has: (1) Bootloader similar to Arduino UNO to receive sketch codes from IDE and storing them in the application flash section.
(2) Fuse bytes are:
EF HF LF LB
FE DD E1 FF
(a) 16 MHz system clock derived from internal 8 MHz oscillator by PLL. (b) External RESET is disabled
5. The Board is compatiable with Arduino IDE 1.8.19 with the following execeptons which I have discovered experimentally during the operation of INT0-interrupt. (1) PB0, ..., PB5 could be defined as 0, ..., 5 only when the pins are used as general purpose IO lines.
(2) INT0-pin is the alternate function of PB2, and it cannot be defined as 2 which I did in my sketch of post #1. (The INT0 interrupt did not work.)
(3) The attachInterrupt() function also does not work.
6. At last I have managed to make the following sketch working to interrupt the ATtiny85 of the Digispark Board. (I have installed 2k external pull-up at INT0-pin.)
#define LED 1
volatile bool flag = false;
void setup()
{
pinMode(1, OUTPUT);// DDRB |= (1<<DDRB1);//|(1<<PB0); // set PB2 as output(LED)
GIMSK |= (1 << INT0); // enabling the INT0 (external interrupt)
MCUCR |= (1 << ISC01); // Configuring as falling edge
sei(); //enabling global interrupt
}
void loop()
{
if(flag == true)
{
blink(); //indication of the occurrence of INT0 interrupt
flag = false;
}
}
ISR (INT0_vect) // Interrupt service routine
{
flag = true;
}
void blink()
{
digitalWrite(LED, HIGH);
delay(10);
digitalWrite(LED, LOW);
delay(10);
}
Once you finish, kindly post your sketch for INT0 operation and the procedures of installing Bootloader, Fuse Bits, and the latest Board Description (the Core) into the ATtiny85 chip of the Digispark Board.
In Digispark Board containing ATtiny85, I tried first the following UNO style format which did not work, and then I tried the one that you have marked which also did not work.
==> //attachInterrupt(digitalPinToInterrupt(INT0), ISRINTZ, FALLING); is accepted by the Compiler; pracatically, it is not executed by the MCU. Next, I tried this code: attachInterrupt(INT0, ISRINTZ, FALLING); which was compiled but was not also executed.
Then you need to connect an ISP programmer to your digispark. Unplug the Digispark from the USB socket. and keep it unplugged. My favorite ISP is an USBASP programmer, but you can take an Arduino UNO and turn it into an ISP programmer.
The rest is done from within the IDE menu (of Attinycore)
Select these options and press "Burn Bootloader". It will also set the fuses.
1. If I install the ATTinyCore (the one you have referred) and leave the old bootloader in the ATtiny85 of Digispark -- will the sketch of post #2 be working?
2. Any idea about the values of the Fuse Bytes (EF, HF, LF) that will be imposed during the burning of the new Bootloader?
If the old bootloader is already micronucleus, you don't need to put a new one in. Just try to upload with Attinycore to your Digispark and see if it works.
That depends on the values you select. e.g. if you select B.O.D. Disabled, that will impact the fuse values.
I have not looked with my ISP programmer what fuse values were set, when I burned the bootloader. What is your concern about the fuses?
I think the 16,5 MHz is needed to get USB to work within a sketch. With 16 MHz that gets out of sync with the USB clock. Please read this.
1. The following sketch works well with ATTinyCore installed (and old Bootloader) except that the inclusion of pinMode(INT0, INPUT_PULL); in the sketch creates problem in the somooth operation of the INT0 interrupt. There is no need to connect external pull-up.
#define LED 1 //DPin for onboard LED
#define INT0 2 //DPin number for INT0-pin
volatile bool flag = false;
void setup()
{
pinMode(LED, OUTPUT);
//pinMode(INT0, INPUT_PULLUP); //INPUT_PULLUP creates problem
//-------system reset indication-----
for (int i = 0; i < 3; i++)
{
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
}
attachInterrupt(digitalPinToInterrupt(INT0), ISRINTZ, FALLING);
}
void loop()
{
if (flag == true)
{
blink(); //interrupt indication
flag = false;
}
}
void ISRINTZ()
{
flag = true;
}
void blink()
{
digitalWrite(LED, HIGH);
delay(10);
digitalWrite(LED, LOW);
delay(10);
}
2. I am concerned to know the fuse values (after storing new Bootloader) in order to check if the external RESET is enabled or not.
After receiving Digispark Board, I read its Fuse Bits using USBasp programmer (AVRDUEDESS) and recoreded the following values: 0xFE, 0xDD, and 0xE1 for EF, HF, and LF respectively.
3. I have read the referred document and have understood the reason of 16.5 MHz clock which is also system clock with knowing slight error on timing functions like delay().
if the (34K) pullup resistor activation causes issues for your test, I suspect your 1Hz pulse driver has very weak output strength. I manually trigger the INT0 and therefore need the pullup, or the input pin will trigger randomly, due to static electricity. If your weak pulsedriver has stable defined HIGH/LOW levels, turning off the pullup is the right thing to do.
This is why I mentioned "depending on the values you select" before "Burn Bootloader".
Disabling the reset pin by selecting it as GPIO is flagged as a "Danger" option.
So it is up to you how you want your reset pin. As long as you remember that if you choose GPIO, you will have to (build and) connect a HV programmer to get your reset pin back as a reset.
1. The 1 Hz interrupting signal comes from DPin-9 of UNO (OC1A Fast PWM with 50% duty cycle). I will be using this signal along with WDT timeout to wake-up MCU from sleep in the next exercise.
I have started the experiment/exercise with the sleep mode operation of Digispark's ATtiny85 when the wake-up sources are 1-sec interrupt and 8-sec WDT timeout. There seems to be some problems; your and others' help might be required. Should I continue here or open a new topic/thread?