What is the cause of the errors “'timer0_pin_port'” and “'_vector_13'”?

偶尔善良 提交于 2021-02-11 12:07:47

问题


#include "IRremote.h"

int receiver = 11;

IRrecv irReceiver(receiver);
decode_results results;

void setup() {
  // put your setup code here, to run once:
pinMode(buttonPinA, INPUT_PULLUP);
pinMode(buttonPinB, INPUT_PULLUP);
pinMode(buttonPinC, INPUT_PULLUP);
pinMode(buttonPinD, INPUT_PULLUP);
irReceiver.enableIRIn();
}

The error message is:

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

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

libraries\IRremote\IRremote.cpp.o (symbol from plugin):(.text+0x0): first defined here

c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

collect2.exe: error: ld returned 1 exit status

exit status 1 Error compiling for board Arduino/Genuino Mega or Mega 2560.

I have recently discovered that "tone" and "IRremote" commands use timer2 from here. I am unaware of what timer2 really is and how to change it.


回答1:


This error is a link-time issue. Two pieces of library code have both declared something with the same name (in this case it's a timer).

So the compilation was all OK, and now the linker is taking the compiled output and is wrapping it into an executable. Every time you see an error message like error: ld returned ..., know it's a link problem, and not a syntax issue. Anything ld is the linker ("ld" is the name of the linker program).

As described here:

https://forum.arduino.cc/index.php?topic=120955.msg2613823#msg2613823

Edit the header file IRRemote.h and change which timer interrupt the library uses:

Change the selection:

#define IR_USE_TIMER1   // tx = pin 9
// #define IR_USE_TIMER2     // tx = pin 3

e.g.:

// #define IR_USE_TIMER1   // tx = pin 9
#define IR_USE_TIMER2     // tx = pin 3


来源:https://stackoverflow.com/questions/53472527/what-is-the-cause-of-the-errors-timer0-pin-port-and-vector-13

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!