You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
12
8
13
9
Three examples are included with this library:
14
10
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.
17
13
* **RS485_Passthrough** - Sends and receives data between the RS-485 port and the default serial port.
18
14
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**.
20
16
21
17
* https://github.com/arduino-libraries/ArduinoRS485[ArduinoRS485 Library by Arduino]
22
18
* https://www.arduino.cc/reference/en/libraries/arduinors485/[ArduinoRS485 documentation by Arduino]
23
19
* 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]
24
20
* 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]
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.
8
26
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.
9
28
#### Syntax
10
29
11
30
```cpp
12
-
RS485Class RS485 (serial, dePin, rePin, txPin);
31
+
RS485Class RS485 (auto serial, int dePin, int rePin, int txPin);
13
32
```
14
33
15
34
#### Parameters
16
35
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`).
* _txPin_: Serial transmit pin (used to send break signals). Optional. Default: -1.
21
40
22
41
### `begin()`
23
42
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.
25
44
26
45
#### Syntax
27
46
47
+
There are 5 overloads of this function:
48
+
28
49
```cpp
50
+
RS485.begin()
29
51
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)
30
55
```
31
56
32
57
#### Parameters
33
58
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.
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.
59
71
60
72
#### Syntax
61
73
@@ -73,7 +85,7 @@ None.
73
85
74
86
### `available()`
75
87
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.
77
89
78
90
#### Syntax
79
91
@@ -87,11 +99,11 @@ None.
87
99
88
100
#### Returns
89
101
90
-
The number of bytes available to read.
102
+
*_int_: The number of bytes available to read.
91
103
92
104
### `peek()`
93
105
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.
95
107
96
108
#### Syntax
97
109
@@ -105,11 +117,11 @@ None.
105
117
106
118
#### Returns
107
119
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.
109
121
110
122
### `read()`
111
123
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.
113
125
114
126
#### Syntax
115
127
@@ -123,7 +135,7 @@ None.
123
135
124
136
#### Returns
125
137
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.
127
139
128
140
### `write()`
129
141
@@ -141,7 +153,7 @@ RS485.write (uint8_t b)
141
153
142
154
#### Returns
143
155
144
-
The number of bytes written.
156
+
*_size_t_: The number of bytes written.
145
157
146
158
### `flush()`
147
159
@@ -163,7 +175,9 @@ None.
163
175
164
176
### `beginTransmission()`
165
177
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.
167
181
168
182
#### Syntax
169
183
@@ -181,7 +195,7 @@ None.
181
195
182
196
### `endTransmission()`
183
197
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.
185
199
186
200
#### Syntax
187
201
@@ -199,7 +213,7 @@ None.
199
213
200
214
### `receive()`
201
215
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.
203
217
204
218
#### Syntax
205
219
@@ -217,7 +231,7 @@ None.
217
231
218
232
### `noReceive()`
219
233
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 highimpedance state.
221
235
222
236
#### Syntax
223
237
@@ -235,7 +249,7 @@ None.
235
249
236
250
### `sendBreak()`
237
251
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.
239
253
240
254
#### Syntax
241
255
@@ -253,7 +267,7 @@ None.
253
267
254
268
### `sendBreakMicroseconds()`
255
269
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.
257
271
258
272
#### Syntax
259
273
@@ -281,9 +295,27 @@ RS485.setPins (int dePin, int rePin, int txPin)
281
295
282
296
#### Parameters
283
297
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).
Copy file name to clipboardExpand all lines: library.properties
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
name=CSE_ArduinoRS485
2
-
version=1.0.9
2
+
version=1.0.10
3
3
author=CIRCUITSTATE
4
4
maintainer=CIRCUITSTATE <@circuitstate>
5
5
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.
0 commit comments