Compile Error of Timer0 Overflow Vector with Arduino UNO (ATmega328P) and IDE

I am trying to use Timer 0 Overflow Interrupt in Arduino UNO (CPU = ATmega328P) and IDE. I wrote its code at a code block section below in this post but had a compile error as:

Linking everything together...

"C:\Program Files\arduino-1.8.19\hardware\tools\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\xxxxx\AppData\Local\Temp\arduino_build_241054/Interrupt_Timer_TIMER0_OVF.ino.elf" "C:\Users\xxxxx\AppData\Local\Temp\arduino_build_241054\sketch\Interrupt_Timer_TIMER0_OVF.ino.cpp.o" "C:\Users\xxxxx\AppData\Local\Temp\arduino_build_241054/core\core.a" "-LC:\Users\xxxxx\AppData\Local\Temp\arduino_build_241054" -lm

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

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

C:\Users\xxxxx\AppData\Local\Temp\arduino_build_241054\sketch\Interrupt_Timer_TIMER0_OVF.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 Arduino Uno.


The error disappears if I remove "ISR(TIMER0_OVF_vect)" section.

The error seems to be "multiple definition of `__vector_16'."

When I used TIMER2, its overflow interrupt code could be compiled and operation worked.

How can I solve this?

Please advise.

#include <avr/io.h>
#include <avr/interrupt.h>
 
ISR(TIMER0_OVF_vect)
{ 
  PORTB ^= (1<<PB5);
}
 
void Timer0_Init(void)
{
  TCCR0A = (0<<COM0A1)|(0<<COM0A0)|(0<<COM0B1)|(0<<COM0B0)|(0<<WGM01)|(0<<WGM00);
  TCCR0B = (0<<FOC0A)|(0<<FOC0B)|(0<<WGM02)|(0<<CS02)|(1<<CS01)|(0<<CS00);
  TIMSK0 = (0<<OCIE0B)|(0<<OCIE0A)|(1<<TOIE0);
}
 
void setup() {
  Timer0_Init();
  DDRB = (1<<PB5);
  sei();
}
 
void loop() {
  while(true) {
  }
}

Timer 0 is used by the Arduino system for the millis() function. That means the overflow ISR for timer 0 is already in use.

MicroBahner,

Thank you for your prompt answer. Now I could understand why it is.

You could have looked for yourself

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