Skip to content

Commit 2d5eb33

Browse files
Merge pull request #79 from leomar75/rs485_slave-support-for-mega-promicro-boards
#38 ATmega32U4, ATmega2560, ATmega1280 supported as a RS485 Slave
2 parents b7d193b + f5ea9d8 commit 2d5eb33

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/DcsBios.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ do not come with their own build system, we are just putting everything into the
4545
#include "internal/DcsBiosNgRS485Master.cpp.inc"
4646
#endif
4747
#ifdef DCSBIOS_RS485_SLAVE
48-
#include "internal/DcsBiosNgRS485Slave.h"
49-
#include "internal/DcsBiosNgRS485Slave.cpp.inc"
48+
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
49+
#include "internal/UART.Mod/DcsBiosNgRS485Slave.h"
50+
#include "internal/UART.Mod/DcsBiosNgRS485Slave.cpp.inc"
51+
#else
52+
#include "internal/DcsBiosNgRS485Slave.h"
53+
#include "internal/DcsBiosNgRS485Slave.cpp.inc"
54+
#endif
5055
#endif
5156
#ifdef DCSBIOS_ESP32_WIFI
5257
#include "internal/ESP32WiFi/DcsBiosESP32WiFiSlave.h"

src/internal/UART.Mod/DcsBiosNgRS485Slave.cpp.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ namespace DcsBios {
172172

173173
}
174174

175-
// Arduino Mega UART 1
176-
#ifdef UART1_SELECT
175+
// Arduino Mega UART 1 or Arduino ProMicro
176+
#if defined(UART1_SELECT) || defined(__AVR_ATmega32U4__)
177177
RS485Slave rs485slave(&UDR1, &UCSR1A, &UCSR1B, &UCSR1C, TXENABLE_PIN);
178178
ISR(USART1_RX_vect) { rs485slave.rxISR(); }
179179
ISR(USART1_TX_vect) { rs485slave.txcISR(); }
@@ -204,8 +204,8 @@ namespace DcsBios {
204204

205205
void setup() {
206206

207-
// Arduino Mega UART 1
208-
#ifdef UART1_SELECT
207+
// Arduino Mega UART 1 or Arduino ProMicro
208+
#if defined(UART1_SELECT) || defined(__AVR_ATmega32U4__)
209209
PRR1 &= ~(0<<PRUSART1); // PRR1 Bit 0 - PRUSART1: Power Reduction USART1
210210
UBRR1H = 0;
211211
UBRR1L = 3; // 250000 bps

src/internal/UART.Mod/DcsBiosNgRS485Slave.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
// Check for Arduino Mega when using UART 1,2 or 3
66
#if defined (UART1_SELECT) || defined(UART2_SELECT) || defined(UART3_SELECT)
7-
#if not (defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__))
7+
#if defined(__AVR_ATmega32U4__) && (defined (UART2_SELECT) || defined (UART3_SELECT))
8+
#error The RS485Slave sketch requires an Arduino Mega for UART 2 or UART 3!
9+
#elseif not (defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__))
810
#error The RS485Slave sketch requires an Arduino Mega for UART 1, UART 2 or UART 3!
911
#endif
1012
#endif
1113

1214
#include "Arduino.h"
13-
#include "RingBuffer.h"
15+
#include "../RingBuffer.h"
1416

1517
namespace DcsBios {
1618

@@ -87,8 +89,8 @@ namespace DcsBios {
8789
void udreISR();
8890
void txcISR();
8991

90-
// Arduino Mega UART 1
91-
#ifdef UART1_SELECT
92+
// Arduino Mega UART 1 or Arduino ProMicro
93+
#if defined(UART1_SELECT) || defined(__AVR_ATmega32U4__)
9294
inline void set_txen() { *ucsrb &= ~((1<<RXEN1) | (1<<RXCIE1)); *txen_port |= txen_pin_mask; *ucsrb |= (1<<TXEN1) | (1<<TXCIE1); };
9395
inline void clear_txen() { *ucsrb &= ~((1<<TXEN1) | (1<<TXCIE1)); *txen_port &= ~txen_pin_mask; *ucsrb |= (1<<RXEN1) | (1<<RXCIE1); };
9496
inline void tx_byte(uint8_t c) { set_txen(); *udr = c; *ucsra |= (1<<TXC1); }

0 commit comments

Comments
 (0)