|
| 1 | +**Contributed by Kevin Smith of Stroud Research Center** |
| 2 | + |
| 3 | +If you look at the SoftwareSerial library - |
| 4 | +https://github.com/arduino/Arduino/blob/master/libraries/SoftwareSerial/SoftwareSerial.cpp |
| 5 | + |
| 6 | +- you will see a section of code copied below: |
| 7 | + |
| 8 | +#if defined(PCINT0_vect) |
| 9 | +ISR(PCINT0_vect) |
| 10 | +{ |
| 11 | + SoftwareSerial::handle_interrupt(); |
| 12 | +} |
| 13 | +#endif |
| 14 | + |
| 15 | +#if defined(PCINT1_vect) |
| 16 | +ISR(PCINT1_vect) |
| 17 | +{ |
| 18 | + SoftwareSerial::handle_interrupt(); |
| 19 | +} |
| 20 | +#endif |
| 21 | + |
| 22 | +#if defined(PCINT2_vect) |
| 23 | +ISR(PCINT2_vect) |
| 24 | +{ |
| 25 | + SoftwareSerial::handle_interrupt(); |
| 26 | +} |
| 27 | +#endif |
| 28 | + |
| 29 | +#if defined(PCINT3_vect) |
| 30 | +ISR(PCINT3_vect) |
| 31 | +{ |
| 32 | + SoftwareSerial::handle_interrupt(); |
| 33 | +} |
| 34 | +#endif |
| 35 | + |
| 36 | + |
| 37 | +It basically says, if the hardware has something called PCINT0, PCINT1, PCINT2, or PCINT3, |
| 38 | +claim it for the SoftwareSerial library to use. ArduinoUNO only has up to PCINT2, but |
| 39 | +other models have more PCINTs available. |
| 40 | + |
| 41 | +Anyway, we do not need to be so greedy. We only need pins 2 and 3 for SoftwareSerial, which |
| 42 | +is PCINT2. So we simply "comment out" the sections in the SoftwareSerial library that |
| 43 | +we aren't using for SoftwareSerial. Commenting out is better than deleting, since you |
| 44 | +may want to get this functionality back later. |
| 45 | + |
| 46 | +//#if defined(PCINT0_vect) |
| 47 | +//ISR(PCINT0_vect) |
| 48 | +//{ |
| 49 | +// SoftwareSerial::handle_interrupt(); |
| 50 | +//} |
| 51 | +//#endif |
| 52 | + |
| 53 | +//#if defined(PCINT1_vect) |
| 54 | +//ISR(PCINT1_vect) |
| 55 | +//{ |
| 56 | +// SoftwareSerial::handle_interrupt(); |
| 57 | +//} |
| 58 | +//#endif |
| 59 | + |
| 60 | +#if defined(PCINT2_vect) |
| 61 | +ISR(PCINT2_vect) |
| 62 | +{ |
| 63 | + SoftwareSerial::handle_interrupt(); |
| 64 | +} |
| 65 | +#endif |
| 66 | + |
| 67 | +//#if defined(PCINT3_vect) |
| 68 | +//ISR(PCINT3_vect) |
| 69 | +//{ |
| 70 | +// SoftwareSerial::handle_interrupt(); |
| 71 | +//} |
| 72 | +//#endif |
| 73 | + |
| 74 | +Next, we are going to do the complementary action in the SDI-12 Library, which is also |
| 75 | +being greedy. Since we are using pin 9 for SDI-12, we give it to PCINT0: |
| 76 | + |
| 77 | +//6.3 |
| 78 | +#if defined(PCINT0_vect) |
| 79 | +ISR(PCINT0_vect){ SDI12::handleInterrupt(); } |
| 80 | +#endif |
| 81 | + |
| 82 | +//#if defined(PCINT1_vect) |
| 83 | +//ISR(PCINT1_vect){ SDI12::handleInterrupt(); } |
| 84 | +//#endif |
| 85 | + |
| 86 | +//#if defined(PCINT2_vect) |
| 87 | +//ISR(PCINT2_vect){ SDI12::handleInterrupt(); } |
| 88 | +//#endif |
| 89 | + |
| 90 | +//#if defined(PCINT3_vect) |
| 91 | +//ISR(PCINT3_vect){ SDI12::handleInterrupt(); } |
| 92 | +//#endif |
| 93 | + |
| 94 | +Restart the Arduino IDE, and it should recognize the changes to the libraries and your |
| 95 | +code should compile without issue. |
0 commit comments