/
Receiver.ino
74 lines (65 loc) · 2.08 KB
/
Receiver.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2017 Olimex Ltd.
//
// GNU GENERAL PUBLIC LICENSE
// Version 3, 29 June 2007
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Tested with 2 ESP32-EVB Rev.I + 2 MOD-RS485-ISO connected to the UEXT
// The 2 MOD-RS485-ISO modules are connected between each other:
// A to A; B to B; GND_ISO to GND_ISO
// and the AB jumpers are closed on both modules
//
// One of the ESP32-EVB board is programmed with Sender sketch
// the other ESP32-EVB with Receiver sketch (both sketches are part of the library examples)
//
// Upon sending character from the Sender the Receiver will announce it
//
// Known bug: Sometimes there is an issue with the transfer resulting in a loss of data
#include <MOD-RS485-ISO.h>
/* MOD-RS485-ISO FIFO is limited to 64 bytes */
#define MAX_FIFO_SIZE 64
/* Make object with default address */
MOD_RS485_ISO rs;
/* Create data buffer with maximum FIFO size */
char data[MAX_FIFO_SIZE];
void setup()
{
Serial.begin(115200);
while(!Serial);
/* Enable RX */
rs.setControl(RX_ENABLED);
/* Change mode */
Serial.println("Setting mode to bridge...");
rs.setMode(BRIDGE_MODE);
/* Set baudrate */
Serial.println("Setting baudrate to 9600...");
rs.setBaudrate(UART_B9600);
}
int Time, PrevTime = 0;
void loop ()
{
Time = millis ();
if (Time-PrevTime > 200)
{
PrevTime = Time;
rs.readData((uint8_t *)data, MAX_FIFO_SIZE);
if (data[0] != 0)
{
Serial.print("Received data: ");
Serial.println(data);
data[0] = 0;
}
}
}