Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit d5dcfa4

Browse files
committed
Add documentation to examples
1 parent df390c3 commit d5dcfa4

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

Diff for: examples/RS485_fullduplex/RS485_fullduplex.ino

+19-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,26 @@ void setup()
3333
delay(1000);
3434
Serial.println("Start RS485 initialization");
3535

36+
// Set the PMC Communication Protocols to default config
3637
comm_protocols.init();
38+
// RS485/RS232 default config is:
39+
// - RS485 mode
40+
// - Half Duplex
41+
// - No A/B and Y/Z 120 Ohm termination enabled
42+
43+
// Enable the RS485/RS232 system
3744
comm_protocols.rs485Enable(true);
45+
46+
// Enable Full Duplex mode
47+
// This will also enable A/B and Y/Z 120 Ohm termination resistors
3848
comm_protocols.rs485FullDuplex(true);
3949

40-
comm_protocols.rs485.receive();
50+
// Specify baudrate, and preamble and postamble times for RS485 communication
4151
comm_protocols.rs485.begin(115200, 0, 500);
52+
53+
// Start in receive mode
54+
comm_protocols.rs485.receive();
55+
4256

4357
Serial.println("Initialization done!");
4458
}
@@ -49,13 +63,17 @@ void loop()
4963
Serial.write(comm_protocols.rs485.read());
5064

5165
if (millis() > sendNow) {
66+
// Disable receive mode before transmission
5267
comm_protocols.rs485.noReceive();
68+
5369
comm_protocols.rs485.beginTransmission();
5470

5571
comm_protocols.rs485.print("hello ");
5672
comm_protocols.rs485.println(counter++);
5773

5874
comm_protocols.rs485.endTransmission();
75+
76+
// Re-enable receive mode after transmission
5977
comm_protocols.rs485.receive();
6078

6179
sendNow = millis() + sendInterval;

Diff for: examples/RS485_halfduplex/RS485_halfduplex.ino

+18-3
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,33 @@ using namespace machinecontrol;
2121
constexpr unsigned long sendInterval { 1000 };
2222
unsigned long sendNow { 0 };
2323

24-
unsigned long counter = 0;
24+
unsigned long counter { 0 };
2525

2626
void setup()
2727
{
2828

2929
Serial.begin(115200);
30+
// Wait for Serial or start after 2.5s
3031
for (auto const timeout = millis() + 2500; !Serial && timeout < millis(); delay(500))
3132
;
3233

3334
delay(2500);
3435
Serial.println("Start RS485 initialization");
3536

37+
// Set the PMC Communication Protocols to default config
3638
comm_protocols.init();
39+
40+
// RS485/RS232 default config is:
41+
// - RS485 mode
42+
// - Half Duplex
43+
// - No A/B and Y/Z 120 Ohm termination enabled
44+
45+
// Enable the RS485/RS232 system
3746
comm_protocols.rs485Enable(true);
3847

48+
// Specify baudrate, and preamble and postamble times for RS485 communication
3949
comm_protocols.rs485.begin(115200, 0, 500);
50+
// Start in receive mode
4051
comm_protocols.rs485.receive();
4152

4253
Serial.println("Initialization done!");
@@ -46,17 +57,21 @@ void loop()
4657
{
4758
if (comm_protocols.rs485.available())
4859
Serial.write(comm_protocols.rs485.read());
49-
60+
5061
if (millis() > sendNow) {
62+
// Disable receive mode before transmission
5163
comm_protocols.rs485.noReceive();
64+
5265
comm_protocols.rs485.beginTransmission();
5366

5467
comm_protocols.rs485.print("hello ");
5568
comm_protocols.rs485.println(counter++);
5669

5770
comm_protocols.rs485.endTransmission();
5871

59-
sendNow = millis() + sendInterval;
72+
// Re-enable receive mode after transmission
6073
comm_protocols.rs485.receive();
74+
75+
sendNow = millis() + sendInterval;
6176
}
6277
}

0 commit comments

Comments
 (0)