ATtiny85 - problem defining ISR(TIM0_OVF_vect)

I am trying to port some working C code (compiled in Studio 7, loaded via ISP and tested on MCU) for an ATiny85 back into Arduino for a friend.

My original code uses Counter/Timer0 to generate PWM on OC0B (PB1) as I want to keep SDA and SCL pins (PB0/OC0A and PB2) free as we may need these to communicate with MCU later on.

When I try to compile code that includes a counter0 overflow interrupt in Arduino, it fails to compile.
But when I try to compile code for a counter1 overflow interrupt in Arduino, it compiles successfully.

Why is this?

In the example below, I have stripped out all but the code in question.

I have included the code and verbose compiler output for ISR(TIM0_OVF_vect) showing error. If I do this for ISR(TIM1_OVF_vect) or ISR (PCINT0_vect) for that matter, I can compile.

volatile uint8_t FLAGS = 0; // a register of flags to communicate activity between isr and main() - Bits defined as:
#define TIM 2               // flag for Timer0 overflow event 

void setup() {
  // put your setup code here, to run once:
}

ISR(TIM0_OVF_vect){   // timer overflow interrupt 
  FLAGS |= (1<<TIM);  // set flag so that main knows to execute some code 
}

void loop() {
  // put your main code here, to run repeatedly:

}

/*
 * Arduino: 1.8.16 (Windows 10), Board: "ATtiny25/45/85, ATtiny85, Internal 8 MHz"

D:\Users\Peter\Documents\arduino-1.8.16\arduino-builder -dump-prefs -logger=machine -hardware D:\Users\Peter\Documents\arduino-1.8.16\hardware -hardware C:\Users\Peter\AppData\Local\Arduino15\packages -tools D:\Users\Peter\Documents\arduino-1.8.16\tools-builder -tools D:\Users\Peter\Documents\arduino-1.8.16\hardware\tools\avr -tools C:\Users\Peter\AppData\Local\Arduino15\packages -built-in-libraries D:\Users\Peter\Documents\arduino-1.8.16\libraries -libraries D:\Users\Peter\Documents\Arduino\libraries -fqbn=attiny:avr:ATtinyX5:cpu=attiny85,clock=internal8 -ide-version=10816 -build-path C:\Users\Peter\AppData\Local\Temp\arduino_build_113847 -warnings=none -build-cache C:\Users\Peter\AppData\Local\Temp\arduino_cache_445182 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -verbose D:\Users\Peter\Documents\Arduino\ATtiny85Sample\ATtiny85Sample.ino

D:\Users\Peter\Documents\arduino-1.8.16\arduino-builder -compile -logger=machine -hardware D:\Users\Peter\Documents\arduino-1.8.16\hardware -hardware C:\Users\Peter\AppData\Local\Arduino15\packages -tools D:\Users\Peter\Documents\arduino-1.8.16\tools-builder -tools D:\Users\Peter\Documents\arduino-1.8.16\hardware\tools\avr -tools C:\Users\Peter\AppData\Local\Arduino15\packages -built-in-libraries D:\Users\Peter\Documents\arduino-1.8.16\libraries -libraries D:\Users\Peter\Documents\Arduino\libraries -fqbn=attiny:avr:ATtinyX5:cpu=attiny85,clock=internal8 -ide-version=10816 -build-path C:\Users\Peter\AppData\Local\Temp\arduino_build_113847 -warnings=none -build-cache C:\Users\Peter\AppData\Local\Temp\arduino_cache_445182 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.arduinoOTA.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -verbose D:\Users\Peter\Documents\Arduino\ATtiny85Sample\ATtiny85Sample.ino

Using board 'ATtinyX5' from platform in folder: C:\Users\Peter\AppData\Local\Arduino15\packages\attiny\hardware\avr\1.0.2

Using core 'arduino' from platform in folder: C:\Users\Peter\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.4

Detecting libraries used...

"C:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=8000000L -DARDUINO=10816 -DARDUINO_attiny -DARDUINO_ARCH_AVR "-IC:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.4\\cores\\arduino" "-IC:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\attiny\\hardware\\avr\\1.0.2\\variants\\tiny8" "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847\\sketch\\ATtiny85Sample.ino.cpp" -o nul

Generating function prototypes...

"C:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=8000000L -DARDUINO=10816 -DARDUINO_attiny -DARDUINO_ARCH_AVR "-IC:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.4\\cores\\arduino" "-IC:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\attiny\\hardware\\avr\\1.0.2\\variants\\tiny8" "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847\\sketch\\ATtiny85Sample.ino.cpp" -o "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847\\preproc\\ctags_target_for_gcc_minus_e.cpp"

"D:\\Users\\Peter\\Documents\\arduino-1.8.16\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=attiny85 -DF_CPU=8000000L -DARDUINO=10816 -DARDUINO_attiny -DARDUINO_ARCH_AVR "-IC:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.4\\cores\\arduino" "-IC:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\attiny\\hardware\\avr\\1.0.2\\variants\\tiny8" "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847\\sketch\\ATtiny85Sample.ino.cpp" -o "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847\\sketch\\ATtiny85Sample.ino.cpp.o"

Compiling libraries...

Compiling core...

Using precompiled core: C:\Users\Peter\AppData\Local\Temp\arduino_cache_445182\core\core_attiny_avr_ATtinyX5_cpu_attiny85,clock_internal8_b7bb48e507f447625c49e883d65f7886.a

Linking everything together...

"C:\\Users\\Peter\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=attiny85 -o "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847/ATtiny85Sample.ino.elf" "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847\\sketch\\ATtiny85Sample.ino.cpp.o" "C:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847/..\\arduino_cache_445182\\core\\core_attiny_avr_ATtinyX5_cpu_attiny85,clock_internal8_b7bb48e507f447625c49e883d65f7886.a" "-LC:\\Users\\Peter\\AppData\\Local\\Temp\\arduino_build_113847" -lm

wiring.c.o (symbol from plugin): In function `__vector_5':

(.text+0x0): multiple definition of `__vector_5'

C:\Users\Peter\AppData\Local\Temp\arduino_build_113847\sketch\ATtiny85Sample.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board ATtiny25/45/85.

 */

Try TIMER0_OVF_vect per https://ece-classes.usc.edu/ee459/library/documents/avr_intr_vectors/

Hi Dave
Thanks for the suggestion but sadly that's not the answer. (Oh I wish it were, I even said Doh! to myself before I tested it.)
TIMER0_OVF - still gives the same error - like it's been defined before and I can't redefine it??
TIMER1_OVF works fine - but this is not the timer I'm trying to use.
My test code and the shorthand compiler error below:

volatile uint8_t FLAGS = 0; // a register of flags to communicate activity between isr and main() - Bits defined as:
#define TIM 2               // flag for Timer0 overflow event 

void setup() {
  // put your setup code here, to run once:
}

ISR(TIMER0_OVF_vect){   // timer overflow interrupt 
  FLAGS |= (1<<TIM);  // set flag so that main knows to execute some code 
}

void loop() {
  // put your main code here, to run repeatedly:

}
/*
Arduino: 1.8.16 (Windows 10), Board: "ATtiny25/45/85, ATtiny85, Internal 8 MHz"

wiring.c.o (symbol from plugin): In function `__vector_5':

(.text+0x0): multiple definition of `__vector_5'

sketch\ATtiny85Sample.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board ATtiny25/45/85.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
 
 */

Remove loop and setup. Add main. Enjoy.

But, you're on your own for managing time; millis and micros will no longer be available.

Do you have an option to compile without millis being implemented? Seem to recall some attiny processors had that option under the tools menu.

Arduino millis() uses that timer.

1 Like

Compiles fine when you disable millis()

Hi David
That's it - Timer0 is being used by this Arduino macro (which I'm not using).
I don't see an option not to include millis - I only see this for the ATtiny13.
No matter - I re-wrote the code to use Timer1 and selected OC1A as output - as it uses same physical pin.
My code now works in 'raw C' and also in 'Arduino land' - I had a minor scoping error for one of the variables I was messin' with but apart from that I'm clean and clear.

Thank you for your time and confirmation of what the problem was - now I understand the significance of with or without millis() in the device selection.

Hi
Ah Ha!
Thank you.
Several posts with the same content. I switched to Timer1 and can compile and load via Arduino as ISP successfully.
Is there a guide that identifies h/w and s/w resources used by Arduino so I don't trip up again?

Hi
Thank you.
Yup, seems this is the cause of my issue.
I don't see an option on my device list that allows me to select millis() as disabled.
What Additional Boards Manager URLs are you using. I'd like to load a different ATtiny85 board definition to those I have.

My URL is:

(https://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json,
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json,
http://drazzy.com/package_drazzy.com_index.json)

The core I showed you is Attinycore (drazzy). It's part of your board managers URL, but it looks like you have activated another (damellis) core for Attiny.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.