From 255f0108322acfc8e2608ad9a15e0bceaa2bb3aa Mon Sep 17 00:00:00 2001 From: mostafa hk Date: Mon, 30 Aug 2021 12:35:38 +0430 Subject: [PATCH 1/8] ESP8266 ESP32 compatible --- README.adoc | 1 + src/RS485.cpp | 4 ++-- src/RS485.h | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.adoc b/README.adoc index b1be50e..ee19f70 100644 --- a/README.adoc +++ b/README.adoc @@ -8,6 +8,7 @@ image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/ image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield. +I've Made this compatible with ESP8266 and ESP32. This library supports the Maxim Integrated MAX3157 and equivalent chipsets. diff --git a/src/RS485.cpp b/src/RS485.cpp index ba6e80f..c492723 100644 --- a/src/RS485.cpp +++ b/src/RS485.cpp @@ -38,12 +38,12 @@ void RS485Class::begin(unsigned long baudrate, int predelay, int postdelay) begin(baudrate, SERIAL_8N1, predelay, postdelay); } -void RS485Class::begin(unsigned long baudrate, uint16_t config) +void RS485Class::begin(unsigned long baudrate, RS485_SER_CONF_TYPE config) { begin(baudrate, config, RS485_DEFAULT_PRE_DELAY, RS485_DEFAULT_POST_DELAY); } -void RS485Class::begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay) +void RS485Class::begin(unsigned long baudrate, RS485_SER_CONF_TYPE config, int predelay, int postdelay) { _baudrate = baudrate; _config = config; diff --git a/src/RS485.h b/src/RS485.h index 050b253..054730d 100644 --- a/src/RS485.h +++ b/src/RS485.h @@ -31,11 +31,22 @@ #ifdef __AVR__ #define RS485_DEFAULT_DE_PIN 2 #define RS485_DEFAULT_RE_PIN -1 +#elif defined(ESP32) || defined(ESP8266) +#define RS485_DEFAULT_DE_PIN 0 +#define RS485_DEFAULT_RE_PIN 0 #else #define RS485_DEFAULT_DE_PIN A6 #define RS485_DEFAULT_RE_PIN A5 #endif +#if defined(ESP8266) +#define RS485_SER_CONF_TYPE SerialConfig +#elif defined(ESP32) +#define RS485_SER_CONF_TYPE uint32_t +#else +#define RS485_SER_CONF_TYPE uint16_t +#endif + #define RS485_DEFAULT_PRE_DELAY 50 #define RS485_DEFAULT_POST_DELAY 50 @@ -45,9 +56,9 @@ class RS485Class : public Stream { RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin); virtual void begin(unsigned long baudrate); - virtual void begin(unsigned long baudrate, uint16_t config); + virtual void begin(unsigned long baudrate, RS485_SER_CONF_TYPE config); virtual void begin(unsigned long baudrate, int predelay, int postdelay); - virtual void begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay); + virtual void begin(unsigned long baudrate, RS485_SER_CONF_TYPE config, int predelay, int postdelay); virtual void end(); virtual int available(); virtual int peek(); From b23375d37efff5a9fe5bc1953cb44545a3a5011c Mon Sep 17 00:00:00 2001 From: mostafa hk Date: Mon, 30 Aug 2021 14:50:48 +0430 Subject: [PATCH 2/8] v1.0.3 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index ffd6dfe..55c4a06 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoRS485 -version=1.0.2 +version=1.0.3 author=Arduino maintainer=Arduino sentence=Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield. From 3ea0bb810232e1a0dc4f1284a4a368fb0a33296c Mon Sep 17 00:00:00 2001 From: mostafa hk Date: Mon, 30 Aug 2021 15:20:12 +0430 Subject: [PATCH 3/8] version 1.0.4 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 55c4a06..2883b58 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoRS485 -version=1.0.3 +version=1.0.4 author=Arduino maintainer=Arduino sentence=Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield. From 9114fa42ec11ea06769a532c4008974d7783de5d Mon Sep 17 00:00:00 2001 From: mostafa hk Date: Mon, 30 Aug 2021 15:29:04 +0430 Subject: [PATCH 4/8] bug fix --- src/RS485.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RS485.h b/src/RS485.h index 054730d..16c1908 100644 --- a/src/RS485.h +++ b/src/RS485.h @@ -90,7 +90,7 @@ class RS485Class : public Stream { bool _transmisionBegun; unsigned long _baudrate; - uint16_t _config; + RS485_SER_CONF_TYPE _config; }; extern RS485Class RS485; From e056966d7cd2fc375e530967b8f11a9f8a20d56a Mon Sep 17 00:00:00 2001 From: mostafa hk Date: Wed, 13 Oct 2021 17:52:00 +0330 Subject: [PATCH 5/8] esp32/8266 compatible fix --- library.properties | 2 +- src/RS485.h | 29 +---------------------------- src/RS485_defs.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 src/RS485_defs.h diff --git a/library.properties b/library.properties index 2883b58..5fbf24d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoRS485 -version=1.0.4 +version=1.0.5 author=Arduino maintainer=Arduino sentence=Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield. diff --git a/src/RS485.h b/src/RS485.h index 16c1908..aa760d7 100644 --- a/src/RS485.h +++ b/src/RS485.h @@ -21,35 +21,8 @@ #define _RS485_H_INCLUDED #include +#include "RS485_defs.h" -#ifdef PIN_SERIAL1_TX -#define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX -#else -#define RS485_DEFAULT_TX_PIN 1 -#endif - -#ifdef __AVR__ -#define RS485_DEFAULT_DE_PIN 2 -#define RS485_DEFAULT_RE_PIN -1 -#elif defined(ESP32) || defined(ESP8266) -#define RS485_DEFAULT_DE_PIN 0 -#define RS485_DEFAULT_RE_PIN 0 -#else -#define RS485_DEFAULT_DE_PIN A6 -#define RS485_DEFAULT_RE_PIN A5 -#endif - -#if defined(ESP8266) -#define RS485_SER_CONF_TYPE SerialConfig -#elif defined(ESP32) -#define RS485_SER_CONF_TYPE uint32_t -#else -#define RS485_SER_CONF_TYPE uint16_t -#endif - - -#define RS485_DEFAULT_PRE_DELAY 50 -#define RS485_DEFAULT_POST_DELAY 50 class RS485Class : public Stream { public: diff --git a/src/RS485_defs.h b/src/RS485_defs.h new file mode 100644 index 0000000..aef77b6 --- /dev/null +++ b/src/RS485_defs.h @@ -0,0 +1,33 @@ +#ifndef _ARDUINO_RS485_DEFS_H_INCLUDED +#define _ARDUINO_RS485_DEFS_H_INCLUDED + +#ifdef PIN_SERIAL1_TX +#define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX +#else +#define RS485_DEFAULT_TX_PIN 1 +#endif + +#ifdef __AVR__ +#define RS485_DEFAULT_DE_PIN 2 +#define RS485_DEFAULT_RE_PIN -1 +#elif defined(ESP32) || defined(ESP8266) +#define RS485_DEFAULT_DE_PIN 0 +#define RS485_DEFAULT_RE_PIN 0 +#else +#define RS485_DEFAULT_DE_PIN A6 +#define RS485_DEFAULT_RE_PIN A5 +#endif + +#if defined(ESP8266) +#define RS485_SER_CONF_TYPE SerialConfig +#elif defined(ESP32) +#define RS485_SER_CONF_TYPE uint32_t +#else +#define RS485_SER_CONF_TYPE uint16_t +#endif + + +#define RS485_DEFAULT_PRE_DELAY 50 +#define RS485_DEFAULT_POST_DELAY 50 + +#endif From c2a9f37ffa0e3f1711af43a1c33c7a055df4610a Mon Sep 17 00:00:00 2001 From: mostafa hk Date: Mon, 22 Nov 2021 14:32:14 +0330 Subject: [PATCH 6/8] ESP32 Serial2 Fix --- library.properties | 2 +- src/RS485.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 5fbf24d..23b88ee 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoRS485 -version=1.0.5 +version=1.0.6 author=Arduino maintainer=Arduino sentence=Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield. diff --git a/src/RS485.cpp b/src/RS485.cpp index c492723..eb2ec29 100644 --- a/src/RS485.cpp +++ b/src/RS485.cpp @@ -137,6 +137,11 @@ void RS485Class::endTransmission() } _transmisionBegun = false; +#ifdef ESP32 + // there is a bug in ESP32 for Serial2 + while(_serial->available()) + _serial->read(); +#endif } void RS485Class::receive() From 4af2c4287cfad5f2cdc8d98c048213025fd6485b Mon Sep 17 00:00:00 2001 From: mostafahk <30733372+mostafahk@users.noreply.github.com> Date: Mon, 3 Jan 2022 17:34:00 +0330 Subject: [PATCH 7/8] re,de pins bug fix --- src/RS485_defs.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/RS485_defs.h b/src/RS485_defs.h index aef77b6..6d585b6 100644 --- a/src/RS485_defs.h +++ b/src/RS485_defs.h @@ -1,18 +1,24 @@ #ifndef _ARDUINO_RS485_DEFS_H_INCLUDED #define _ARDUINO_RS485_DEFS_H_INCLUDED +#ifndef RS485_DEFAULT_TX_PIN #ifdef PIN_SERIAL1_TX #define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX #else -#define RS485_DEFAULT_TX_PIN 1 +#define RS485_DEFAULT_TX_PIN 1 +#endif #endif #ifdef __AVR__ #define RS485_DEFAULT_DE_PIN 2 #define RS485_DEFAULT_RE_PIN -1 #elif defined(ESP32) || defined(ESP8266) +#ifndef RS485_DEFAULT_DE_PIN #define RS485_DEFAULT_DE_PIN 0 +#endif +#ifndef RS485_DEFAULT_RE_PIN #define RS485_DEFAULT_RE_PIN 0 +#endif #else #define RS485_DEFAULT_DE_PIN A6 #define RS485_DEFAULT_RE_PIN A5 @@ -26,7 +32,6 @@ #define RS485_SER_CONF_TYPE uint16_t #endif - #define RS485_DEFAULT_PRE_DELAY 50 #define RS485_DEFAULT_POST_DELAY 50 From 43b5ea3ccd53e020ea7a5780ab12c43447177639 Mon Sep 17 00:00:00 2001 From: mostafahk <30733372+mostafahk@users.noreply.github.com> Date: Mon, 3 Jan 2022 17:34:37 +0330 Subject: [PATCH 8/8] version inc --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 23b88ee..673aec3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoRS485 -version=1.0.6 +version=1.0.61 author=Arduino maintainer=Arduino sentence=Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield.