本帖最后由 cciew 于 2015-9-9 00:52 编辑
来自:http://forum.arduino.cc/index.php?topic=336196.0
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.
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(http://forum.arduino.cc/index.ph ... &topic=251764.0).
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. |