From f953240277e5fd8559d69fab1ae99271efacd3e0 Mon Sep 17 00:00:00 2001 From: Vishnu Mohanan Date: Sun, 30 Jun 2024 21:11:50 +0530 Subject: [PATCH] v1.0.13 * Fixed Mega 2560 compatibility issue. --- Changes.md | 7 ++++ README.adoc | 2 +- examples/RS485_Receiver/RS485_Receiver.ino | 8 ++-- examples/RS485_Sender/RS485_Sender.ino | 8 ++-- library.json | 2 +- library.properties | 2 +- src/CSE_RS485.cpp | 4 +- src/CSE_RS485.h | 44 ++++++++++++++++++++-- 8 files changed, 58 insertions(+), 19 deletions(-) diff --git a/Changes.md b/Changes.md index 166f31c..1d7d9af 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,13 @@ Changelog for the `CSE_ArduinoRS485` library. Latest entries are at the top. +# +### **+05:30 08:31:31 PM 30-06-2024, Sunday** + + * Added new platform/board checking preprocessor section to enable the SoftrwareSerial library. Some AVR boards like Mega 2560 have multiple harware serial ports and therefore shouldn't be using the SoftwareSerial library. The new changes fix this issue. + * The examples are compiling for Uno, Mega 2560 and ESP32 DevKit. + * New Revision `v1.0.13`. + # ### **+05:30 12:34:00 AM 21-05-2024, Tuesday** diff --git a/README.adoc b/README.adoc index ddf7e75..f06a312 100644 --- a/README.adoc +++ b/README.adoc @@ -1,6 +1,6 @@ :repository-owner: CIRCUITSTATE :repository-name: CSE_ArduinoRS485 -:repository-version: 1.0.12 +:repository-version: 1.0.13 image::https://socialify.git.ci/CIRCUITSTATE/CSE_ArduinoRS485/image?description=1&font=KoHo&forks=1&issues=1&logo=https%3A%2F%2Fwww.circuitstate.com%2Fwp-content%2Fuploads%2F2024%2F05%2FCIRCUITSTATE-R-Emblem-20052024-2.svg&name=1&pattern=Circuit%20Board&pulls=1&stargazers=1&theme=Auto[CSE_ArduinoRS485] diff --git a/examples/RS485_Receiver/RS485_Receiver.ino b/examples/RS485_Receiver/RS485_Receiver.ino index 934c66c..50dad9d 100644 --- a/examples/RS485_Receiver/RS485_Receiver.ino +++ b/examples/RS485_Receiver/RS485_Receiver.ino @@ -11,12 +11,10 @@ #include -// Declare the RS485 interface here with a hardware serial port. -// RS485Class RS485 (Serial1, 2, 3, 4); // DE, RE, TX +// If you want to use a software serial port, uncomment the following line. +// SoftwareSerial Serial1 (10, 11); // RX, TX -// If you want to use a software serial port, declare it here, -// comment out the previous declaration, and uncomment this section. -SoftwareSerial Serial1 (10, 11); // RX, TX +// For using Hardware serial ports, the following line is enough. RS485Class RS485 (Serial1, 2, 3, 4); // DE, RE, TX void setup() { diff --git a/examples/RS485_Sender/RS485_Sender.ino b/examples/RS485_Sender/RS485_Sender.ino index 3be1953..64d8dac 100644 --- a/examples/RS485_Sender/RS485_Sender.ino +++ b/examples/RS485_Sender/RS485_Sender.ino @@ -13,12 +13,10 @@ int counter = 0; -// Declare the RS485 interface here with a hardware serial port. -// RS485Class RS485 (Serial1, 2, 3, 4); // DE, RE, TX - -// If you want to use a software serial port, declare it here, -// comment out the previous declaration, and uncomment this section. +// If you want to use a software serial port, uncomment the following line. SoftwareSerial Serial1 (10, 11); // RX, TX + +// For using Hardware serial ports, the following line is enough. RS485Class RS485 (Serial1, 2, 3, 4); // DE, RE, TX void setup() { diff --git a/library.json b/library.json index 03594bf..5ffef52 100644 --- a/library.json +++ b/library.json @@ -13,7 +13,7 @@ "url": "https://github.com/CIRCUITSTATE", "maintainer": true }, - "version": "1.0.12", + "version": "1.0.13", "license": "LGPL-2.1", "frameworks": "arduino", "platforms": "*" diff --git a/library.properties b/library.properties index 1ff7273..954d6e6 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=CSE_ArduinoRS485 -version=1.0.12 +version=1.0.13 author=CIRCUITSTATE maintainer=CIRCUITSTATE <@circuitstate> sentence=Allows sending and receiving data through the RS-485 interface, using any Arduino-compatible boards. diff --git a/src/CSE_RS485.cpp b/src/CSE_RS485.cpp index c4ebe87..95e0db0 100644 --- a/src/CSE_RS485.cpp +++ b/src/CSE_RS485.cpp @@ -20,8 +20,8 @@ */ //===================================================================================// -// Version: 1.0.12 -// Last modified: +05:30 15:08:03 PM 28-01-2024, Sunday +// Version: 1.0.13 +// Last modified: +05:30 21:11:24 PM 30-06-2024, Sunday // Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485 //===================================================================================// diff --git a/src/CSE_RS485.h b/src/CSE_RS485.h index 78274f3..a5426fa 100644 --- a/src/CSE_RS485.h +++ b/src/CSE_RS485.h @@ -20,8 +20,8 @@ */ //===================================================================================// -// Version: 1.0.12 -// Last modified: +05:30 15:03:34 PM 28-01-2024, Sunday +// Version: 1.0.13 +// Last modified: +05:30 21:11:21 PM 30-06-2024, Sunday // Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485 //===================================================================================// @@ -41,10 +41,46 @@ // You can expand the software serial support here. // SoftwareSerial is required by boards like Arduino Uno and Nano which don't have a // dedicated secondary hardware serial port. -#define SOFTWARE_SERIAL_REQUIRED defined(__AVR__) || defined(ARDUINO_ARCH_AVR) || defined(ESP8266) +// #define SOFTWARE_SERIAL_REQUIRED defined(__AVR__) || defined(ARDUINO_ARCH_AVR) || defined(ESP8266) + +// #if !defined(HAVE_HWSERIAL1) && !defined(HAVE_HWSERIAL2) && !defined(HAVE_HWSERIAL3) && !defined(HAVE_HWSERIAL4) +// #define SOFTWARE_SERIAL_REQUIRED 1 +// #endif + +// // Check if the user has defined the macro to control SoftwareSerial inclusion +// #ifdef DISABLE_SOFTWARE_SERIAL +// #define SOFTWARE_SERIAL_REQUIRED 0 +// #else +// #define SOFTWARE_SERIAL_REQUIRED 1 +// #endif + +// Define default values +#define _HAVE_HWSERIAL1 + +// Check for specific architectures and boards +#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) + // Arduino Uno and Nano have only one hardware serial port + #define _HAVE_HWSERIAL1 +#elif defined(ARDUINO_AVR_MEGA2560) + // Arduino Mega has four hardware serial ports + #define _HAVE_HWSERIAL1 + #define _HAVE_HWSERIAL2 + #define _HAVE_HWSERIAL3 + #define _HAVE_HWSERIAL4 +#elif defined(ARDUINO_ARCH_ESP32) + // ESP32 typically has three hardware serial ports + #define _HAVE_HWSERIAL1 + #define _HAVE_HWSERIAL2 + #define _HAVE_HWSERIAL3 +#endif + +// Define a flag to include SoftwareSerial if no additional UARTs are available +#if !defined(_HAVE_HWSERIAL2) && !defined(_HAVE_HWSERIAL3) && !defined(_HAVE_HWSERIAL4) + #define SOFTWARE_SERIAL_REQUIRED 1 +#endif // The SoftwareSerial is loaded automatically when required. -#if SOFTWARE_SERIAL_REQUIRED +#ifdef SOFTWARE_SERIAL_REQUIRED #include #endif