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

Commit 040bd53

Browse files
authored
Merge pull request #1 from manchoz/mnx_rs232_example
Update RS232 example
2 parents 7297cb7 + 601d932 commit 040bd53

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

examples/RS232/RS232.ino

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
from the interface RX channel.
88
99
Circuit:
10-
- Portenta H7
11-
- Machine Control
12-
- A Slave device with RS232 interface
13-
- Connect TXN to RXD Slave RS232 channel
14-
- Connect RSXN to TXD Slave RS232 channel
10+
- Arduino Portenta Machine Control (PMC)
11+
- Device with RS232 interface
12+
- Connect PMC TXN to RS232 Device RXD
13+
- Connect PMC RXP to RS232 Device TXD
14+
- Connect PMC GND to RS232 Device GND
1515
1616
*/
1717

18-
#include "Arduino_MachineControl.h"
18+
#include <Arduino_MachineControl.h>
1919

2020
using namespace machinecontrol;
2121

@@ -39,15 +39,18 @@ void setup()
3939
comm_protocols.init();
4040

4141
// RS485/RS232 default config is:
42+
// - RS485/RS232 system disabled
4243
// - RS485 mode
4344
// - Half Duplex
4445
// - No A/B and Y/Z 120 Ohm termination enabled
4546

4647
// Enable the RS485/RS232 system
47-
comm_protocols.rs485Enable(false);
48+
comm_protocols.rs485Enable(true);
49+
// Enable the RS232 mode
50+
comm_protocols.rs485ModeRS232(true);
4851

49-
// Specify baudrate, and preamble and postamble times for RS485 communication
50-
comm_protocols.rs485.begin(115200, 0, 500);
52+
// Specify baudrate for RS232 communication
53+
comm_protocols.rs485.begin(115200);
5154
// Start in receive mode
5255
comm_protocols.rs485.receive();
5356

@@ -60,14 +63,21 @@ void loop()
6063
Serial.write(comm_protocols.rs485.read());
6164

6265
if (millis() > sendNow) {
66+
String log = "[";
67+
log += sendNow;
68+
log += "] ";
69+
70+
String msg = "hello ";
71+
msg += counter++;
72+
73+
log += msg;
74+
Serial.println(log);
75+
6376
// Disable receive mode before transmission
6477
comm_protocols.rs485.noReceive();
6578

6679
comm_protocols.rs485.beginTransmission();
67-
68-
comm_protocols.rs485.print("hello ");
69-
comm_protocols.rs485.println(counter++);
70-
80+
comm_protocols.rs485.println(msg);
7181
comm_protocols.rs485.endTransmission();
7282

7383
// Re-enable receive mode after transmission

0 commit comments

Comments
 (0)