Skip to content

Add MY_RS485_DE_INVERSE define to invert the device enable pin polarity #1358

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

Merged
merged 6 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions MyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@
*/
//#define MY_RS485_DE_PIN (2)

/**
* @def MY_RS485_DE_INVERSE
* @brief Define this if RS485 driver enable pin polarity is inverted (low-active).
*/
//#define MY_RS485_DE_INVERSE

/**
* @def MY_RS485_HWSERIAL
* @brief Define this if RS485 is connected to a hardware serial port.
Expand Down Expand Up @@ -2317,6 +2323,7 @@
#define MY_OTA_USE_I2C_EEPROM
// RS485
#define MY_RS485
#define MY_RS485_DE_INVERSE
#define MY_RS485_HWSERIAL
// RF24
#define MY_RADIO_RF24
Expand Down
18 changes: 17 additions & 1 deletion hal/transport/RS485/MyTransportRS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@
#endif

#if defined(MY_RS485_DE_PIN)
#if !defined(MY_RS485_DE_INVERSE)
#define assertDE() hwDigitalWrite(MY_RS485_DE_PIN, HIGH); delayMicroseconds(5)
#define deassertDE() hwDigitalWrite(MY_RS485_DE_PIN, LOW)

#else
#define assertDE() hwDigitalWrite(MY_RS485_DE_PIN, LOW); delayMicroseconds(5)
#define deassertDE() hwDigitalWrite(MY_RS485_DE_PIN, HIG)
#endif
#else
#define assertDE()
#define deassertDE()
Expand Down Expand Up @@ -264,7 +268,11 @@ bool transportSend(const uint8_t to, const void* data, const uint8_t len, const
}

#if defined(MY_RS485_DE_PIN)
#if !defined(MY_RS485_DE_INVERSE)
hwDigitalWrite(MY_RS485_DE_PIN, HIGH);
#else
hwDigitalWrite(MY_RS485_DE_PIN, LOW);
#endif
delayMicroseconds(5);
#endif

Expand Down Expand Up @@ -310,7 +318,11 @@ bool transportSend(const uint8_t to, const void* data, const uint8_t len, const
_dev.flush();
#endif
#endif
#if !defined(MY_RS485_DE_INVERSE)
hwDigitalWrite(MY_RS485_DE_PIN, LOW);
#else
hwDigitalWrite(MY_RS485_DE_PIN, HIGH);
#endif
#endif
return true;
}
Expand All @@ -324,7 +336,11 @@ bool transportInit(void)
_serialReset();
#if defined(MY_RS485_DE_PIN)
hwPinMode(MY_RS485_DE_PIN, OUTPUT);
#if !defined(MY_RS485_DE_INVERSE)
hwDigitalWrite(MY_RS485_DE_PIN, LOW);
#else
hwDigitalWrite(MY_RS485_DE_PIN, HIGH);
#endif
#endif
return true;
}
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ MY_RFM69_TX_POWER_DBM LITERAL1
MY_RS485 LITERAL1
MY_RS485_BAUD_RATE LITERAL1
MY_RS485_DE_PIN LITERAL1
MY_RS485_DE_INVERSE LITERAL1
MY_RS485_HWSERIAL LITERAL1
MY_RS485_MAX_MESSAGE_LENGTH LITERAL1
MY_RS485_SOH_COUNT LITERAL1
Expand Down