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.)
This commit is contained in:
David A. Mellis 2012-08-30 08:47:35 -04:00
parent ae9b90603b
commit a374e8b766
2 changed files with 29 additions and 29 deletions

View File

@ -393,11 +393,11 @@ try_again:
*_ubrrh = baud_setting >> 8;
*_ubrrl = baud_setting;
//set number of data bits
current_config = *_ubrrh;
current_config = *_ucsrc;
current_config |= config;
*_ucsrc = current_config;
//set the data bits, parity, and stop bits
#if defined(__AVR_ATmega8__)
config |= 0x80; // select UCSRC register (shared with UBRRH)
#endif
*_ucsrc = config;
sbi(*_ucsrb, _rxen);
sbi(*_ucsrb, _txen);

View File

@ -69,30 +69,30 @@ class HardwareSerial : public Stream
};
// Define config for Serial.begin(baud, config);
#define SERIAL_5N1 0x80
#define SERIAL_6N1 0x82
#define SERIAL_7N1 0x84
#define SERIAL_8N1 0x86
#define SERIAL_5N2 0x88
#define SERIAL_6N2 0x8A
#define SERIAL_7N2 0x8C
#define SERIAL_8N2 0x8E
#define SERIAL_5E1 0xA0
#define SERIAL_6E1 0xA2
#define SERIAL_7E1 0xA4
#define SERIAL_8E1 0xA6
#define SERIAL_5E2 0xA8
#define SERIAL_6E2 0xAA
#define SERIAL_7E2 0xAC
#define SERIAL_8E2 0xAE
#define SERIAL_5O1 0xB0
#define SERIAL_6O1 0xB2
#define SERIAL_7O1 0xB4
#define SERIAL_8O1 0xB6
#define SERIAL_5O2 0xB8
#define SERIAL_6O2 0xBA
#define SERIAL_7O2 0xBC
#define SERIAL_8O2 0xBE
#define SERIAL_5N1 0x00
#define SERIAL_6N1 0x02
#define SERIAL_7N1 0x04
#define SERIAL_8N1 0x06
#define SERIAL_5N2 0x08
#define SERIAL_6N2 0x0A
#define SERIAL_7N2 0x0C
#define SERIAL_8N2 0x0E
#define SERIAL_5E1 0x20
#define SERIAL_6E1 0x22
#define SERIAL_7E1 0x24
#define SERIAL_8E1 0x26
#define SERIAL_5E2 0x28
#define SERIAL_6E2 0x2A
#define SERIAL_7E2 0x2C
#define SERIAL_8E2 0x2E
#define SERIAL_5O1 0x30
#define SERIAL_6O1 0x32
#define SERIAL_7O1 0x34
#define SERIAL_8O1 0x36
#define SERIAL_5O2 0x38
#define SERIAL_6O2 0x3A
#define SERIAL_7O2 0x3C
#define SERIAL_8O2 0x3E
#if defined(UBRRH) || defined(UBRR0H)
extern HardwareSerial Serial;