Home arrow Forum arrow Archived Forum
FreakLabs Forum
Welcome, Guest
Please Login or Register.    Lost Password?
freakduino, gps and NewSoftSerial - library conflict (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: freakduino, gps and NewSoftSerial - library conflict
#2680
Eric Walstad (User)
Apprentice Freak
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
freakduino, gps and NewSoftSerial - library conflict 3 Years, 11 Months ago Karma: 0  
Hi,

I'm trying to get my freakduinos-with-gps-shields to send gps data to each other. I'm getting a compiler error when I try to include the NewSoftSerial library:
Code:

#include <chibi.h> #include <NewSoftSerial.h> void setup() { } void loop() { }
Code:

/tmp/build2295336246552428931.tmp/NewSoftSerial/NewSoftSerial.cpp.o: In function `NewSoftSerial::NewSoftSerial(unsigned char, unsigned char, bool)': /usr/share/arduino/libraries/NewSoftSerial/NewSoftSerial.cpp:346: multiple definition of `__vector_3' /tmp/build2295336246552428931.tmp/chibiArduino/chibi.cpp.o:/usr/share/arduino/libraries/chibiArduino/chibi.cpp:69: first defined here
If either of the above includes is commented out then it compiles fine. I've grepped my Arduino library dir for '__vector_3' but found no matches. I can get my two freakduinos to send simple strings back and forth with the example sketches that Akiba includes. I can get them to aqcuire a GPS lock and send GPS data to the serial monitor using NSS. But, if I try to use both libraries I get the error. I've googled the arduino forums but didn't find a fix or any ideas on where to go from here. Any advice is appreciated. Thanks in advance, Eric.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#2681
Akiba (Admin)
Admin
Posts: 1245
graph
User Online Now Click here to see the profile of this user
Re:freakduino, gps and NewSoftSerial - library conflict 3 Years, 11 Months ago Karma: 25  
Hi Eric.
The NewSoftSerial library is declaring interrupt service routines for the pin change interrupts even if it doesn't use them. Here's a quick explanation of how the pin change interrupts work.

Almost all of the IOs on the ATMega328P can be used as an interrupt, but only to detect if there's a level change (high to low, low to high). This is in addition to the two dedicated external interrupt pins on the chip. If you look at the datasheet, you'll see that the pin names have designations like PCINT0 to PCINT23. The ATMega328 groups 8 pin change interrupts together into one interrupt vector so in total, there are three dedicated pin change interrupt vectors called PCINT0_vect, PCINT1_vect, and PCINT2_vect.

PCINT0_vect is the vector that handles any interrupt from physical pins PCINT0 to PCINT7, PCINT1_vect handles interrupts from physical pins PCINT8 to PCINT15, etc...

The chibiArduino stack uses physical pin PCINT6 (XTAL1/PB6) on the ATMega328. That means that its interrupt vector gets mapped to PCINT0_vect. In the NewSoftSerial Library, it declares interrupt service routines for all three pin change interrupt vectors PCINT0_vect, PCINT1_vect, and PCINT2_vect, even if they are not used. Hence, you can comment out the service routine in the NewSoftSerial library if you're not using the associated pins for serial data.

The chibiArduino stack requires the PCINT0_vect to operate. If you comment out (disable) the PCINT0_vect from the NewSoftSerial library, you will not be able to use Arduino pins 8-13 for software serial data. Actually pins 11 to 13 are used for the SPI so basically, you'd be restricted from using digital pins 8 to 10. If you're okay with this, then its possible to use chibiArduino and NewSoftSerial together. Here is the modification I made on the NewSoftSerial library so that the two stacks can compile when used together.

NewSoftSerial.cpp, approximately Line 315
Code:

//#if defined(PCINT0_vect) //ISR(PCINT0_vect) //{ // NewSoftSerial::handle_interrupt(); //} //#endif #if defined(PCINT1_vect) ISR(PCINT1_vect) { NewSoftSerial::handle_interrupt(); } #endif #if defined(PCINT2_vect) ISR(PCINT2_vect) { NewSoftSerial::handle_interrupt(); } #endif #if defined(PCINT3_vect) ISR(PCINT3_vect) { NewSoftSerial::handle_interrupt(); } #endif
 
Report to moderator   Logged Logged  
 
Last Edit: 2010/12/26 18:13 By cjwang.
  The administrator has disabled public write access.
#3138
Rob (Visitor)
Click here to see the profile of this user
Birthdate:
Re:freakduino, gps and NewSoftSerial - library conflict 3 Years, 3 Months ago  
I have a similar problem using NewSoftSerial with the Chibi. I am using pins 2,3 to talk with a TTL serial camera (Adafruit).

While the library now compiles without errors, I am seeing frequent random errors in the data transfer (32 bytes, 38400). I've validated the hardware is working fine, and using a Duemilanova works without error. Doesn't commenting out that vector disable NewSoftSerial from being able to use interrupts on physical pins 0 through 7 rather than pins 8-13 ?

Thanks in advance for any insights
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#3139
Rob (Visitor)
Click here to see the profile of this user
Birthdate:
Re:freakduino, gps and NewSoftSerial - library conflict 3 Years, 3 Months ago  
Answer to my own post ... read the data sheet. NewSoftSerial on PD3 and PD4, aka PCINT19 and PCINT20, would be PCINT2_vect.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
get the latest posts directly to your desktop