1

When trying to compile the sketch below, I get this error when using either the IDE or the CLI:

HardwareSerial0.cpp.o (symbol from plugin): 
In function `Serial':
(.text+0x0): multiple definition of `__vector_18'

This seems to have something to do with multiple definitions of USART_RX_vect.

Since I'm not using any extra libraries, that doesn't seem to be the source of the problem (though library conflicts are the source of many similar problems I've seen on here and elsewhere). Any suggestions on how to fix this?

Sketch:

// Listen to the Serial Port for Instructions and Print Register Values

volatile boolean start = false;  // flag to start register inspection; global

void setup() {
  Serial.begin(9600);
  if (Serial) {
    Serial.println("Arduino listening...");
    Serial.println("Enter g or s at any time");  // g = go, s = stop
  }
}

void loop() {
  while (start) {
    // print the values of some ADC registers
    Serial.print("ADMUX  register: ");
    print_bin(ADMUX);
    Serial.print("ADCSRA register: ");
    print_bin(ADCSRA);
    Serial.println(" ");
    delay(1000);
  }
}

ISR(USART_RX_vect) {
  unsigned char data;
  data = UDR0;
  if (data == 'g') {
    start = true;
  }
  if (data == 's') {
    start = false;
  }
}

void print_bin(byte aByte) {
  for (int8_t aBit = 7; aBit >= 0; aBit--) {
    if (aBit == 3) {
      Serial.print(" ");
    }
    Serial.print(bitRead(aByte, aBit) ? '1' : '0');
  }
  Serial.println(" ");
}

Using the Arduino IDE as follows:
Version: 2.3.0
Date: 2024-02-07T13:40:21.377Z
CLI Version: 0.35.2

1
  • 1
    Well the Serial is probably using the same ISR. (may differ for different boards, however Arduino Core usually occupy all related ISRs for all serial ports)
    – KIIV
    Feb 10 at 22:05

1 Answer 1

2

USART_RX_vect is defined by the Arduino core library. It is part of the implementation of the Serial object. Your sketch has a second definition of the same ISR, thus the conflict.

Basically you have two choices: either you write your own code to handle the serial port at the I/O register level (like in your ISR above), or you rely on the Serial implementation of the Arduino core (Serial.available() and Serial.read() to read data). You cannot mix the approaches like you are trying to do here.

2
  • Thanks, self-inflicted wound. In another sketch I used ISR(ADC_vect) without such a conflict but I guess that one is not implemented in the core library. Live and learn. Feb 10 at 22:14
  • @BryanHanson: Indeed. The core busy-waits for the ADC (in analogRead()) instead of using the interrupt. Feb 10 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.