From 14519aa7ee2ada669bea50632a60d1ca6a147502 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 13 Sep 2017 13:35:22 +0200 Subject: [PATCH] Support the second serial (original commit 7d2d6c6fdcb296e776c7143cc72f6ca2271aa11e on MK2 by AndreeeCZ) --- Firmware/MarlinSerial.cpp | 45 +++++++++++++++++++++++++++-- Firmware/MarlinSerial.h | 59 ++++++++++++++++++++++++++++----------- Firmware/Marlin_main.cpp | 50 ++++++++++++++++++++++++++++++++- 3 files changed, 134 insertions(+), 20 deletions(-) diff --git a/Firmware/MarlinSerial.cpp b/Firmware/MarlinSerial.cpp index fba87cc8..8606b9f2 100644 --- a/Firmware/MarlinSerial.cpp +++ b/Firmware/MarlinSerial.cpp @@ -23,6 +23,8 @@ #include "Marlin.h" #include "MarlinSerial.h" +int selectedSerialPort; + #ifndef AT90USB // this next line disables the entire HardwareSerial.cpp, // this is so I can support Attiny series and any other chip without a UART @@ -64,6 +66,23 @@ FORCE_INLINE void store_char(unsigned char c) store_char(c); } } + + SIGNAL(USART2_RX_vect) + { + if (selectedSerialPort == 1) { + // Test for a framing error. + if (UCSR2A & (1<> 8; + UBRR2L = baud_setting; + + sbi(UCSR2B, RXEN2); + sbi(UCSR2B, TXEN2); + sbi(UCSR2B, RXCIE2); } void MarlinSerial::end() { cbi(M_UCSRxB, M_RXENx); cbi(M_UCSRxB, M_TXENx); - cbi(M_UCSRxB, M_RXCIEx); + cbi(M_UCSRxB, M_RXCIEx); + + cbi(UCSR2B, RXEN2); + cbi(UCSR2B, TXEN2); + cbi(UCSR2B, RXCIE2); } diff --git a/Firmware/MarlinSerial.h b/Firmware/MarlinSerial.h index 6776b568..30f5b83d 100644 --- a/Firmware/MarlinSerial.h +++ b/Firmware/MarlinSerial.h @@ -73,6 +73,7 @@ // is the index of the location from which to read. #define RX_BUFFER_SIZE 128 +extern int selectedSerialPort; struct ring_buffer { @@ -110,24 +111,48 @@ class MarlinSerial //: public Stream } - FORCE_INLINE void checkRx(void) + void checkRx(void) { - if((M_UCSRxA & (1< 0) { + uint8_t serial_char = MSerial.read(); + selectedSerialPort = 1; + MSerial.write(serial_char); + numbersRead++; + selectedSerialPort = 0; + } + } + selectedSerialPort = 1; + MSerial.write('\n'); + /*for (int b = 0; b < 3; b++) { + tone(BEEPER, 110); + delay(50); + noTone(BEEPER); + delay(50); + }*/ + } else { + MYSERIAL.println("Not in farm mode."); + } + + } else if(code_seen("Fir")){ SERIAL_PROTOCOLLN(FW_version);