From aa8f6512a5b79f0273b55b1314a027b7d5eb7ed6 Mon Sep 17 00:00:00 2001 From: Vishnu Mohanan Date: Tue, 25 Jul 2023 20:30:52 +0530 Subject: [PATCH] v1.0.7 * Updated documentation. --- .gitignore | 1 + README.adoc | 5 + docs/api.md | 143 ++++++------------ library.json | 2 +- library.properties | 2 +- ...7e-FB9F1F6D63ED817E!565346-a7e027.insyncdl | 0 ...7e-FB9F1F6D63ED817E!565350-3de3fc.insyncdl | 0 src/CSE_RS485.cpp | 4 +- src/CSE_RS485.h | 4 +- 9 files changed, 58 insertions(+), 103 deletions(-) create mode 100644 .gitignore delete mode 100644 src/.~fb9f1f6d63ed817e-FB9F1F6D63ED817E!565346-a7e027.insyncdl delete mode 100644 src/.~fb9f1f6d63ed817e-FB9F1F6D63ED817E!565350-3de3fc.insyncdl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fadbca0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.~*.insyncdl diff --git a/README.adoc b/README.adoc index dfab8f2..e9e3ee2 100644 --- a/README.adoc +++ b/README.adoc @@ -1,8 +1,13 @@ :repository-owner: CIRCUITSTATE :repository-name: CSE_ArduinoRS485 +:repository-version: 1.0.7 = {repository-name} Library for Arduino = +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +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"] + This Arduino library allows you to send and receive data using the **RS-485** interface standard. Supported by all Arduino-compatible boards such as ESP32, STM32, RP2040, AVR, SAMD, ESP8266, etc. You can use both hardware and software serial ports. This library supports the Maxim Integrated MAX485 and equivalent chipsets. Three examples are included with this library: diff --git a/docs/api.md b/docs/api.md index f408c29..e1df7a1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -2,14 +2,31 @@ ## Methods -### `begin()` +### `RS485Class()` -Initializes the RS485 object communication speed. +Creates a new CSE_ArduinoRS485 object. If you are using a hardware serial port, you can simply send its name as a parameter. If you are using software serial, you must include the SoftwareSerial library first and create a new object of that type. Then send the name of the object as a parameter. #### Syntax +```cpp +RS485Class RS485 (serial, dePin, rePin, txPin); ``` -RS485.begin(baudrate) + +#### Parameters + +* _serial_: Name of the serial port to use. Can be hardware serial or software serial. +* _dePin_: Drive enable pin. +* _rePin_: Receive enable pin. Optional. Default: -1. +* _txPin_: Serial transmit pin (used to send break signals). Optional. Default: -1. + +### `begin()` + +Initializes the RS485 object communication speed. The baudrate can be left empty to make it 0. This will prevent the serial port from being initialized by the RS485 library. But then you have to manually initialize the serial port before calling any RS485 library function. + +#### Syntax + +```cpp +RS485.begin (baudrate) ``` #### Parameters @@ -38,11 +55,11 @@ None. ### `end()` -Disables RS485 communication. +Disables RS485 communication. This will close the serial port and reset the DE and RE pins to INPUT mode. #### Syntax -``` +```cpp RS485.end() ``` @@ -76,7 +93,7 @@ Get the number of bytes (characters) available for reading from the RS485 port. #### Syntax -``` +```cpp RS485.available() ``` @@ -110,7 +127,7 @@ Returns the next byte (character) of the incoming serial data without removing i #### Syntax -``` +```cpp RS485.peek() ``` @@ -144,7 +161,7 @@ Reads incoming serial data. #### Syntax -``` +```cpp RS485.read() ``` @@ -178,8 +195,8 @@ Writes binary data to the serial port. This data is sent as a byte or series of #### Syntax -``` -RS485.write(uint8_t b) +```cpp +RS485.write (uint8_t b) ``` #### Parameters @@ -212,7 +229,7 @@ Waits for the transmission of outgoing serial data to complete. #### Syntax -``` +```cpp RS485.flush() ``` @@ -242,11 +259,11 @@ None. ### `beginTransmission()` -Enables RS-485 transmission. +Enables RS-485 transmission. This will assert the DE pin and the RE pin is not modified (since DE has priority over RE). #### Syntax -``` +```cpp RS485.beginTransmission() ``` @@ -258,29 +275,6 @@ None. None. -#### Example - -``` -#include - -int counter = 0; - -void setup() { - RS485.begin(9600); -} - -void loop() { - RS485.beginTransmission(); - RS485.print("Counter: "); - RS485.println(counter); - RS485.endTransmission(); - - counter++; - - delay(1000); -} -``` - #### See also * [begin()](#begin) @@ -299,11 +293,11 @@ void loop() { ### `endTransmission()` -Disables RS-485 transmission. +Disables RS-485 transmission. This deasserts the DE pin and the RE pin is not modified (since DE has priority over RE). #### Syntax -``` +```cpp RS485.endTransmission() ``` @@ -315,29 +309,6 @@ None. None. -#### Example - -``` -#include - -int counter = 0; - -void setup() { - RS485.begin(9600); -} - -void loop() { - RS485.beginTransmission(); - RS485.print("Counter: "); - RS485.println(counter); - RS485.endTransmission(); - - counter++; - - delay(1000); -} -``` - #### See also * [begin()](#begin) @@ -356,11 +327,11 @@ void loop() { ### `receive()` -Enables reception. +Enables reception. This asserts the RE pin. The state of the DE pins should be set to LOW before calling this function. #### Syntax -``` +```cpp RS485.receive() ``` @@ -372,28 +343,6 @@ None. None. -#### Example - -``` -#include - -void setup() { - Serial.begin(9600); - while (!Serial); - - RS485.begin(9600); - - // Enable data reception - RS485.receive(); -} - -void loop() { - if (RS485.available()) { - Serial.write(RS485.read()); - } -} -``` - #### See also * [begin()](#begin) @@ -412,11 +361,11 @@ void loop() { ### `noReceive()` -Disables reception. +Disables reception. This deasserts the RE pin. If the DE pin is also deasserted (LOW), then the transceiver enters a high-impedance state. #### Syntax -``` +```cpp RS485.noReceive() ``` @@ -446,12 +395,12 @@ None. ### `sendBreak()` -Sends a serial break signal for the specified duration in milliseconds. +Sends a serial break signal for the specified duration in milliseconds. This function will only work if the TX pin is specified in the constructor. The serial port will be reinitialized only if the baudrate is greater than 0. #### Syntax -``` -RS485.sendBreak(unsigned int duration) +```cpp +RS485.sendBreak (unsigned int duration) ``` #### Parameters @@ -480,12 +429,12 @@ None. ### `sendBreakMicroseconds()` -Sends a serial break signal for the specified duration in microseconds. +Sends a serial break signal for the specified duration in microseconds. This function will only work if the TX pin is specified in the constructor. The serial port will be reinitialized only if the baudrate is greater than 0. #### Syntax -``` -RS485.sendBreak(unsigned int duration) +```cpp +RS485.sendBreak (unsigned int duration) ``` #### Parameters @@ -514,19 +463,19 @@ None. ### `setPins()` -Modify the pins used to communicate with the MAX3157 chipset. By default the library uses pin 14 for TX, pin A6 for drive output enable, and pin A5 for receiver output enable. +Modify the pins used to communicate with the RS-485 transceiver. #### Syntax -``` -RS485.setPins(int txPin, int dePin, int rePin) +```cpp +RS485.setPins (int dePin, int rePin, int txPin) ``` #### Parameters -* _txPin_: transmission pin (used to send break signals). * _dePin_: drive output enable pin. * _rePin_: receiver output enable pin. +* _txPin_: transmission pin (used to send break signals). #### Returns diff --git a/library.json b/library.json index 1e34fb4..b0e5ad0 100644 --- a/library.json +++ b/library.json @@ -13,7 +13,7 @@ "url": "https://github.com/CIRCUITSTATE", "maintainer": true }, - "version": "1.0.6", + "version": "1.0.7", "license": "LGPL-2.1", "frameworks": "arduino", "platforms": "*" diff --git a/library.properties b/library.properties index d00c2bb..bc1a2bc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=CSE_ArduinoRS485 -version=1.0.6 +version=1.0.7 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/.~fb9f1f6d63ed817e-FB9F1F6D63ED817E!565346-a7e027.insyncdl b/src/.~fb9f1f6d63ed817e-FB9F1F6D63ED817E!565346-a7e027.insyncdl deleted file mode 100644 index e69de29..0000000 diff --git a/src/.~fb9f1f6d63ed817e-FB9F1F6D63ED817E!565350-3de3fc.insyncdl b/src/.~fb9f1f6d63ed817e-FB9F1F6D63ED817E!565350-3de3fc.insyncdl deleted file mode 100644 index e69de29..0000000 diff --git a/src/CSE_RS485.cpp b/src/CSE_RS485.cpp index 33b85d8..60b5f75 100644 --- a/src/CSE_RS485.cpp +++ b/src/CSE_RS485.cpp @@ -20,8 +20,8 @@ */ //===================================================================================// -// Version: 1.0.6 -// Last modified: +05:30 19:18:39 PM 25-07-2023, Tuesday +// Version: 1.0.7 +// Last modified: +05:30 20:29:06 PM 25-07-2023, Tuesday // Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485 //===================================================================================// diff --git a/src/CSE_RS485.h b/src/CSE_RS485.h index 8fe6e4c..40bc97d 100644 --- a/src/CSE_RS485.h +++ b/src/CSE_RS485.h @@ -20,8 +20,8 @@ */ //===================================================================================// -// Version: 1.0.6 -// Last modified: +05:30 19:20:17 PM 25-07-2023, Tuesday +// Version: 1.0.7 +// Last modified: +05:30 20:29:01 PM 25-07-2023, Tuesday // Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485 //===================================================================================//