Skip to content
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

#38 ATmega32U4, ATmega2560, ATmega1280 supported as a RS485 Slave #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions src/DcsBios.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ do not come with their own build system, we are just putting everything into the
#include "internal/DcsBiosNgRS485Master.cpp.inc"
#endif
#ifdef DCSBIOS_RS485_SLAVE
#include "internal/DcsBiosNgRS485Slave.h"
#include "internal/DcsBiosNgRS485Slave.cpp.inc"
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
#include "internal/UART.Mod/DcsBiosNgRS485Slave.h"
#include "internal/UART.Mod/DcsBiosNgRS485Slave.cpp.inc"
#else
#include "internal/DcsBiosNgRS485Slave.h"
#include "internal/DcsBiosNgRS485Slave.cpp.inc"
#endif
#endif
#ifdef DCSBIOS_IRQ_SERIAL

Expand Down
8 changes: 4 additions & 4 deletions src/internal/UART.Mod/DcsBiosNgRS485Slave.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ namespace DcsBios {

}

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

void setup() {

// Arduino Mega UART 1
#ifdef UART1_SELECT
// Arduino Mega UART 1 or Arduino ProMicro
#if defined(UART1_SELECT) || defined(__AVR_ATmega32U4__)
PRR1 &= ~(0<<PRUSART1); // PRR1 Bit 0 - PRUSART1: Power Reduction USART1
UBRR1H = 0;
UBRR1L = 3; // 250000 bps
Expand Down
10 changes: 6 additions & 4 deletions src/internal/UART.Mod/DcsBiosNgRS485Slave.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

// Check for Arduino Mega when using UART 1,2 or 3
#if defined (UART1_SELECT) || defined(UART2_SELECT) || defined(UART3_SELECT)
#if not (defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__))
#if defined(__AVR_ATmega32U4__) && (defined (UART2_SELECT) || defined (UART3_SELECT))
#error The RS485Slave sketch requires an Arduino Mega for UART 2 or UART 3!
#elseif not (defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__))
#error The RS485Slave sketch requires an Arduino Mega for UART 1, UART 2 or UART 3!
#endif
#endif

#include "Arduino.h"
#include "RingBuffer.h"
#include "../RingBuffer.h"

namespace DcsBios {

Expand Down Expand Up @@ -87,8 +89,8 @@ namespace DcsBios {
void udreISR();
void txcISR();

// Arduino Mega UART 1
#ifdef UART1_SELECT
// Arduino Mega UART 1 or Arduino ProMicro
#if defined(UART1_SELECT) || defined(__AVR_ATmega32U4__)
inline void set_txen() { *ucsrb &= ~((1<<RXEN1) | (1<<RXCIE1)); *txen_port |= txen_pin_mask; *ucsrb |= (1<<TXEN1) | (1<<TXCIE1); };
inline void clear_txen() { *ucsrb &= ~((1<<TXEN1) | (1<<TXCIE1)); *txen_port &= ~txen_pin_mask; *ucsrb |= (1<<RXEN1) | (1<<RXCIE1); };
inline void tx_byte(uint8_t c) { set_txen(); *udr = c; *ucsra |= (1<<TXC1); }
Expand Down