paulo-raca / YetAnotherArduinoPcIntLibrary

An Arduino library to handle Pin Change Interrupts
21 stars 5 forks source link

Error when use software Serial #2

Open klero2 opened 6 years ago

klero2 commented 6 years ago

Hello.

I have been testing your library which works great and is easy to use.

recently making a project where I use your library to handle user input (buttons) along with the SoftwareSerial library it does not compile.

Just by adding the line #include it will not compile.

I use the Atmega644A, it works well if not SoftwareSerial library is included.

this is the error message the compiler give me: `Arduino: 1.8.5 (Windows 7), Board: "ATmega644, Standard, 644 / 644A, 2.7v, Enabled, 8 MHz external"

libraries\Yet_Another_Arduino_PcInt_Library\YetAnotherPcInt.cpp.o (symbol from plugin): In function `__vector_4':

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

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

libraries\Yet_Another_Arduino_PcInt_Library\YetAnotherPcInt.cpp.o (symbol from plugin): In function `__vector_4':

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

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

libraries\Yet_Another_Arduino_PcInt_Library\YetAnotherPcInt.cpp.o (symbol from plugin): In function `__vector_4':

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

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

libraries\Yet_Another_Arduino_PcInt_Library\YetAnotherPcInt.cpp.o (symbol from plugin): In function `__vector_4':

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

libraries\SoftwareSerial\SoftwareSerial.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 ATmega644.

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

klero2 commented 6 years ago

this is my code

`

include //Comment it and it will compile

define lcd_BL_pin 0

define pump_pin 26 //A2, PA2, 26

define n_1 A5

define n_2 A4

define n_3 A7

define n_4 A6

include

/ Press #1 / void num_1(const char* message){ Serial.println("#1 pressed"); digitalWrite(lcd_BL_pin,!digitalRead(lcd_BL_pin)); }

/ Press #2 / void num_2(const char* message){ Serial.println("#2 pressed"); digitalWrite(pump_pin,!digitalRead(pump_pin)); }

/ Press #3 / void num_3(const char* message){ Serial.println("#3 pressed"); }

/ Press #4 / void num_4(const char* message){ Serial.println("#4 pressed"); }

void setup() { Serial.begin(57600); // pinMode(13, OUTPUT);

pinMode(lcd_BL_pin, OUTPUT); pinMode(pump_pin, OUTPUT); digitalWrite(lcd_BL_pin, 0); digitalWrite(pump_pin, 0);

pinMode(n_1, INPUT_PULLUP); PcInt::attachInterrupt(n_1, num_1, "#1", FALLING);

pinMode(n_2, INPUT_PULLUP); PcInt::attachInterrupt(n_2, num_2, "#2", FALLING);

pinMode(n_3, INPUT_PULLUP); PcInt::attachInterrupt(n_3, num_3, "#3", FALLING);

pinMode(n_4, INPUT_PULLUP); PcInt::attachInterrupt(n_4, num_4, "#4", FALLING);

}

void loop() { Serial.println("Nada"); delay(2000); } `

paulo-raca commented 6 years ago

Hello, @klero2, thanks for using it.

Arduino's SoftwareSerial library also relies on Pin Change Interruptions, and the error you are seeing is caused by both of them trying to define the same interrupt.

They cannot coexist as-is.

One way around it to modify the libraries so that each one only attaches to a different interrupts (E.g., if PCINT_INPUT_PORT0 maps to pins 1-8 and PCINT_INPUT_PORT1 maps to pins 9-16, you can add your buttons to pins 1-8 and your serial ports on pins 9-15.

Another way would be to merge the interrupt handlers: Remove the ISR() blocks from SoftwareSerial.cpp and instead add SoftwareSerial::handle_interrupt(); on the top of IMPLEMENT_ISR() in my library;