Multiple definition of `__vector_9'

Any help would be appreciated. I am using an Arduino Micro. The below code works fine:

#include <TMC2209.h>

HardwareSerial & serial_stream = Serial1;

const long SERIAL_BAUD_RATE = 115200;
const int DELAY = 3000;

// Instantiate TMC2209
TMC2209 stepper_driver;

#define LED 15
#define input_pin 11

volatile bool inputChanged = false; 

void setup()
{
  Serial.begin(SERIAL_BAUD_RATE);

  stepper_driver.setup(serial_stream);

  pinMode(LED, OUTPUT);
  pinMode(input_pin, INPUT);
  digitalWrite(LED, LOW);

  // Set up PCINT for pins PCINT0-7
  PCICR |= B00000001;  // Enable PCIE0 (PCINT0-7 interrupt)
  PCMSK0 |= B10000000; //PCINT7)

  sei();
}

void loop()
{
  if (stepper_driver.isSetupAndCommunicating())
  {
    Serial.println("Stepper driver is setup and communicating!");
    Serial.println("Try turning driver power off to see what happens.");
  }
  else if (stepper_driver.isCommunicatingButNotSetup())
  {
    Serial.println("Stepper driver is communicating but not setup!");
    Serial.println("Running setup again...");
    stepper_driver.setup(serial_stream);
  }
  else
  {
    Serial.println("Stepper driver is not communicating!");
    Serial.println("Try turning driver power on to see what happens.");
  }
  Serial.println();
  delay(DELAY);
    if (inputChanged) {
    // Toggle LED state
    digitalWrite(LED, digitalRead(LED) == HIGH ? LOW : HIGH);
    inputChanged = false; // Reset the flag
  }
  // Delay to debounce and visibly see the LED state change, if needed
  // delay(100);
}

But when I add the ISR to the code I get the "multiple definition of `__vector_9'" error and it fails to compile. Here is the code with the ISR:

#include <TMC2209.h>

HardwareSerial & serial_stream = Serial1;

const long SERIAL_BAUD_RATE = 115200;
const int DELAY = 3000;

// Instantiate TMC2209
TMC2209 stepper_driver;

#define LED 15
#define input_pin 11

volatile bool inputChanged = false; 

void setup()
{
  Serial.begin(SERIAL_BAUD_RATE);

  stepper_driver.setup(serial_stream);

  pinMode(LED, OUTPUT);
  pinMode(input_pin, INPUT);
  digitalWrite(LED, LOW);

  // Set up PCINT for pins PCINT0-7
  PCICR |= B00000001;  // Enable PCIE0 (PCINT0-7 interrupt)
  PCMSK0 |= B10000000; //PCINT7)

  sei();
}

void loop()
{
  if (stepper_driver.isSetupAndCommunicating())
  {
    Serial.println("Stepper driver is setup and communicating!");
    Serial.println("Try turning driver power off to see what happens.");
  }
  else if (stepper_driver.isCommunicatingButNotSetup())
  {
    Serial.println("Stepper driver is communicating but not setup!");
    Serial.println("Running setup again...");
    stepper_driver.setup(serial_stream);
  }
  else
  {
    Serial.println("Stepper driver is not communicating!");
    Serial.println("Try turning driver power on to see what happens.");
  }
  Serial.println();
  delay(DELAY);
    if (inputChanged) {
    // Toggle LED state
    digitalWrite(LED, digitalRead(LED) == HIGH ? LOW : HIGH);
    inputChanged = false; // Reset the flag
  }
  // Delay to debounce and visibly see the LED state change, if needed
  // delay(100);
}

ISR(PCINT0_vect) {
  // ISR for pin change interrupt for PCINT7
  inputChanged = true; // Simply flag that input has changed
}

Thanks in advance for any advice!

It means that ISR is already used

How is it being used? I don't understand. I have only called it one time.

Maybe by the library you included. Remove all the stepper code and library, then see if you still have a conflict.

It looks like the TMC2209 library #includes the SoftwareSerial library even though you're not using it. SoftwareSerial defines an ISR for that vector.

What are you trying to do with interrupts anyway?

The interrupt vector table for the 32u4 shows this for vectors 9 and 10.

9 $0010 Reserved Reserved
10 $0012 PCINT0 Pin Change Interrupt Request 0

It's possible that adding the PCINT0 would conflict with a software serial use of interrupt vector 10. I would think more basic issue with software serial and interrupt vectors should be present even before you add the pin change interrupt vector.

Can you link to the specific library you are using for the 2209?

Confusingly, the conflict is reported to be with vector 9, which is reserved.

I'm puzzled by this, and wonder if there is a problem with the Arduino Micro board definition, e.g. some confusion about the vector numbering system.

This is the TMC2209.h library being used.

I am stumped how I keep getting this vector 9 error.

I am using the TMC2209.h library to configure 4 TMC driver ICs via the hardware UART port of the Arduino Micro. I want to use pin change interrupts to flag when each IC driver detects a motor stall.

You can't, if some other library is using those interrupts.

Either use a different external interrupt, or remove the conflicting library.

I think there is an issue with
avr-libc/avr-libc/include/avr/iom32u4.h

1345 #define PCINT0_vect_num 9
1346 #define PCINT0_vect _VECTOR(9) /* Pin Change Interrupt Request 0

This does not appear to be one of the #undef corrections in pins_arduino.h for the leonardo/micro.

// Workaround for wrong definitions in "iom32u4.h".
// This should be fixed in the AVR toolchain.
#undef UHCON
#undef UHINT
#undef UHIEN
#undef UHADDR
#undef UHFNUM
#undef UHFNUML
#undef UHFNUMH
#undef UHFLEN
#undef UPINRQX
#undef UPINTX
#undef UPNUM
#undef UPRST
#undef UPCONX
#undef UPCFG0X
#undef UPCFG1X
#undef UPSTAX
#undef UPCFG2X
#undef UPIENX
#undef UPDATX
#undef TCCR2A
#undef WGM20
#undef WGM21
#undef COM2B0
#undef COM2B1
#undef COM2A0
#undef COM2A1
#undef TCCR2B
#undef CS20
#undef CS21
#undef CS22
#undef WGM22
#undef FOC2B
#undef FOC2A
#undef TCNT2
#undef TCNT2_0
#undef TCNT2_1
#undef TCNT2_2
#undef TCNT2_3
#undef TCNT2_4
#undef TCNT2_5
#undef TCNT2_6
#undef TCNT2_7
#undef OCR2A
#undef OCR2_0
#undef OCR2_1
#undef OCR2_2
#undef OCR2_3
#undef OCR2_4
#undef OCR2_5
#undef OCR2_6
#undef OCR2_7
#undef OCR2B
#undef OCR2_0
#undef OCR2_1
#undef OCR2_2
#undef OCR2_3
#undef OCR2_4
#undef OCR2_5
#undef OCR2_6
#undef OCR2_7

Looks like that definition is just plain wrong.

There are a couple of reports of problems with implementing pin change interrupts with the Leonardo (ATmega32u4) that were not reported as resolved.

There is a simple work around.

Find this link to the leonardo variant in the 1.8.6 core file.

AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\leonardo

Then, add to the long list of #undefines and then save the file. Your code then compiles without error.

#undef PCINT0_vect_num        
#undef PCINT0_vect

You are correct. I updated the core file as stated and it compiles successfully, but now the com port is acting squirrely when I try to upload code:

Sketch uses 7456 bytes (26%) of program storage space. Maximum is 28672 bytes.
Global variables use 612 bytes (23%) of dynamic memory, leaving 1948 bytes for local variables. Maximum is 2560 bytes.
avrdude: ser_open(): can't set com-state for "\.\COM4"
Failed uploading: uploading error: exit status 1

That is an Arduino IDE issue on the PC. You will need to do another search to track that down.

This error message is a good search phrase:

avrdude: ser_open(): can't set com-state for "\.\COM4"

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