Skip to content

Commit 0e561d1

Browse files
committed
v1.0.10
* Updated library info. * Updated docs.
1 parent 464778f commit 0e561d1

File tree

8 files changed

+85
-63
lines changed

8 files changed

+85
-63
lines changed

.codespellrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.adoc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
:repository-owner: CIRCUITSTATE
22
:repository-name: CSE_ArduinoRS485
3-
:repository-version: 1.0.9
3+
:repository-version: 1.0.10
44

55
= {repository-name} Library for Arduino =
66

7-
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"]
8-
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"]
9-
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"]
10-
11-
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.
7+
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 for communication. This library supports the Maxim Integrated **MAX485** and equivalent transceivers.
128

139
Three examples are included with this library:
1410

15-
* **RS485_Sender** - Sends data to a receiver.
16-
* **RS485_Receiver** - Receives data from a sender.
11+
* **RS485_Sender** - Sends data to a connected receiver.
12+
* **RS485_Receiver** - Receives data from a connected sender.
1713
* **RS485_Passthrough** - Sends and receives data between the RS-485 port and the default serial port.
1814

19-
This library is a fork of the ArduinoRS485 library by Arduino, and is maintained by **CIRCUITSTATE**.
15+
This library is a fork of the **ArduinoRS485** library by Arduino, and is maintained by **CIRCUITSTATE Electronics**.
2016

2117
* https://github.com/arduino-libraries/ArduinoRS485[ArduinoRS485 Library by Arduino]
2218
* https://www.arduino.cc/reference/en/libraries/arduinors485/[ArduinoRS485 documentation by Arduino]
2319
* https://www.circuitstate.com/tutorials/what-is-rs-485-how-to-use-max485-with-arduino-for-reliable-long-distance-serial-communication/[RS-485 tutorial by CIRCUITSTATE]
2420
* https://www.circuitstate.com/pinouts/max485-cd4069-rs-485-module-with-auto-data-direction-control-pinout-diagram-and-pin-reference/[MAX485+CD4069 Module Pinout by CIRCUITSTATE]
21+
* https://www.circuitstate.com/tutorials/what-is-modbus-communication-protocol-and-how-to-implement-modbus-rtu-with-arduino/[Modbus RTU tutorial by CIRCUITSTATE]
2522

docs/api.md

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,73 @@
1-
# Arduino RS485 library
1+
# CSE_ArduinoRS485 library
22

33
## Methods
44

5+
### Index
6+
7+
* [begin()](#begin)
8+
* [end()](#end)
9+
* [available()](#available)
10+
* [peek()](#peek)
11+
* [read()](#read)
12+
* [write()](#write)
13+
* [flush()](#flush)
14+
* [beginTransmission()](#begintransmission)
15+
* [endTransmission()](#endtransmission)
16+
* [receive()](#receive)
17+
* [noReceive()](#noreceive)
18+
* [sendBreak()](#sendbreak)
19+
* [sendBreakMicroseconds()](#sendbreakmicroseconds)
20+
* [setPins()](#setpins)
21+
* [setdelays()](#setdelays)
22+
523
### `RS485Class()`
624

7-
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.
25+
Creates a new `RS485Class` 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.
826

27+
Currently, software serial is supported only on AVR (Arduino Uno, Nano, etc.) and ESP8266 boards. The macro `SOFTWARE_SERIAL_REQUIRED` is used to check if a software serial port to be used. You can update the board support by adding the board name to the macro in the `CSE_RS485.h` file.
928
#### Syntax
1029

1130
```cpp
12-
RS485Class RS485 (serial, dePin, rePin, txPin);
31+
RS485Class RS485 (auto serial, int dePin, int rePin, int txPin);
1332
```
1433
1534
#### Parameters
1635
17-
* _serial_: Name of the serial port to use. Can be hardware serial or software serial.
36+
* _serial_: Name of the serial port to use. Can be hardware serial (`HardwareSerial`) or software serial (`SoftwareSerial`).
1837
* _dePin_: Drive enable pin.
1938
* _rePin_: Receive enable pin. Optional. Default: -1.
2039
* _txPin_: Serial transmit pin (used to send break signals). Optional. Default: -1.
2140
2241
### `begin()`
2342
24-
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.
43+
Initializes the RS485 object. The baudrate can be left empty to make it 0. This will prevent the serial port from being initialized by the RS485 library. You have to then manually initialize the serial port before calling any RS485 library function. If the baudrate is non-zero, the user can also specify the UART configuration, for example `SERIAL_8N1`. It is also possible to set pre and post delays in milliseconds for each communication.
2544
2645
#### Syntax
2746
47+
There are 5 overloads of this function:
48+
2849
```cpp
50+
RS485.begin()
2951
RS485.begin (baudrate)
52+
RS485.begin (unsigned long baudrate, uint16_t config)
53+
RS485.begin (unsigned long baudrate, int predelay, int postdelay)
54+
RS485.begin (unsigned long baudrate, uint16_t config, int predelay, int postdelay)
3055
```
3156

3257
#### Parameters
3358

34-
* _baudrate_: communication speed in bits per second (baud).
59+
* _baudrate_: Communication speed in bits per second (baud). Optional. Default: 0. If 0, the serial port will not be initialized.
60+
* _config_: Serial port configuration. Example, `SERIAL_8N1`.
61+
* _predelay_: Delay in milliseconds before sending data. Optional. Default: 0.
62+
* _postdelay_: Delay in milliseconds after sending data. Optional. Default: 0.
3563

3664
#### Returns
3765

3866
None.
3967

40-
#### See also
41-
42-
* [end()](#end)
43-
* [available()](#available)
44-
* [peek()](#peek)
45-
* [read()](#read)
46-
* [write()](#write)
47-
* [flush()](#flush)
48-
* [beginTransmission()](#begintransmission)
49-
* [endTransmission()](#endtransmission)
50-
* [receive()](#receive)
51-
* [noReceive()](#noreceive)
52-
* [sendBreak()](#sendbreak)
53-
* [sendBreakMicroseconds()](#sendbreakmicroseconds)
54-
* [setPins()](#setpins)
55-
5668
### `end()`
5769

58-
Disables RS485 communication. This will close the serial port and reset the DE and RE pins to INPUT mode.
70+
Disables RS485 communication. This will close the serial port and reset the DE and RE pins to INPUT mode. The serial port will be closed regardless of whether it was initialized by the RS485 library or not.
5971

6072
#### Syntax
6173

@@ -73,7 +85,7 @@ None.
7385

7486
### `available()`
7587

76-
Get the number of bytes (characters) available for reading from the RS485 port. This is data that already arrived and is stored in the serial receive buffer.
88+
Returns the number of bytes (characters) available for reading from the RS485 port. This is data that already arrived and is stored in the serial receive buffer.
7789

7890
#### Syntax
7991

@@ -87,11 +99,11 @@ None.
8799

88100
#### Returns
89101

90-
The number of bytes available to read.
102+
* _int_: The number of bytes available to read.
91103

92104
### `peek()`
93105

94-
Returns the next byte (character) of the incoming serial data without removing it from the internal serial buffer. That is, successive calls to peek() will return the same character, as will the next call to read().
106+
Returns the next byte (character) of the incoming serial data without removing it from the internal serial buffer. That is, successive calls to `peek()` will return the same character, as will the next call to `read()`. The original Arduino serial `peek()` function returns an `int` type. So this library also does the same.
95107

96108
#### Syntax
97109

@@ -105,11 +117,11 @@ None.
105117

106118
#### Returns
107119

108-
The first byte of incoming serial data available or -1 if no data is available.
120+
* _int_: The first byte of incoming serial data available or -1 if no data is available.
109121

110122
### `read()`
111123

112-
Reads incoming serial data.
124+
Returns a single byte from the serial read buffer. Return -1 if no data is available. Each read operation will remove the byte from the buffer.
113125

114126
#### Syntax
115127

@@ -123,7 +135,7 @@ None.
123135

124136
#### Returns
125137

126-
The first byte of incoming serial data available or -1 if no data is available.
138+
* _int_: The first byte of incoming serial data available or -1 if no data is available.
127139

128140
### `write()`
129141

@@ -141,7 +153,7 @@ RS485.write (uint8_t b)
141153

142154
#### Returns
143155

144-
The number of bytes written.
156+
* _size_t_: The number of bytes written.
145157

146158
### `flush()`
147159

@@ -163,7 +175,9 @@ None.
163175

164176
### `beginTransmission()`
165177

166-
Enables RS-485 transmission. This will assert the DE pin and the RE pin is not modified (since DE has priority over RE).
178+
Starts RS-485 transmission. This will assert the DE pin and wait for a pre-delay if it is set. The DE pin has priority over the RE pin. That means, if both DE and RE are actively asserted, the transceiver will be in transmission mode.
179+
180+
You must call this function before any write operations.
167181

168182
#### Syntax
169183

@@ -181,7 +195,7 @@ None.
181195

182196
### `endTransmission()`
183197

184-
Disables RS-485 transmission. This deasserts the DE pin and the RE pin is not modified (since DE has priority over RE).
198+
Ends the RS-485 transmission. This deasserts the DE pin and the RE pin is not modified (since DE has priority over RE). If the post-delay is non-zero, the function wait for the specified duration before deasserting the DE pin.
185199

186200
#### Syntax
187201

@@ -199,7 +213,7 @@ None.
199213

200214
### `receive()`
201215

202-
Enables reception. This asserts the RE pin. The state of the DE pins should be set to LOW before calling this function.
216+
Puts the transceiver in receive mode by asserting the RE pin. If the DE pin is currently being asserted, this has no effect, because DE has precedence over RE. Call the `endTransmission()` function to deassert the DE pin to free the bus.
203217

204218
#### Syntax
205219

@@ -217,7 +231,7 @@ None.
217231

218232
### `noReceive()`
219233

220-
Disables reception. This deasserts the RE pin. If the DE pin is also deasserted (LOW), then the transceiver enters a high-impedance state.
234+
Puts the transceiver in a no receive mode by deasserting the RE pin. If the DE pin is also deasserted, then the transceiver is in a high impedance state.
221235

222236
#### Syntax
223237

@@ -235,7 +249,7 @@ None.
235249

236250
### `sendBreak()`
237251

238-
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.
252+
Sends a serial break signal for the specified duration in milliseconds. This is done by closing the serial port, holding the TX pin of the serial port LOW for a specified duration in milliseconds, and then reinitializing the serial port. If the TX pins is not set, this function has no effect. The serial port will be reinitialized only if the baudrate is greater than 0. If the baudrate is 0, then you have to manually initialize the serial port in your main code, just after calling this function.
239253

240254
#### Syntax
241255

@@ -253,7 +267,7 @@ None.
253267

254268
### `sendBreakMicroseconds()`
255269

256-
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.
270+
Same as `sendBreak()` but the duration is specified in microseconds.
257271

258272
#### Syntax
259273

@@ -281,9 +295,27 @@ RS485.setPins (int dePin, int rePin, int txPin)
281295

282296
#### Parameters
283297

284-
* _dePin_: drive output enable pin.
285-
* _rePin_: receiver output enable pin.
286-
* _txPin_: transmission pin (used to send break signals).
298+
* _dePin_: Drive output enable pin.
299+
* _rePin_: Receiver output enable pin.
300+
* _txPin_: Transmission pin (used to send break signals).
301+
302+
#### Returns
303+
304+
None.
305+
### `setDelays()`
306+
307+
Sets the pre and post delays in milliseconds.
308+
309+
#### Syntax
310+
311+
```cpp
312+
RS485.setDelays (int predelay, int postdelay)
313+
```
314+
315+
#### Parameters
316+
317+
* _predelay_: The delay before sending data.
318+
* _postdelay_: The delay after sending data.
287319

288320
#### Returns
289321

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ noReceive KEYWORD2
2626
sendBreak KEYWORD2
2727
sendBreakMicroseconds KEYWORD2
2828
setPins KEYWORD2
29+
setDelays KEYWORD2
2930

3031
#######################################
3132
# Constants (LITERAL1)

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"url": "https://github.com/CIRCUITSTATE",
1414
"maintainer": true
1515
},
16-
"version": "1.0.9",
16+
"version": "1.0.10",
1717
"license": "LGPL-2.1",
1818
"frameworks": "arduino",
1919
"platforms": "*"

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=CSE_ArduinoRS485
2-
version=1.0.9
2+
version=1.0.10
33
author=CIRCUITSTATE
44
maintainer=CIRCUITSTATE <@circuitstate>
55
sentence=Allows sending and receiving data through the RS-485 interface, using any Arduino-compatible boards.
6-
paragraph=This library supports the Maxim Integrated MAX485 and equivalent chipsets. You can use both hardware serial and software serial ports for communication.
6+
paragraph=This library supports the Maxim Integrated MAX485 and equivalent RS485 transceivers. You can use both hardware and software serial ports for communication.
77
category=Communication
88
url=https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
99
architectures=*

src/CSE_RS485.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
//===================================================================================//
2222

23-
// Version: 1.0.9
24-
// Last modified: +05:30 20:37:44 PM 25-07-2023, Tuesday
23+
// Version: 1.0.10
24+
// Last modified: +05:30 12:57:59 PM 04-10-2023, Wednesday
2525
// Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
2626

2727
//===================================================================================//

src/CSE_RS485.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
//===================================================================================//
2222

23-
// Version: 1.0.9
24-
// Last modified: +05:30 20:37:40 PM 25-07-2023, Tuesday
23+
// Version: 1.0.10
24+
// Last modified: +05:30 12:57:53 PM 04-10-2023, Wednesday
2525
// Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
2626

2727
//===================================================================================//
@@ -87,7 +87,6 @@ class RS485Class : public Stream {
8787
void sendBreakMicroseconds (unsigned int duration);
8888

8989
void setPins (int dePin, int rePin = -1, int txPin = -1);
90-
9190
void setDelays (int predelay, int postdelay);
9291

9392
private:

0 commit comments

Comments
 (0)