Skip to content

Add support for RS485 on Controllino Maxi/Mega #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/RS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,12 @@ void RS485Class::setPins(int txPin, int dePin, int rePin)
_rePin = rePin;
}

#if defined(CONTROLLINO_MAXI) || defined(CONTROLLINO_MEGA)
RS485Class RS485(SERIAL_PORT_HARDWARE3, CONTROLLINO_RS485_TX, CONTROLLINO_RS485_DE, CONTROLLINO_RS485_nRE);
#elif defined(__AVR_ATmega2560__)
RS485Class RS485(Serial3, RS485_TX_PIN, RS485_DE_PIN, RS485_nRE_PIN);
#elif defined(__AVR_ATmega328P__)
RS485Class RS485(Serial, RS485_TX_PIN, RS485_DE_PIN, RS485_nRE_PIN);
#else
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
#endif
14 changes: 14 additions & 0 deletions src/RS485.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@

#include <Arduino.h>

#if defined(CONTROLLINO_MAXI) || defined(CONTROLLINO_MEGA)
#include <Controllino.h>
#endif

#if defined(__AVR_ATmega2560__)
#define RS485_DE_PIN 21
#define RS485_nRE_PIN 20
#define RS485_TX_PIN 14
#elif defined(__AVR_ATmega328P__)
#define RS485_DE_PIN 3
#define RS485_nRE_PIN 2
#define RS485_TX_PIN 1
#endif

#ifdef PIN_SERIAL1_TX
#define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX
#else
Expand Down