Missing definitions in the pins_arduino file for ATmega16/32. Compiling error!

Hi! I'm running Arduino code on ATmega16 and ATmega32, using Optiboot. It works really well, but today I tried to compile a sketch that included the SoftSerial library. I got this error message:

Build options changed, rebuilding all
/Users/hansi/Documents/Arduino/hardware/DIP-40/avr/libraries/SoftwareSerial/SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
/Users/hansi/Documents/Arduino/hardware/DIP-40/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:317:36: error: 'digitalPinToPCICR' was not declared in this scope
   if (digitalPinToPCICR(_receivePin)) {
                                    ^
In file included from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/io.h:99:0,
                 from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/interrupt.h:38,
                 from /Users/hansi/Documents/Arduino/hardware/DIP-40/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:41:
/Users/hansi/Documents/Arduino/hardware/DIP-40/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:358:76: error: 'digitalPinToPCICRbit' was not declared in this scope
     *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
                                                                            ^
/Users/hansi/Documents/Arduino/hardware/DIP-40/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:361:51: error: 'digitalPinToPCMSK' was not declared in this scope
     _pcint_maskreg = digitalPinToPCMSK(_receivePin);
                                                   ^
In file included from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/io.h:99:0,
                 from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/interrupt.h:38,
                 from /Users/hansi/Documents/Arduino/hardware/DIP-40/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:41:
/Users/hansi/Documents/Arduino/hardware/DIP-40/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:362:60: error: 'digitalPinToPCMSKbit' was not declared in this scope
     _pcint_maskvalue = _BV(digitalPinToPCMSKbit(_receivePin));
                                                            ^
Error compiling.

I've been looking into the error message, and it seems like the pins_arduino.h file for the ATmega16 and ATmega32 don't include the following definitions:
#define digitalPinToPCICR(p)
#define digitalPinToPCICRbit(p)
#define digitalPinToPCMSK(p)
#define digitalPinToPCMSKbit(p)

as far as I can read from the datasheet, the ATmega16/32 don't have PCINT on any pin. Does this mean soft serial cant be used on these microcontrollers? Can the pins_arduino file be modified to get softserial working

I've included the pins_arduino.h file for the ATmega1284p (compiles without any errors) and ATmega32 (compiling errors)

pins_arduino_ATmega32.h (5.06 KB)

pins_arduino_ATmega1284p.h (4.78 KB)

If it needs to use PCINT pins, yeah, you're out of luck on the '16/32

The 16/32 does provide three external interrupts though (int0,int1, int2), and the software serial library could be modified to use those (though that of course constrains your choice of which pin to use for it) - there may be such a library already available.

the ATmega16/32 don't have PCINT on any pin. Does this mean soft serial cant be used on these microcontrollers?

Yep. That means that "as written" the current software serial library won't run on mega16/mega32 (or ATmega8, either, which is closer to being "officially supported.")
The pin change interrupts give the software serial library the ability to "catch" input characters even when the sketch is not explicitly doing a "read" operation. This is very useful, but is not ALWAYS required. You might be able to find an older SS library that doesn't use PCINT that would still do what you need.

SoftwareSerial uses pin change interrupts because it provides maximum pin selection flexibility -- provided no other library wants to use pin change interrupts (it grabs them all). But changing the code to use external interrupts instead is relatively easy. You could troll someone here into writing a modified version for you. I'd do it! Ha ha.

Robin2 wrote a piece of code that also does this, using external interrupts. Look here.

If you can't use the external interrupt pins then you'd have to do it by polling, like westfw is talking about. That'll work just fine if you don't have anything else to do at the same time. Actually, SoftwareSerial kind of takes over your processor anyways, so it might as well be polling.