multible definition of __vector_X

Hello,

I have a Nano talk to a PZEM017 and a PZEM014 device.

The PZEM017 is a DC energy meter working with 9600 8N2.
The PZEM014 is a AC energy meter working with 9600 8N1.

So as SoftwareSerial does not support 8N2 I used CustomSoftwareSerial.
The PZEM017 only works with the CustomSoftwareSerial with 9600 8N2.

Now to make matters more complicated, the PZEM014 does not work with the CustomSoftwareSerial in 9600 8N1, but it does work with the SoftwareSerial. I have no idea, why that is, I suspect some timing and delay differences.

So I got them PZEMs working in two seperate sketches, but when mergin' the sketches, I get the error of multible definitions of __vector_3, __vector_4 and __vector_5.

Arduino: 1.8.9 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"
libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function SoftwareSerial::read()':** **(.text+0x0): multiple definition of __vector_3'
libraries\CustomSerial\CustomSWSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function SoftwareSerial::read()':** **(.text+0x0): multiple definition of __vector_4'
libraries\CustomSerial\CustomSWSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function SoftwareSerial::read()':** **(.text+0x0): multiple definition of __vector_5'
libraries\CustomSerial\CustomSWSerial.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 Nano.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

It might be, that both interfaces use the same interrupts. Yet, I'm not sure.

I have no idea, how I can resolve that problem.

I can add the entire code, but it is quite extensive and maybe it is possible to give me some hints without me using extensive time to create a small demo version of it.

Thanks in advance.

The difference of the SoftwareSerial and the CustomSWSerial is indeed a delay problem. Adjusting the delay times made it work.

Still I'd be interested in hints on the vector problem.

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

This means that two different pieces of code in your sketch are trying to set the value of the same interrupt vector. Often it is two libraries that use the same timer interrupt.

In this case it appears to be two libraries using the Pin Change interrupts:
__vector_3 = PCINT0 Handler
__vector_4 = PCINT1 Handler
__vector_5 = PCINT2 Handler

NeoSWSerial provides a workaround for two libraries trying to use the same interrupt vector.

The same conflict occurs if you try to use pin change interrupts with software serial.

Thanks for your answers.

So what can I do, when two libraries use the same interrupt?

Nothing?
Maybe try find another library doing the same thing?

I have solved the problem with the two PZEM devices. I can use CustomSWSerial only now.

However, I wanted to add a PCF8575 and now this library produces the same errors, when included.

Please post your code. Please include links to all non-standard libraries that you include.

Regarding interrupt conflicts, sometimes libraries have an easy way to change an ISR, sometimes they don't in which case you have either find an alternative or try to hack the existing one.

Be aware that a microcontroller has limited resources (e.g. timers) and hence the problem that you're experiencing.