Skip to content

Commit a374e8b

Browse files
committed
Changing setting of the UMSELn bits (for UART mode) and serial config values.
Before, the UMSELn1 bit was being to set to 1, putting the UART into a reserved mode. Now, we only set the high (0x80) bit to 1 for the ATmega8, which is needed to access UCSRnC (whose i/o address is shared with UBRRH). Also, no longer bitwise-or the new config with the existing register value, because we're actually configuring all the settings in the register. (We're not using UCPOL, but it's supposed to be 0 in asynchronous mode.)
1 parent ae9b906 commit a374e8b

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

hardware/arduino/cores/arduino/HardwareSerial.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,11 @@ void HardwareSerial::begin(unsigned long baud, byte config)
393393
*_ubrrh = baud_setting >> 8;
394394
*_ubrrl = baud_setting;
395395

396-
//set number of data bits
397-
current_config = *_ubrrh;
398-
current_config = *_ucsrc;
399-
current_config |= config;
400-
*_ucsrc = current_config;
396+
//set the data bits, parity, and stop bits
397+
#if defined(__AVR_ATmega8__)
398+
config |= 0x80; // select UCSRC register (shared with UBRRH)
399+
#endif
400+
*_ucsrc = config;
401401

402402
sbi(*_ucsrb, _rxen);
403403
sbi(*_ucsrb, _txen);

hardware/arduino/cores/arduino/HardwareSerial.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,30 @@ class HardwareSerial : public Stream
6969
};
7070

7171
// Define config for Serial.begin(baud, config);
72-
#define SERIAL_5N1 0x80
73-
#define SERIAL_6N1 0x82
74-
#define SERIAL_7N1 0x84
75-
#define SERIAL_8N1 0x86
76-
#define SERIAL_5N2 0x88
77-
#define SERIAL_6N2 0x8A
78-
#define SERIAL_7N2 0x8C
79-
#define SERIAL_8N2 0x8E
80-
#define SERIAL_5E1 0xA0
81-
#define SERIAL_6E1 0xA2
82-
#define SERIAL_7E1 0xA4
83-
#define SERIAL_8E1 0xA6
84-
#define SERIAL_5E2 0xA8
85-
#define SERIAL_6E2 0xAA
86-
#define SERIAL_7E2 0xAC
87-
#define SERIAL_8E2 0xAE
88-
#define SERIAL_5O1 0xB0
89-
#define SERIAL_6O1 0xB2
90-
#define SERIAL_7O1 0xB4
91-
#define SERIAL_8O1 0xB6
92-
#define SERIAL_5O2 0xB8
93-
#define SERIAL_6O2 0xBA
94-
#define SERIAL_7O2 0xBC
95-
#define SERIAL_8O2 0xBE
72+
#define SERIAL_5N1 0x00
73+
#define SERIAL_6N1 0x02
74+
#define SERIAL_7N1 0x04
75+
#define SERIAL_8N1 0x06
76+
#define SERIAL_5N2 0x08
77+
#define SERIAL_6N2 0x0A
78+
#define SERIAL_7N2 0x0C
79+
#define SERIAL_8N2 0x0E
80+
#define SERIAL_5E1 0x20
81+
#define SERIAL_6E1 0x22
82+
#define SERIAL_7E1 0x24
83+
#define SERIAL_8E1 0x26
84+
#define SERIAL_5E2 0x28
85+
#define SERIAL_6E2 0x2A
86+
#define SERIAL_7E2 0x2C
87+
#define SERIAL_8E2 0x2E
88+
#define SERIAL_5O1 0x30
89+
#define SERIAL_6O1 0x32
90+
#define SERIAL_7O1 0x34
91+
#define SERIAL_8O1 0x36
92+
#define SERIAL_5O2 0x38
93+
#define SERIAL_6O2 0x3A
94+
#define SERIAL_7O2 0x3C
95+
#define SERIAL_8O2 0x3E
9696

9797
#if defined(UBRRH) || defined(UBRR0H)
9898
extern HardwareSerial Serial;

0 commit comments

Comments
 (0)