Skip to content

Commit

Permalink
Fix outdated README, source comments for readParity. Fix dropped 0xff…
Browse files Browse the repository at this point in the history
… octets. (#205)

* Fixes #203 

* Check for hidden stop bit at the end of each rxBits. Fixes first-octet in session dropped issue, and

intermittently dropped octets, in particular the delay(2000), issue. 

* Fixes #204 

* Use precise enum value identifier in sample code.
  • Loading branch information
dok-net authored Mar 26, 2021
1 parent 7fdef9b commit 45437b0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ argument to ``begin()``. Word lengths can be set to between 5 and 8 bits, parity
can be N(one), O(dd) or E(ven) and 1 or 2 stop bits can be used. The default is
``SWSERIAL_8N1`` using 8 bits, no parity and 1 stop bit but any combination can
be used, e.g. ``SWSERIAL_7E2``. If using EVEN or ODD parity, any parity errors
can be detected with the ``peekParityError()`` function. Note that parity
checking must be done before ``read()``, as the parity information is removed
from the buffer when reading the corresponding byte.
can be detected with the ``readParity()`` and ``parityEven()`` or ``parityOdd()``
functions respectively. Note that the result of ``readParity()`` always applies
to the preceding ``read()`` or ``peek()`` call, and is undefined if they report
no data or an error.

To allow flexible 9-bit and data/addressing protocols, the additional parity
modes MARK and SPACE are also available. Furthermore, the parity mode can be
Expand All @@ -93,8 +94,8 @@ up SoftwareSerial with parity mode SPACE, e.g. ``SWSERIAL_8S1``. This will add a
parity bit to every byte sent, setting it to logical zero (SPACE parity).

To detect incoming bytes with the parity bit set (MARK parity), use the
``peekParityError()`` function. To send a byte with the parity bit set, just add
``MARK`` as the second argument when writing, e.g. ``write(ch, MARK)``.
``readParity()`` function. To send a byte with the parity bit set, just add
``MARK`` as the second argument when writing, e.g. ``write(ch, SWSERIAL_PARITY_MARK)``.

## Using and updating EspSoftwareSerial in the esp8266com/esp8266 Arduino build environment

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EspSoftwareSerial",
"version": "6.12.0",
"version": "6.12.1",
"keywords": [
"serial", "io", "softwareserial"
],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EspSoftwareSerial
version=6.12.0
version=6.12.1
author=Dirk Kaar, Peter Lerup
maintainer=Dirk Kaar <[email protected]>
sentence=Implementation of the Arduino software serial for ESP8266/ESP32.
Expand Down
8 changes: 3 additions & 5 deletions src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ int SoftwareSerial::peek() {
}

void SoftwareSerial::rxBits() {
int isrAvail = m_isrBuffer->available();
#ifdef ESP8266
if (m_isrOverflow.load()) {
m_overflow = true;
Expand All @@ -433,19 +432,18 @@ void SoftwareSerial::rxBits() {
}
#endif

m_isrBuffer->for_each([this](const uint32_t& isrCycle) { rxBits(isrCycle); });

// stop bit can go undetected if leading data bits are at same level
// and there was also no next start bit yet, so one byte may be pending.
// low-cost check first
if (!isrAvail && m_rxCurBit >= -1 && m_rxCurBit < m_pduBits - m_stopBits) {
if (m_rxCurBit >= -1 && m_rxCurBit < m_pduBits - m_stopBits) {
uint32_t detectionCycles = (m_pduBits - m_stopBits - m_rxCurBit) * m_bitCycles;
if (ESP.getCycleCount() - m_isrLastCycle > detectionCycles) {
// Produce faux stop bit level, prevents start bit maldetection
// cycle's LSB is repurposed for the level bit
rxBits(((m_isrLastCycle + detectionCycles) | 1) ^ m_invert);
}
}

m_isrBuffer->for_each([this](const uint32_t& isrCycle) { rxBits(isrCycle); });
}

void SoftwareSerial::rxBits(const uint32_t& isrCycle) {
Expand Down
2 changes: 1 addition & 1 deletion src/SoftwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class SoftwareSerial : public Stream {
}
int peek() override;
int read() override;
/// @returns The verbatim parity bit associated with the last read() or peek() call
/// @returns The verbatim parity bit associated with the last successful read() or peek() call
bool readParity()
{
return m_lastReadParity;
Expand Down

0 comments on commit 45437b0

Please sign in to comment.