Skip to content

Commit bcf1463

Browse files
ABOSTMfpistm
authored andcommitted
SoftwareSerial implementation (#645)
1 parent f2ef8f2 commit bcf1463

File tree

6 files changed

+708
-0
lines changed

6 files changed

+708
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Software serial multple serial test
3+
4+
Receives from the hardware serial, sends to software serial.
5+
Receives from software serial, sends to hardware serial.
6+
7+
The circuit:
8+
* RX is digital pin 10 (connect to TX of other device)
9+
* TX is digital pin 11 (connect to RX of other device)
10+
11+
created back in the mists of time
12+
modified 25 May 2012
13+
by Tom Igoe
14+
based on Mikal Hart's example
15+
16+
This example code is in the public domain.
17+
18+
*/
19+
#include <SoftwareSerial.h>
20+
21+
SoftwareSerial mySerial(10, 11); // RX, TX
22+
23+
void setup() {
24+
// Open serial communications and wait for port to open:
25+
Serial.begin(57600);
26+
while (!Serial) {
27+
; // wait for serial port to connect. Needed for native USB port only
28+
}
29+
30+
31+
Serial.println("Goodnight moon!");
32+
33+
// set the data rate for the SoftwareSerial port
34+
mySerial.begin(4800);
35+
mySerial.println("Hello, world?");
36+
}
37+
38+
void loop() { // run over and over
39+
if (mySerial.available()) {
40+
Serial.write(mySerial.read());
41+
}
42+
if (Serial.available()) {
43+
mySerial.write(Serial.read());
44+
}
45+
}
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Software serial multple serial test
3+
4+
Receives from the two software serial ports,
5+
sends to the hardware serial port.
6+
7+
In order to listen on a software port, you call port.listen().
8+
When using two software serial ports, you have to switch ports
9+
by listen()ing on each one in turn. Pick a logical time to switch
10+
ports, like the end of an expected transmission, or when the
11+
buffer is empty. This example switches ports when there is nothing
12+
more to read from a port
13+
14+
The circuit:
15+
Two devices which communicate serially are needed.
16+
* First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX)
17+
* Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX)
18+
19+
20+
created 18 Apr. 2011
21+
modified 19 March 2016
22+
by Tom Igoe
23+
based on Mikal Hart's twoPortRXExample
24+
25+
This example code is in the public domain.
26+
27+
*/
28+
29+
#include <SoftwareSerial.h>
30+
// software serial #1: RX = digital pin 10, TX = digital pin 11
31+
SoftwareSerial portOne(10, 11);
32+
33+
// software serial #2: RX = digital pin 8, TX = digital pin 9
34+
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
35+
SoftwareSerial portTwo(8, 9);
36+
37+
void setup() {
38+
// Open serial communications and wait for port to open:
39+
Serial.begin(9600);
40+
while (!Serial) {
41+
; // wait for serial port to connect. Needed for native USB port only
42+
}
43+
44+
45+
// Start each software serial port
46+
portOne.begin(9600);
47+
portTwo.begin(9600);
48+
}
49+
50+
void loop() {
51+
// By default, the last intialized port is listening.
52+
// when you want to listen on a port, explicitly select it:
53+
portOne.listen();
54+
Serial.println("Data from port one:");
55+
// while there is data coming in, read it
56+
// and send to the hardware serial port:
57+
while (portOne.available() > 0) {
58+
char inByte = portOne.read();
59+
Serial.write(inByte);
60+
}
61+
62+
// blank line to separate data from the two ports:
63+
Serial.println();
64+
65+
// Now listen on the second port
66+
portTwo.listen();
67+
// while there is data coming in, read it
68+
// and send to the hardware serial port:
69+
Serial.println("Data from port two:");
70+
while (portTwo.available() > 0) {
71+
char inByte = portTwo.read();
72+
Serial.write(inByte);
73+
}
74+
75+
// blank line to separate data from the two ports:
76+
Serial.println();
77+
}

libraries/SoftwareSerial/keywords.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#######################################
2+
# Syntax Coloring Map for SoftwareSerial
3+
# (formerly NewSoftSerial)
4+
#######################################
5+
6+
#######################################
7+
# Datatypes (KEYWORD1)
8+
#######################################
9+
10+
SoftwareSerial KEYWORD1
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
begin KEYWORD2
17+
end KEYWORD2
18+
read KEYWORD2
19+
write KEYWORD2
20+
available KEYWORD2
21+
isListening KEYWORD2
22+
overflow KEYWORD2
23+
flush KEYWORD2
24+
listen KEYWORD2
25+
peek KEYWORD2
26+
27+
#######################################
28+
# Constants (LITERAL1)
29+
#######################################
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=SoftwareSerial
2+
version=1.0
3+
author=Arduino, Armin van der Togt
4+
maintainer=stm32duino
5+
sentence=Enables serial communication on any digital pin.
6+
paragraph=The SoftwareSerial library has been developed to allow serial communication on any digital pin of the board, using software to replicate the functionality of the hardware UART. It is possible to have multiple software serial ports.
7+
category=Communication
8+
url=http://www.arduino.cc/en/Reference/SoftwareSerial
9+
architectures=stm32
10+

0 commit comments

Comments
 (0)