@@ -151,12 +151,31 @@ milliseconds is not recommended.
151
151
Serial
152
152
------
153
153
154
- ``Serial `` object works much the same way as on a regular Arduino. Apart
155
- from hardware FIFO (128 bytes for TX and RX) ``Serial `` has
156
- additional 256-byte TX and RX buffers. Both transmit and receive is
157
- interrupt-driven. Write and read functions only block the sketch
158
- execution when the respective FIFO/buffers are full/empty. Note that
159
- the length of additional 256-bit buffer can be customized.
154
+ The ``Serial `` object works much the same way as on a regular Arduino. Apart
155
+ from the hardware FIFO (128 bytes for TX and RX), ``Serial `` has an
156
+ additional customizable 256-byte RX buffer. The size of this software buffer can
157
+ be changed by the user. It is suggested to use a bigger size at higher receive speeds.
158
+
159
+ The ``::setRxBufferSize(size_t size) `` method changes the RX buffer size as needed. This
160
+ should be called before ``::begin() ``. The size argument should be at least large enough
161
+ to hold all data received before reading.
162
+
163
+ For transmit-only operation, the 256-byte RX buffer can be switched off to save RAM by
164
+ passing mode SERIAL_TX_ONLY to Serial.begin(). Other modes are SERIAL_RX_ONLY and
165
+ SERIAL_FULL (the default).
166
+
167
+ Receive is interrupt-driven, but transmit polls and busy-waits. Blocking behavior is as follows:
168
+ The ``::write() `` call does not block if the number of bytes fits in the current space available
169
+ in the TX FIFO. The call blocks if the TX FIFO is full and waits until there is room before
170
+ writing more bytes into it, until all bytes are written. In other words, when the call returns,
171
+ all bytes have been written to the TX FIFO, but that doesn't mean that all bytes have been sent
172
+ out through the serial line yet.
173
+ The ``::read() `` call doesn't block, not even if there are no bytes available for reading.
174
+ The ``::readBytes() `` call blocks until the number of bytes read complies with the number of
175
+ bytes required by the argument passed in.
176
+ The ``::flush() `` call blocks waiting for the TX FIFO to be empty before returning. It is
177
+ recommended to call this to make sure all bytes have been sent before doing configuration changes
178
+ on the serial port (e.g. changing baudrate) or doing a board reset.
160
179
161
180
``Serial `` uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3
162
181
(RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling
@@ -180,14 +199,13 @@ instead, call ``Serial1.setDebugOutput(true)``.
180
199
You also need to use ``Serial.setDebugOutput(true) `` to enable output
181
200
from ``printf() `` function.
182
201
183
- The method ``Serial.setRxBufferSize(size_t size) `` allows to define the
184
- receiving buffer depth. The default value is 256.
185
-
186
202
Both ``Serial `` and ``Serial1 `` objects support 5, 6, 7, 8 data bits,
187
203
odd (O), even (E), and no (N) parity, and 1 or 2 stop bits. To set the
188
204
desired mode, call ``Serial.begin(baudrate, SERIAL_8N1) ``,
189
205
``Serial.begin(baudrate, SERIAL_6E2) ``, etc.
190
-
206
+ Default configuration mode is SERIAL_8N1. Possibilities are SERIAL_[5678][NEO][12].
207
+ Example: ``SERIAL_8N1 `` means 8bits No parity 1 stop bit.
208
+
191
209
A new method has been implemented on both ``Serial `` and ``Serial1 `` to
192
210
get current baud rate setting. To get the current baud rate, call
193
211
``Serial.baudRate() ``, ``Serial1.baudRate() ``. Return a ``int `` of
@@ -206,7 +224,7 @@ current speed. For example
206
224
207
225
| ``Serial`` and ``Serial1`` objects are both instances of the
208
226
``HardwareSerial`` class.
209
- | I've done this also for official ESP8266 `Software
227
+ | This is also done for official ESP8266 `Software
210
228
Serial <libraries.rst#softwareserial>`__
211
229
library, see this `pull
212
230
request <https://github.com/plerup/espsoftwareserial/pull/22>`__.
0 commit comments