setup second serial port only in case it is selected

This commit is contained in:
PavelSindler 2017-10-16 17:03:38 +02:00
parent 8dd9a4308e
commit c2478ae7d3
4 changed files with 19 additions and 27 deletions

View File

@ -96,7 +96,7 @@ void serial_echopair_P(const char *s_P, float v);
void serial_echopair_P(const char *s_P, double v); void serial_echopair_P(const char *s_P, double v);
void serial_echopair_P(const char *s_P, unsigned long v); void serial_echopair_P(const char *s_P, unsigned long v);
extern int selectedSerialPort; extern uint8_t selectedSerialPort;
//Things to write to serial from Program memory. Saves 400 to 2k of RAM. //Things to write to serial from Program memory. Saves 400 to 2k of RAM.
FORCE_INLINE void serialprintPGM(const char *str) FORCE_INLINE void serialprintPGM(const char *str)

View File

@ -67,8 +67,6 @@ FORCE_INLINE void store_char(unsigned char c)
#ifndef SNMM #ifndef SNMM
SIGNAL(USART2_RX_vect) SIGNAL(USART2_RX_vect)
{ {
SERIAL_ECHOPGM("Debug:");
MYSERIAL.println(1);
if (selectedSerialPort == 1) { if (selectedSerialPort == 1) {
// Test for a framing error. // Test for a framing error.
if (UCSR2A & (1<<FE2)) { if (UCSR2A & (1<<FE2)) {
@ -110,8 +108,6 @@ void MarlinSerial::begin(long baud)
#endif #endif
// set up the first (original serial port) // set up the first (original serial port)
if (useU2X) { if (useU2X) {
SERIAL_ECHOPGM("Debug:");
MYSERIAL.println(3);
M_UCSRxA = 1 << M_U2Xx; M_UCSRxA = 1 << M_U2Xx;
baud_setting = (F_CPU / 4 / baud - 1) / 2; baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else { } else {
@ -128,29 +124,29 @@ void MarlinSerial::begin(long baud)
sbi(M_UCSRxB, M_RXCIEx); sbi(M_UCSRxB, M_RXCIEx);
#ifndef SNMM #ifndef SNMM
// set up the second serial port
if (useU2X) {
UCSR2A = 1 << U2X2;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
UCSR2A = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) if (selectedSerialPort == 1) { //set up also the second serial port
UBRR2H = baud_setting >> 8; if (useU2X) {
UBRR2L = baud_setting; UCSR2A = 1 << U2X2;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
UCSR2A = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
sbi(UCSR2B, RXEN2); // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
sbi(UCSR2B, TXEN2); UBRR2H = baud_setting >> 8;
sbi(UCSR2B, RXCIE2); UBRR2L = baud_setting;
sbi(UCSR2B, RXEN2);
sbi(UCSR2B, TXEN2);
sbi(UCSR2B, RXCIE2);
}
#endif #endif
} }
void MarlinSerial::end() void MarlinSerial::end()
{ {
SERIAL_ECHOPGM("Debug:");
MYSERIAL.println(4);
cbi(M_UCSRxB, M_RXENx); cbi(M_UCSRxB, M_RXENx);
cbi(M_UCSRxB, M_TXENx); cbi(M_UCSRxB, M_TXENx);
cbi(M_UCSRxB, M_RXCIEx); cbi(M_UCSRxB, M_RXCIEx);

View File

@ -73,7 +73,7 @@
// is the index of the location from which to read. // is the index of the location from which to read.
#define RX_BUFFER_SIZE 128 #define RX_BUFFER_SIZE 128
extern int selectedSerialPort; extern uint8_t selectedSerialPort;
struct ring_buffer struct ring_buffer
{ {

View File

@ -290,7 +290,7 @@ unsigned int custom_message_type;
unsigned int custom_message_state; unsigned int custom_message_state;
char snmm_filaments_used = 0; char snmm_filaments_used = 0;
int selectedSerialPort; uint8_t selectedSerialPort;
float distance_from_min[3]; float distance_from_min[3];
@ -1030,12 +1030,8 @@ void setup()
if ((farm_mode == 0xFF && farm_no == 0) || ((uint16_t)farm_no == 0xFFFF)) if ((farm_mode == 0xFF && farm_no == 0) || ((uint16_t)farm_no == 0xFFFF))
farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode
if ((uint16_t)farm_no == 0xFFFF) farm_no = 0; if ((uint16_t)farm_no == 0xFFFF) farm_no = 0;
SERIAL_ECHOPGM("Farm mode:");
MYSERIAL.println(farm_mode);
if (farm_mode) if (farm_mode)
{ {
SERIAL_ECHOPGM("Debug:");
MYSERIAL.println(0);
prusa_statistics(8); prusa_statistics(8);
no_response = true; //we need confirmation by recieving PRUSA thx no_response = true; //we need confirmation by recieving PRUSA thx
important_status = 8; important_status = 8;