This commit is contained in:
@@ -1,33 +1,35 @@
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// On ESP8266:
|
||||
// Local SoftwareSerial loopback, connect D5 (rx) and D6 (tx).
|
||||
// Local EspSoftwareSerial loopback, connect D5 (rx) and D6 (tx).
|
||||
// For local hardware loopback, connect D5 to D8 (tx), D6 to D7 (rx).
|
||||
// For hardware send/sink, connect D7 (rx) and D8 (tx).
|
||||
// Hint: The logger is run at 9600bps such that enableIntTx(true) can remain unchanged. Blocking
|
||||
// interrupts severely impacts the ability of the SoftwareSerial devices to operate concurrently
|
||||
// interrupts severely impacts the ability of the EspSoftwareSerial devices to operate concurrently
|
||||
// and/or in duplex mode.
|
||||
// Operating in software serial full duplex mode, runs at 19200bps and few errors (~2.5%).
|
||||
// Operating in software serial half duplex mode (both loopback and repeater),
|
||||
// runs at 57600bps with nearly no errors.
|
||||
// Operating loopback in full duplex, and repeater in half duplex, runs at 38400bps with nearly no errors.
|
||||
// On ESP32:
|
||||
// For SoftwareSerial or hardware send/sink, connect D5 (rx) and D6 (tx).
|
||||
// For EspSoftwareSerial or hardware send/sink, connect D5 (rx) and D6 (tx).
|
||||
// Hardware Serial2 defaults to D4 (rx), D3 (tx).
|
||||
// For local hardware loopback, connect D5 (rx) to D3 (tx), D6 (tx) to D4 (rx).
|
||||
|
||||
#ifndef D5
|
||||
#if defined(ESP8266)
|
||||
#define D5 (14)
|
||||
#define D6 (12)
|
||||
#define D7 (13)
|
||||
#define D8 (15)
|
||||
#define D5 (14)
|
||||
#define D7 (13)
|
||||
#define D6 (12)
|
||||
#define RX (3)
|
||||
#define TX (1)
|
||||
#elif defined(ESP32)
|
||||
#define D5 (18)
|
||||
#define D6 (19)
|
||||
#define D7 (23)
|
||||
#define D8 (5)
|
||||
#define D5 (18)
|
||||
#define D7 (23)
|
||||
#define D6 (19)
|
||||
#define RX (3)
|
||||
#define TX (1)
|
||||
#endif
|
||||
#endif
|
||||
@@ -45,11 +47,11 @@ constexpr int IUTBITRATE = 19200;
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
constexpr SoftwareSerialConfig swSerialConfig = SWSERIAL_8E1;
|
||||
constexpr SerialConfig hwSerialConfig = SERIAL_8E1;
|
||||
constexpr EspSoftwareSerial::Config swSerialConfig = EspSoftwareSerial::SWSERIAL_8E1;
|
||||
constexpr SerialConfig hwSerialConfig = ::SERIAL_8E1;
|
||||
#elif defined(ESP32)
|
||||
constexpr SoftwareSerialConfig swSerialConfig = SWSERIAL_8E1;
|
||||
constexpr uint32_t hwSerialConfig = SERIAL_8E1;
|
||||
constexpr EspSoftwareSerial::Config swSerialConfig = EspSoftwareSerial::SWSERIAL_8E1;
|
||||
constexpr uint32_t hwSerialConfig = ::SERIAL_8E1;
|
||||
#else
|
||||
constexpr unsigned swSerialConfig = 3;
|
||||
#endif
|
||||
@@ -70,37 +72,37 @@ constexpr int ReportInterval = IUTBITRATE / 8;
|
||||
#if defined(ESP8266)
|
||||
#if defined(HWLOOPBACK) || defined(HWSOURCESWSINK)
|
||||
HardwareSerial& hwSerial(Serial);
|
||||
SoftwareSerial serialIUT;
|
||||
SoftwareSerial logger;
|
||||
EspSoftwareSerial::UART serialIUT;
|
||||
EspSoftwareSerial::UART logger;
|
||||
#elif defined(HWSOURCESINK)
|
||||
HardwareSerial& serialIUT(Serial);
|
||||
SoftwareSerial logger;
|
||||
EspSoftwareSerial::UART logger;
|
||||
#else
|
||||
SoftwareSerial serialIUT;
|
||||
EspSoftwareSerial::UART serialIUT;
|
||||
HardwareSerial& logger(Serial);
|
||||
#endif
|
||||
#elif defined(ESP32)
|
||||
#if defined(HWLOOPBACK) || defined (HWSOURCESWSINK)
|
||||
HardwareSerial& hwSerial(Serial2);
|
||||
SoftwareSerial serialIUT;
|
||||
EspSoftwareSerial::UART serialIUT;
|
||||
#elif defined(HWSOURCESINK)
|
||||
HardwareSerial& serialIUT(Serial2);
|
||||
#else
|
||||
SoftwareSerial serialIUT;
|
||||
EspSoftwareSerial::UART serialIUT;
|
||||
#endif
|
||||
HardwareSerial& logger(Serial);
|
||||
#else
|
||||
SoftwareSerial serialIUT(14, 12);
|
||||
EspSoftwareSerial::UART serialIUT(14, 12);
|
||||
HardwareSerial& logger(Serial);
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
#if defined(HWLOOPBACK) || defined(HWSOURCESINK) || defined(HWSOURCESWSINK)
|
||||
Serial.begin(IUTBITRATE, hwSerialConfig, SERIAL_FULL, 1, invert);
|
||||
Serial.begin(IUTBITRATE, hwSerialConfig, ::SERIAL_FULL, 1, invert);
|
||||
Serial.swap();
|
||||
Serial.setRxBufferSize(2 * BLOCKSIZE);
|
||||
logger.begin(9600, SWSERIAL_8N1, -1, TX);
|
||||
logger.begin(9600, EspSoftwareSerial::SWSERIAL_8N1, -1, TX);
|
||||
#else
|
||||
logger.begin(9600);
|
||||
#endif
|
||||
@@ -132,7 +134,7 @@ void setup() {
|
||||
logger.begin(9600);
|
||||
#endif
|
||||
|
||||
logger.println(PSTR("Loopback example for EspSoftwareSerial"));
|
||||
logger.println(PSTR("Loopback example for EspEspSoftwareSerial"));
|
||||
|
||||
start = micros();
|
||||
txCount = 0;
|
||||
|
||||
@@ -1,17 +1,48 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include "SoftwareSerial.h"
|
||||
|
||||
SoftwareSerial swSer1;
|
||||
SoftwareSerial swSer2;
|
||||
#ifndef D5
|
||||
#if defined(ESP8266)
|
||||
#define D5 (14)
|
||||
#define D6 (12)
|
||||
#elif defined(ESP32)
|
||||
#define D5 (18)
|
||||
#define D6 (19)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
EspSoftwareSerial::UART swSer1;
|
||||
EspSoftwareSerial::UART swSer2;
|
||||
|
||||
void checkSwSerial(EspSoftwareSerial::UART* ss) {
|
||||
byte ch;
|
||||
while (!Serial.available());
|
||||
ss->enableTx(true);
|
||||
while (Serial.available()) {
|
||||
ch = Serial.read();
|
||||
ss->write(ch);
|
||||
}
|
||||
ss->enableTx(false);
|
||||
// wait 1 second for the reply from EspSoftwareSerial if any
|
||||
delay(1000);
|
||||
if (ss->available()) {
|
||||
Serial.print(PSTR("\nResult:"));
|
||||
while (ss->available()) {
|
||||
ch = (byte)ss->read();
|
||||
Serial.print(ch < 0x10 ? PSTR(" 0") : PSTR(" "));
|
||||
Serial.print(ch, HEX);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
delay(2000);
|
||||
Serial.begin(115200);
|
||||
Serial.println(PSTR("\nOne Wire Half Duplex Serial Tester"));
|
||||
swSer1.begin(115200, SWSERIAL_8N1, 12, 12, false, 256);
|
||||
swSer1.begin(115200, EspSoftwareSerial::SWSERIAL_8N1, D6, D6, false, 256);
|
||||
// high speed half duplex, turn off interrupts during tx
|
||||
swSer1.enableIntTx(false);
|
||||
swSer2.begin(115200, SWSERIAL_8N1, 14, 14, false, 256);
|
||||
swSer2.begin(115200, EspSoftwareSerial::SWSERIAL_8N1, D5, D5, false, 256);
|
||||
// high speed half duplex, turn off interrupts during tx
|
||||
swSer2.enableIntTx(false);
|
||||
}
|
||||
@@ -26,25 +57,3 @@ void loop() {
|
||||
checkSwSerial(&swSer2);
|
||||
|
||||
}
|
||||
|
||||
void checkSwSerial(SoftwareSerial* ss) {
|
||||
byte ch;
|
||||
while (!Serial.available());
|
||||
ss->enableTx(true);
|
||||
while (Serial.available()) {
|
||||
ch = Serial.read();
|
||||
ss->write(ch);
|
||||
}
|
||||
ss->enableTx(false);
|
||||
// wait 1 second for the reply from SOftwareSerial if any
|
||||
delay(1000);
|
||||
if (ss->available()) {
|
||||
Serial.print(PSTR("\nResult:"));
|
||||
while (ss->available()) {
|
||||
ch = (byte)ss->read();
|
||||
Serial.print(ch < 0x10 ? PSTR(" 0") : PSTR(" "));
|
||||
Serial.print(ch, HEX);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// On ESP8266:
|
||||
// SoftwareSerial loopback for remote source (loopback.ino), or hardware loopback.
|
||||
// EspSoftwareSerial loopback for remote source (loopback.ino), or hardware loopback.
|
||||
// Connect source D5 (rx) to local D8 (tx), source D6 (tx) to local D7 (rx).
|
||||
// Hint: The logger is run at 9600bps such that enableIntTx(true) can remain unchanged. Blocking
|
||||
// interrupts severely impacts the ability of the SoftwareSerial devices to operate concurrently
|
||||
// interrupts severely impacts the ability of the EspSoftwareSerial devices to operate concurrently
|
||||
// and/or in duplex mode.
|
||||
// On ESP32:
|
||||
// For software or hardware loopback, connect source rx to local D8 (tx), source tx to local D7 (rx).
|
||||
|
||||
#ifndef D5
|
||||
#if defined(ESP8266)
|
||||
#define D5 (14)
|
||||
#define D6 (12)
|
||||
#define D7 (13)
|
||||
#define D8 (15)
|
||||
#define D5 (14)
|
||||
#define D7 (13)
|
||||
#define D6 (12)
|
||||
#define RX (3)
|
||||
#define TX (1)
|
||||
#elif defined(ESP32)
|
||||
#define D5 (18)
|
||||
#define D6 (19)
|
||||
#define D7 (23)
|
||||
#define D8 (5)
|
||||
#define D5 (18)
|
||||
#define D7 (23)
|
||||
#define D6 (19)
|
||||
#define RX (3)
|
||||
#define TX (1)
|
||||
#endif
|
||||
#endif
|
||||
@@ -35,11 +37,11 @@ constexpr int IUTBITRATE = 19200;
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
constexpr SoftwareSerialConfig swSerialConfig = SWSERIAL_8E1;
|
||||
constexpr SerialConfig hwSerialConfig = SERIAL_8E1;
|
||||
constexpr EspSoftwareSerial::Config swSerialConfig = EspSoftwareSerial::SWSERIAL_8E1;
|
||||
constexpr SerialConfig hwSerialConfig = ::SERIAL_8E1;
|
||||
#elif defined(ESP32)
|
||||
constexpr SoftwareSerialConfig swSerialConfig = SWSERIAL_8E1;
|
||||
constexpr uint32_t hwSerialConfig = SERIAL_8E1;
|
||||
constexpr EspSoftwareSerial::Config swSerialConfig = EspSoftwareSerial::SWSERIAL_8E1;
|
||||
constexpr uint32_t hwSerialConfig = ::SERIAL_8E1;
|
||||
#else
|
||||
constexpr unsigned swSerialConfig = 3;
|
||||
#endif
|
||||
@@ -58,30 +60,30 @@ constexpr int ReportInterval = IUTBITRATE / 8;
|
||||
#if defined(ESP8266)
|
||||
#if defined(HWLOOPBACK)
|
||||
HardwareSerial& repeater(Serial);
|
||||
SoftwareSerial logger;
|
||||
EspSoftwareSerial::UART logger;
|
||||
#else
|
||||
SoftwareSerial repeater;
|
||||
EspSoftwareSerial::UART repeater;
|
||||
HardwareSerial& logger(Serial);
|
||||
#endif
|
||||
#elif defined(ESP32)
|
||||
#if defined(HWLOOPBACK)
|
||||
HardwareSerial& repeater(Serial2);
|
||||
#else
|
||||
SoftwareSerial repeater;
|
||||
EspSoftwareSerial::UART repeater;
|
||||
#endif
|
||||
HardwareSerial& logger(Serial);
|
||||
#else
|
||||
SoftwareSerial repeater(14, 12);
|
||||
EspSoftwareSerial::UART repeater(14, 12);
|
||||
HardwareSerial& logger(Serial);
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
#if defined(ESP8266)
|
||||
#if defined(HWLOOPBACK)
|
||||
repeater.begin(IUTBITRATE, hwSerialConfig, SERIAL_FULL, 1, invert);
|
||||
repeater.begin(IUTBITRATE, hwSerialConfig, ::SERIAL_FULL, 1, invert);
|
||||
repeater.swap();
|
||||
repeater.setRxBufferSize(2 * BLOCKSIZE);
|
||||
logger.begin(9600, SWSERIAL_8N1, -1, TX);
|
||||
logger.begin(9600, EspSoftwareSerial::SWSERIAL_8N1, -1, TX);
|
||||
#else
|
||||
repeater.begin(IUTBITRATE, swSerialConfig, D7, D8, invert, 4 * BLOCKSIZE);
|
||||
#ifdef HALFDUPLEX
|
||||
@@ -105,7 +107,7 @@ void setup() {
|
||||
logger.begin(9600);
|
||||
#endif
|
||||
|
||||
logger.println(PSTR("Repeater example for EspSoftwareSerial"));
|
||||
logger.println(PSTR("Repeater example for EspEspSoftwareSerial"));
|
||||
start = micros();
|
||||
rxCount = 0;
|
||||
seqErrors = 0;
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
// On ESP8266:
|
||||
// At 80MHz runs up 57600ps, and at 160MHz CPU frequency up to 115200bps with only negligible errors.
|
||||
// Connect pin 12 to 14.
|
||||
// At 80MHz runs up 57600bps, and at 160MHz CPU frequency up to 115200bps with only negligible errors.
|
||||
// Connect pin 13 to 15.
|
||||
// For verification and as a example for how to use SW serial on the USB to PC connection,
|
||||
// which allows the use of HW Serial on GPIO13 and GPIO15 instead, #define SWAPSERIAL below.
|
||||
// Notice how the bitrates are also swapped then between RX/TX and GPIO13/GPIO15.
|
||||
// Builtin debug output etc. must be stopped on HW Serial in this case, as it would interfere with the
|
||||
// external communication on GPIO13/GPIO15.
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#ifndef D5
|
||||
#if defined(ESP8266)
|
||||
#define D5 (14)
|
||||
#define D6 (12)
|
||||
#define D7 (13)
|
||||
#define D8 (15)
|
||||
#define D5 (14)
|
||||
#define D7 (13)
|
||||
#define D6 (12)
|
||||
#define RX (3)
|
||||
#define TX (1)
|
||||
#elif defined(ESP32)
|
||||
#define D5 (18)
|
||||
#define D6 (19)
|
||||
#define D7 (23)
|
||||
#define D8 (5)
|
||||
#define D5 (18)
|
||||
#define D7 (23)
|
||||
#define D6 (19)
|
||||
#define RX (3)
|
||||
#define TX (1)
|
||||
#endif
|
||||
#endif
|
||||
@@ -26,33 +33,47 @@
|
||||
#define BAUD_RATE 57600
|
||||
#endif
|
||||
|
||||
SoftwareSerial swSer;
|
||||
#undef SWAPSERIAL
|
||||
|
||||
#ifndef SWAPSERIAL
|
||||
auto& usbSerial = Serial;
|
||||
EspSoftwareSerial::UART testSerial;
|
||||
#else
|
||||
EspSoftwareSerial::UART usbSerial;
|
||||
auto& testSerial = Serial;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// Important: the buffer size optimizations here, in particular the isrBufSize (11) that is only sufficiently
|
||||
// large to hold a single 8N1 word, are on the basis that any char written to the loopback SoftwareSerial
|
||||
// adapter gets read before another write is performed.
|
||||
// Block writes with a size greater than 1 would usually fail. Do not copy this into your own project without
|
||||
// reading the documentation.
|
||||
swSer.begin(BAUD_RATE, SWSERIAL_8N1, D5, D6, false, 95, 11);
|
||||
#ifndef SWAPSERIAL
|
||||
usbSerial.begin(115200);
|
||||
// Important: the buffer size optimizations here, in particular the isrBufSize (11) that is only sufficiently
|
||||
// large to hold a single word (up to start - 8 data - parity - stop), are on the basis that any char written
|
||||
// to the loopback EspSoftwareSerial adapter gets read before another write is performed.
|
||||
// Block writes with a size greater than 1 would usually fail. Do not copy this into your own project without
|
||||
// reading the documentation.
|
||||
testSerial.begin(BAUD_RATE, EspSoftwareSerial::SWSERIAL_8N1, D7, D8, false, 95, 11);
|
||||
#else
|
||||
testSerial.begin(115200);
|
||||
testSerial.setDebugOutput(false);
|
||||
testSerial.swap();
|
||||
usbSerial.begin(BAUD_RATE, EspSoftwareSerial::SWSERIAL_8N1, RX, TX, false, 95);
|
||||
#endif
|
||||
|
||||
Serial.println(PSTR("\nSoftware serial test started"));
|
||||
usbSerial.println(PSTR("\nSoftware serial test started"));
|
||||
|
||||
for (char ch = ' '; ch <= 'z'; ch++) {
|
||||
swSer.write(ch);
|
||||
}
|
||||
swSer.println();
|
||||
for (char ch = ' '; ch <= 'z'; ch++) {
|
||||
testSerial.write(ch);
|
||||
}
|
||||
testSerial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (swSer.available() > 0) {
|
||||
Serial.write(swSer.read());
|
||||
yield();
|
||||
}
|
||||
while (Serial.available() > 0) {
|
||||
swSer.write(Serial.read());
|
||||
yield();
|
||||
}
|
||||
|
||||
while (testSerial.available() > 0) {
|
||||
usbSerial.write(testSerial.read());
|
||||
yield();
|
||||
}
|
||||
while (usbSerial.available() > 0) {
|
||||
testSerial.write(usbSerial.read());
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user