Skip to content

Commit e962b4c

Browse files
Add config parameter to RS485 initialization (#27)
* Update RS485CommClass.cpp Added RS485Config * Update RS485CommClass.h * Update RS485_fullduplex.ino * Update RS485_halfduplex.ino * Removed = in cpp
1 parent b66618e commit e962b4c

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

examples/RS485_fullduplex/RS485_fullduplex.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void setup() {
3838
// - Half Duplex
3939
// - No A/B and Y/Z 120 Ohm termination enabled
4040
// Enable the RS485/RS232 system
41-
MachineControl_RS485Comm.begin(115200, 0, 500); // Specify baudrate, and preamble and postamble times for RS485 communication
41+
MachineControl_RS485Comm.begin(115200, SERIAL_8N1, 0, 500); // Specify baudrate, serial_config and preamble and postamble times for RS485 communication
4242

4343
// Enable Full Duplex mode
4444
// This will also enable A/B and Y/Z 120 Ohm termination resistors
@@ -70,4 +70,4 @@ void loop() {
7070

7171
sendNow = millis() + sendInterval;
7272
}
73-
}
73+
}

examples/RS485_halfduplex/RS485_halfduplex.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void setup() {
3737
// - Half Duplex
3838
// - No A/B and Y/Z 120 Ohm termination enabled
3939
// Enable the RS485/RS232 system
40-
MachineControl_RS485Comm.begin(115200, 0, 500); // Specify baudrate, and preamble and postamble times for RS485 communication
40+
MachineControl_RS485Comm.begin(115200, SERIAL_8N1, 0, 500); // Specify baudrate, serial config and preamble and postamble times for RS485 communication
4141

4242
// Start in receive mode
4343
MachineControl_RS485Comm.receive();
@@ -65,4 +65,4 @@ void loop() {
6565

6666
sendNow = millis() + sendInterval;
6767
}
68-
}
68+
}

src/RS485CommClass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RS485CommClass::RS485CommClass(arduino::UART& uart_itf, PinName rs_tx_pin, PinNa
1717
RS485CommClass::~RS485CommClass()
1818
{ }
1919

20-
void RS485CommClass::begin(unsigned long baudrate, int predelay, int postdelay) {
20+
void RS485CommClass::begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay) {
2121
/* Pinout configuration */
2222
pinMode(PinNameToIndex(MC_RS485_TX_PIN), OUTPUT);
2323
pinMode(PinNameToIndex(MC_RS485_RX_PIN), OUTPUT);
@@ -45,7 +45,7 @@ void RS485CommClass::begin(unsigned long baudrate, int predelay, int postdelay)
4545
_enable();
4646

4747
/* Call begin() base class to initialize RS485 communication */
48-
RS485Class::begin(baudrate, predelay, postdelay);
48+
RS485Class::begin(baudrate, config, predelay, postdelay);
4949

5050
return;
5151
}
@@ -92,4 +92,4 @@ void RS485CommClass::_disable() {
9292

9393
arduino::UART _UART4_ {MC_RS485_TX_PIN, MC_RS485_RX_PIN, NC, NC};
9494
RS485CommClass MachineControl_RS485Comm(_UART4_);
95-
/**** END OF FILE ****/
95+
/**** END OF FILE ****/

src/RS485CommClass.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ class RS485CommClass : public RS485Class {
5454
* This method initializes the RS485 communication protocol with the specified baud rate and pre/post delays.
5555
*
5656
* @param baudrate The desired baud rate for the RS485 communication.
57+
* @param config The desired Serial config (bits, parity and stopbits), see HardwareSerial.h
5758
* @param predelay The delay before sending data in the RS485 communication (default: RS485_DEFAULT_PRE_DELAY).
5859
* @param postdelay The delay after sending data in the RS485 communication (default: RS485_DEFAULT_POST_DELAY).
5960
*/
60-
void begin(unsigned long baudrate = 115200, int predelay = RS485_DEFAULT_PRE_DELAY, int postdelay = RS485_DEFAULT_POST_DELAY);
61+
void begin(unsigned long baudrate = 115200, uint16_t config = SERIAL_8N1, int predelay = RS485_DEFAULT_PRE_DELAY, int postdelay = RS485_DEFAULT_POST_DELAY);
6162

6263
/**
6364
* @brief Close the RS485 communication protocol.

0 commit comments

Comments
 (0)