cciew 发表于 2015-9-9 00:36:15

atmega16 不支持软串口(SoftwareSerial)吗?

atmega16 不支持软串口(SoftwareSerial)吗?atmega8也不支持?除了他俩其他芯片好像都可以!



cciew 发表于 2015-9-9 00:48:13

本帖最后由 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 usePCINT 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.php?PHPSESSID=94oaj0io1gcp4ja4lld3oa7kg3&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.

cciew 发表于 2015-9-9 00:55:39

http://forum.arduino.cc/index.php?PHPSESSID=94oaj0io1gcp4ja4lld3oa7kg3&topic=251764.0
In a recent Thread the usual complaints were made about the SoftwareSerial library not functioning alongside the Servo library. In Reply #17 @oric_dan suggested a limited version of SoftwareSerial for the Uno that would work in parallel with other libraries.

That prompted the realization that I had a few projects that together probably contained all of the concepts necessary to achieve that.

The attached code sss.ino is the result. It uses Pins 3 (INT1) and 4 and Timer2A and seems to work quite happily with the Servo library. It is only intended for use on an Uno (or standalone Atmega 328).

The file DemoSimpleSoftSerial.ino illustrates the use of sss.ino. And the file DemoPartner.ino is a program that I have run on a Mega (because it has multiple hardware Serial Ports) to receive data from and send data to the Uno.

I concluded that there is little advantage in converting the code into a Class or into a proper Library. Because of its simplicity there cannot be multiple instances of it - in other words you can only use it to add one Software Serial connection to an Uno. Because of the way the Arduino manages projects the variables in sss.ino are not accessible to the code in the main .ino file but the various functions are. I have prefixed the names of all the functions and variables with sss to reduce the possibility of clashing with names in other parts of a project.

To use the code you just need to add a copy of the file sss.ino into the Arduino project. Using the demo program attached you would put both of the file DemoSimpleSoftSerial.ino and sss.ino into a directory called DemoSimpleSoftSerial.

Interestingly the code works exactly as I expected it would when the idea first occurred to me but I could fill a whole book with the stupid mistakes that wasted time while bringing the various pieces together.

...R

zhb1190 发表于 2015-9-9 09:23:27

软串口需要用到port信号改变的中断,atmega8和16貌似都没有,所以用不了

cciew 发表于 2015-9-9 20:39:14

“zhb1190”解释的好,但是想用,能添加外部中断吗?
页: [1]
查看完整版本: atmega16 不支持软串口(SoftwareSerial)吗?