| ||
|
Shopping Cart
|
| Home | MP3 Player | 8051 Tools | All Projects | PJRC Store | Site Map |
|
You are here:
Teensy
| Search PJRC |
|
SoftwareSerial LibrarySoftwareSerial NewSoftSerial corrects the problems present in SoftwareSerial. Download: SoftwareSerial is included with Arduino Known ProblemsSoftwareSerial does not handle interrupts properly. Any interrupts, from the normal timer0 (used for millis, delay, micros) to any other libraries in use, can cause corrupted data.SoftwareSerial has poor timing, with incorrect hard-coded assumptions about the speed of digitalWrite. On Teensy, the maximum working baud rate is 19200. SoftwareSerial does not support available(), and can only receive data when read() is called, which severly limits its usefulness for many applications. If you do use SoftwareSerial, the transmit pin is not set to output mode automatically. You must use pinMode to set it. As of June 2010, the Arduino developers are considering replace SoftwareSerial with NewSoftSerial in some future version (0019 or later). They may rename NewSoftSerial to SoftwareSerial at that time. Example Program
/* SoftwareSerial example (modified for Teensy++ pin numbers) http://arduino.cc/en/Reference/SoftwareSerialExample Sample of the SoftwareSerial library. Listens for serial in on rxPin and sends it out again on txPin. by Tom Igoe based on examples by David Mellis and Heather Dewey-Hagborg written: 6 Jan 2007 */ // include the SoftwareSerial library so you can use its functions: #include <SoftwareSerial.h> #define rxPin 27 #define txPin 0 #define ledPin 6 // set up a new serial port SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); byte pinState = 0; void setup() { // define pin modes for tx, rx, led pins: pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); pinMode(ledPin, OUTPUT); // set the data rate for the SoftwareSerial port mySerial.begin(9600); mySerial.println("Hello World - SoftwareSerial"); } void loop() { // listen for new serial coming in: char someChar = mySerial.read(); // print out the character: mySerial.print(someChar); // toggle an LED just so you see the thing's alive. // this LED will go on with every OTHER character received: toggle(ledPin); } void toggle(int pinNum) { // set the LED pin using the pinState variable: digitalWrite(pinNum, pinState); // if pinState = 0, set it to 1, and vice versa: pinState = !pinState; } DetailsFor more details, please refer to the official SoftwareSerial page. |