@@ -12,12 +12,13 @@ Except at high bitrates, depending on other ongoing activity,
12
12
interrupts in particular, this software serial adapter
13
13
supports full duplex receive and send. At high bitrates (115200bps)
14
14
send bit timing can be improved at the expense of blocking concurrent
15
- full duplex receives, with the SoftwareSerial::enableIntTx(false) function call.
15
+ full duplex receives, with the `` SoftwareSerial::enableIntTx(false) `` function call.
16
16
17
17
The same functionality is given as the corresponding AVR library but
18
18
several instances can be active at the same time. Speed up to 115200 baud
19
- is supported. Diverging from the AVR SoftwareSerial class, the constructor takes
20
- no arguments, instead the begin() function handles pin assignments and logic inversion.
19
+ is supported. Besides a constructor compatible to the AVR SoftwareSerial class,
20
+ and updated constructor that takes no arguments exists, instead the `` begin() ``
21
+ function can handle the pin assignments and logic inversion.
21
22
It also has optional input buffer capacity arguments for byte buffer and ISR bit buffer.
22
23
This way, it is a better drop-in replacement for the hardware serial APIs on the ESP MCUs.
23
24
@@ -26,12 +27,11 @@ ongoing, there will be some inexactness in interrupt timings. This may
26
27
lead to inevitable, but few, bit errors when having heavy data traffic
27
28
at high baud rates.
28
29
29
-
30
30
## Resource optimization
31
31
32
32
The memory footprint can be optimized to just fit the amount of expected
33
33
incoming asynchronous data.
34
- For this, the SoftwareSerial constructor provides two arguments. First, the
34
+ For this, the `` SoftwareSerial `` constructor provides two arguments. First, the
35
35
octet buffer capacity for assembled received octets can be set. Read calls are
36
36
satisfied from this buffer, freeing it in return.
37
37
Second, the signal edge detection buffer of 32bit fields can be resized.
@@ -41,7 +41,7 @@ to assemble received octets, thus promoting completed octets to the octet
41
41
buffer, freeing fields in the edge detection buffer.
42
42
43
43
Look at the swsertest.ino example. There, on reset, ASCII characters ' ' to 'z'
44
- are send . This happens not as a block write, but in single write calls per
44
+ are sent . This happens not as a block write, but in a single write call per
45
45
character. As the example uses a local loopback wire, every outgoing bit is
46
46
immediately received back. Therefore, any single write call causes up to
47
47
10 fields - depending on the exact bit pattern - to be occupied in the signal
@@ -57,43 +57,67 @@ data until the next read call.
57
57
For the swsertest.ino example, this results in the following optimized
58
58
constructor arguments to spend only the minimum RAM on buffers required:
59
59
60
- The octet buffer capacity (bufCapacity) is 93 (91 characters net plus two tolerance).
61
- The signal edge detection buffer capacity (isrBufCapacity) is 10, as each octet has
60
+ The octet buffer capacity (`` bufCapacity `` ) is 93 (91 characters net plus two tolerance).
61
+ The signal edge detection buffer capacity (`` isrBufCapacity `` ) is 10, as each octet has
62
62
10 bits on the wire, which are immediately received during the write, and each
63
63
write call causes the signal edge detection to promote the previously sent and
64
64
received bits to the octet buffer.
65
65
66
66
In a more generalized scenario, calculate the bits (use message size in octets
67
67
times 10) that may be asynchronously received to determine the value for
68
- isrBufCapacity in the constructor. Also use the number of received octets
69
- that must be buffered for reading as the value of bufCapacity.
68
+ `` isrBufCapacity `` in the constructor. Also use the number of received octets
69
+ that must be buffered for reading as the value of `` bufCapacity `` .
70
70
The more frequently your code calls write or read functions, the greater the
71
- chances are that you can reduce the isrBufCapacity footprint without losing data,
71
+ chances are that you can reduce the `` isrBufCapacity `` footprint without losing data,
72
72
and each time you call read to fetch from the octet buffer, you reduce the
73
73
need for space there.
74
74
75
+ ## SoftwareSerialConfig and parity
76
+ The configuration of the data stream is done via a `` SoftwareSerialConfig ``
77
+ argument to `` begin() `` . Word lengths can be set to between 5 and 8 bits, parity
78
+ can be N(one), O(dd) or E(ven) and 1 or 2 stop bits can be used. The default is
79
+ `` SWSERIAL_8N1 `` using 8 bits, no parity and 1 stop bit but any combination can
80
+ be used, e.g. `` SWSERIAL_7E2 `` . If using EVEN or ODD parity, any parity errors
81
+ can be detected with the `` peekParityError() `` function. Note that parity
82
+ checking must be done before `` read() `` , as the parity information is removed
83
+ from the buffer when reading the corresponding byte.
84
+
85
+ To allow flexible 9-bit and data/addressing protocols, the additional parity
86
+ modes MARK and SPACE are also available. Furthermore, the parity mode can be
87
+ individually set in each call to `` write() `` .
88
+
89
+ This allows a simple implementation of protocols where the parity bit is used to
90
+ distinguish between data and addresses/commands ("9-bit" protocols). First set
91
+ up SoftwareSerial with parity mode SPACE, e.g. `` SWSERIAL_8S1 `` . This will add a
92
+ parity bit to every byte sent, setting it to logical zero (SPACE parity).
93
+
94
+ To detect incoming bytes with the parity bit set (MARK parity), use the
95
+ `` peekParityError() `` function. To send a byte with the parity bit set, just add
96
+ `` MARK `` as the second argument when writing, e.g. `` write(ch, MARK) `` .
75
97
76
98
## Using and updating EspSoftwareSerial in the esp8266com/esp8266 Arduino build environment
77
99
78
- The EspSoftwareSerial is both part of the BSP download for ESP8266 in Arduino,
100
+ EspSoftwareSerial is both part of the BSP download for ESP8266 in Arduino,
79
101
and it is set up as a Git submodule in the esp8266 source tree,
80
- specifically in .../esp8266/libraries/SoftwareSerial when using a Github
102
+ specifically in `` .../esp8266/libraries/SoftwareSerial `` when using a Github
81
103
repository clone in your Arduino sketchbook hardware directory.
82
104
This supersedes any version of EspSoftwareSerial installed for instance via
83
105
the Arduino library manager, it is not required to install EspSoftwareSerial
84
- for the ESP8266 separately at all.
106
+ for the ESP8266 separately at all, but doing so has ill effect .
85
107
86
108
The responsible maintainer of the esp8266 repository has kindly shared the
87
109
following command line instructions to use, if one wishes to manually
88
110
update EspSoftwareSerial to a newer release than pulled in via the ESP8266 Arduino BSP:
89
111
90
112
To update esp8266/arduino SoftwareSerial submodule to lastest master:
91
113
92
- ```
93
- (optional, clean it:)
114
+ Clean it (optional):
115
+ ``` shell
94
116
$ rm -rf libraries/SoftwareSerial
95
117
$ git submodule update --init
96
- (now update it:)
118
+ ```
119
+ Now update it:
120
+ ``` shell
97
121
$ cd libraries/SoftwareSerial
98
122
$ git checkout master
99
123
$ git pull
0 commit comments