1

Good morning everyone i'm posting this here because i can't figure it out on my own. I've been trying to add ISR function in my project but it doesn't compile.

I work on Microship studio on an ATmega328p on a raw c++ project (NO ARDUINO).

I've been trying to add ISR(vect) interruption in my program but i can't manage to compile and i don't anderstand what i'm doing wrong.

In my code i'm using TIMER0_COMPA_vect but it also doesn't work with none of the 25 vectors in iom328p.h nor with _VECTOR(14).

Here's my code :

#include <avr/interrupt.h>
#include <avr/io.h>

#define F_CPU 9999999

static unsigned long long tick = 0;

static void startup(){
    TCCR0B = 0x01; // set Prescaller
    OCR0A = 200;   //Set the flag trig at 200
    TIMSK0 = (1<<OCIE0A); //interrupt 
}

ISR(TIMER0_COMPA_vect){
    ;
}

Here is the error :

Error       ld returned 1 exit status
Error       multiple definition of `TIMER0_COMPA_vect'  config.h    23
Error       recipe for target 'project.elf' failed
XavierDes
  • 11
  • 2

1 Answers1

2

[I'm assuming that config.h is the name of the file you quoted in the question.]

If you've put the definition in a header file that's included in multiple compilation units, then the linker is noticing that it's been defined multiple times. It's a violation of the one-definition rule in C++.

  • You can declare the ISR in a header file, but the definition should be in an implementation file (.cpp, .cc, .c, etc.).

  • If you don't need to declare it in the header file, then just move the entire function to an implementation file.

  • If you must define it in a header file, then you can add inline to the function signature, which is a misleadingly named way around the one-definition rule.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175