ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 02.06.2025

Просмотров: 3611

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

USART Control and Status

Register B – UCSRB

This bit only has effect for the asynchronous operation. Write this bit to zero when using synchronous operation.

Writing this bit to one will reduce the divisor of the baud rate divider from 16 to 8 effectively doubling the transfer rate for asynchronous communication.

• Bit 0 – MPCM: Multi-processor Communication Mode

This bit enables the Multi-processor Communication mode. When the MPCM bit is written to one, all the incoming frames received by the USART Receiver that do not contain address information will be ignored. The Transmitter is unaffected by the MPCM setting. For more detailed information see “Multi-processor Communication Mode” on page 148.

Bit

7

6

5

4

3

2

1

0

RXCIE

TXCIE

UDRIE

RXEN

TXEN

UCSZ2

RXB8

TXB8

UCSRB

Read/Write

R/W

R/W

R/W

R/W

R/W

R/W

R

R/W

Initial Value

0

0

0

0

0

0

0

0

• Bit 7 – RXCIE: RX Complete Interrupt Enable

Writing this bit to one enables interrupt on the RXC Flag. A USART Receive Complete interrupt will be generated only if the RXCIE bit is written to one, the Global Interrupt Flag in SREG is written to one and the RXC bit in UCSRA is set.

• Bit 6 – TXCIE: TX Complete Interrupt Enable

Writing this bit to one enables interrupt on the TXC Flag. A USART Transmit Complete interrupt will be generated only if the TXCIE bit is written to one, the Global Interrupt Flag in SREG is written to one and the TXC bit in UCSRA is set.

• Bit 5 – UDRIE: USART Data Register Empty Interrupt Enable

Writing this bit to one enables interrupt on the UDRE Flag. A Data Register Empty interrupt will be generated only if the UDRIE bit is written to one, the Global Interrupt Flag in SREG is written to one and the UDRE bit in UCSRA is set.

• Bit 4 – RXEN: Receiver Enable

Writing this bit to one enables the USART Receiver. The Receiver will override normal port operation for the RxD pin when enabled. Disabling the Receiver will flush the receive buffer invalidating the FE, DOR and PE Flags.

• Bit 3 – TXEN: Transmitter Enable

Writing this bit to one enables the USART Transmitter. The Transmitter will override normal port operation for the TxD pin when enabled. The disabling of the Transmitter (writing TXEN to zero) will not become effective until ongoing and pending transmissions are completed (i.e., when the Transmit Shift Register and Transmit Buffer Register do not contain data to be transmitted). When disabled, the Transmitter will no longer override the TxD port.

• Bit 2 – UCSZ2: Character Size

The UCSZ2 bits combined with the UCSZ1:0 bit in UCSRC sets the number of data bits (Character Size) in a frame the Receiver and Transmitter use.

• Bit 1 – RXB8: Receive Data Bit 8

RXB8 is the ninth data bit of the received character when operating with serial frames with nine data bits. Must be read before reading the low bits from UDR.

• Bit 0 – TXB8: Transmit Data Bit 8

152 ATmega8(L)

2486O–AVR–10/04


USART Control and Status

Register C – UCSRC

2486O–AVR–10/04

ATmega8(L)

TXB8 is the ninth data bit in the character to be transmitted when operating with serial frames with nine data bits. Must be written before writing the low bits to UDR.

Bit

7

6

5

4

3

2

1

0

URSEL

UMSEL

UPM1

UPM0

USBS

UCSZ1

UCSZ0

UCPOL

UCSRC

Read/Write

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

Initial Value

1

0

0

0

0

1

1

0

The UCSRC Register shares the same I/O location as the UBRRH Register. See the “Accessing UBRRH/UCSRC Registers” on page 149 section which describes how to access this register.

• Bit 7 – URSEL: Register Select

This bit selects between accessing the UCSRC or the UBRRH Register. It is read as one when reading UCSRC. The URSEL must be one when writing the UCSRC.

• Bit 6 – UMSEL: USART Mode Select

This bit selects between Asynchronous and Synchronous mode of operation.

Table 55. UMSEL Bit Settings

UMSEL Mode

0Asynchronous Operation

1Synchronous Operation

153

• Bit 5:4 – UPM1:0: Parity Mode

These bits enable and set type of Parity Generation and Check. If enabled, the Transmitter will automatically generate and send the parity of the transmitted data bits within each frame. The Receiver will generate a parity value for the incoming data and compare it to the UPM0 setting. If a mismatch is detected, the PE Flag in UCSRA will be set.

Table 56. UPM Bits Settings

UPM1

UPM0

Parity Mode

0

0

Disabled

0

1

Reserved

1

0

Enabled, Even Parity

1

1

Enabled, Odd Parity

• Bit 3 – USBS: Stop Bit Select

This bit selects the number of stop bits to be inserted by the trAnsmitter. The Receiver ignores this setting.

Table 57. USBS Bit Settings

USBS

Stop Bit(s)

0

1-bit

1

2-bit

• Bit 2:1 – UCSZ1:0: Character Size

The UCSZ1:0 bits combined with the UCSZ2 bit in UCSRB sets the number of data bits (Character Size) in a frame the Receiver and Transmitter use.

Table 58. UCSZ Bits Settings

UCSZ2

UCSZ1

UCSZ0

Character Size

0

0

0

5-bit

0

0

1

6-bit

0

1

0

7-bit

0

1

1

8-bit

1

0

0

Reserved

1

0

1

Reserved

1

1

0

Reserved

1

1

1

9-bit

• Bit 0 – UCPOL: Clock Polarity

154 ATmega8(L)

2486O–AVR–10/04


ATmega8(L)

USART Baud Rate Registers –

UBRRL and UBRRHs

This bit is used for Synchronous mode only. Write this bit to zero when Asynchronous mode is used. The UCPOL bit sets the relationship between data output change and data input sample, and the synchronous clock (XCK).

Table 59. UCPOL Bit Settings

Transmitted Data Changed (Output of

Received Data Sampled (Input on

UCPOL

TxD Pin)

RxD Pin)

0

Rising XCK Edge

Falling XCK Edge

1

Falling XCK Edge

Rising XCK Edge

Bit

15

14

13

12

11

10

9

8

URSEL

UBRR[11:8]

UBRRH

UBRR[7:0]

UBRRL

7

6

5

4

3

2

1

0

Read/Write

R/W

R

R

R

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

R/W

Initial Value

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

The UBRRH Register shares the same I/O location as the UCSRC Register. See the “Accessing UBRRH/UCSRC Registers” on page 149 section which describes how to access this register.

• Bit 15 – URSEL: Register Select

This bit selects between accessing the UBRRH or the UCSRC Register. It is read as zero when reading UBRRH. The URSEL must be zero when writing the UBRRH.

• Bit 14:12 – Reserved Bits

These bits are reserved for future use. For compatibility with future devices, these bit must be written to zero when UBRRH is written.

• Bit 11:0 – UBRR11:0: USART Baud Rate Register

This is a 12-bit register which contains the USART baud rate. The UBRRH contains the four most significant bits, and the UBRRL contains the eight least significant bits of the USART baud rate. Ongoing transmissions by the Transmitter and Receiver will be corrupted if the baud rate is changed. Writing UBRRL will trigger an immediate update of the baud rate prescaler.

155

2486O–AVR–10/04


Examples of Baud Rate

Setting

For standard crystal and resonator frequencies, the most commonly used baud rates for asynchronous operation can be generated by using the UBRR settings in Table 60. UBRR values which yield an actual baud rate differing less than 0.5% from the target baud rate, are bold in the table. Higher error ratings are acceptable, but the Receiver will have less noise resistance when the error ratings are high, especially for large serial frames (see “Asynchronous Operational Range” on page 146). The error values are calculated using the following equation:

Error[%] =

---------------BaudRate------------Closest----------------------------Match – 1

• 100%

BaudRate

Table 60. Examples of UBRR Settings for Commonly Used Oscillator Frequencies

Baud

fosc = 1.0000 MHz

fosc = 1.8432 MHz

fosc = 2.0000 MHz

U2X = 0

U2X = 1

U2X = 0

U2X = 1

U2X = 0

U2X = 1

Rate

(bps)

UBRR

Error

UBRR

Error

UBRR

Error

UBRR

Error

UBRR

Error

UBRR

Error

2400

25

0.2%

51

0.2%

47

0.0%

95

0.0%

51

0.2%

103

0.2%

4800

12

0.2%

25

0.2%

23

0.0%

47

0.0%

25

0.2%

51

0.2%

9600

6

-7.0%

12

0.2%

11

0.0%

23

0.0%

12

0.2%

25

0.2%

14.4k

3

8.5%

8

-3.5%

7

0.0%

15

0.0%

8

-3.5%

16

2.1%

19.2k

2

8.5%

6

-7.0%

5

0.0%

11

0.0%

6

-7.0%

12

0.2%

28.8k

1

8.5%

3

8.5%

3

0.0%

7

0.0%

3

8.5%

8

-3.5%

38.4k

1

-18.6%

2

8.5%

2

0.0%

5

0.0%

2

8.5%

6

-7.0%

57.6k

0

8.5%

1

8.5%

1

0.0%

3

0.0%

1

8.5%

3

8.5%

76.8k

1

-18.6%

1

-25.0%

2

0.0%

1

-18.6%

2

8.5%

115.2k

0

8.5%

0

0.0%

1

0.0%

0

8.5%

1

8.5%

230.4k

0

0.0%

-

250k

0

0.0%

Max (1)

62.5 kbps

125 kbps

115.2 kbps

230.4 kbps

125 kbps

250 kbps

1.UBRR = 0, Error = 0.0%

156 ATmega8(L)

2486O–AVR–10/04


ATmega8(L)

Table 61. Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued)

Baud

fosc = 3.6864 MHz

fosc = 4.0000 MHz

fosc = 7.3728 MHz

U2X = 0

U2X = 1

U2X = 0

U2X = 1

U2X = 0

U2X = 1

Rate

(bps)

UBRR

Error

UBRR

Error

UBRR

Error

UBRR

Error

UBRR

Error

UBRR

Error

2400

95

0.0%

191

0.0%

103

0.2%

207

0.2%

191

0.0%

383

0.0%

4800

47

0.0%

95

0.0%

51

0.2%

103

0.2%

95

0.0%

191

0.0%

9600

23

0.0%

47

0.0%

25

0.2%

51

0.2%

47

0.0%

95

0.0%

14.4k

15

0.0%

31

0.0%

16

2.1%

34

-0.8%

31

0.0%

63

0.0%

19.2k

11

0.0%

23

0.0%

12

0.2%

25

0.2%

23

0.0%

47

0.0%

28.8k

7

0.0%

15

0.0%

8

-3.5%

16

2.1%

15

0.0%

31

0.0%

38.4k

5

0.0%

11

0.0%

6

-7.0%

12

0.2%

11

0.0%

23

0.0%

57.6k

3

0.0%

7

0.0%

3

8.5%

8

-3.5%

7

0.0%

15

0.0%

76.8k

2

0.0%

5

0.0%

2

8.5%

6

-7.0%

5

0.0%

11

0.0%

115.2k

1

0.0%

3

0.0%

1

8.5%

3

8.5%

3

0.0%

7

0.0%

230.4k

0

0.0%

1

0.0%

0

8.5%

1

8.5%

1

0.0%

3

0.0%

250k

0

-7.8%

1

-7.8%

0

0.0%

1

0.0%

1

-7.8%

3

-7.8%

0.5M

0

-7.8%

0

0.0%

0

-7.8%

1

-7.8%

1M

0

-7.8%

Max (1)

230.4 kbps

460.8 kbps

250 kbps

0.5 Mbps

460.8 kbps

921.6 kbps

1.UBRR = 0, Error = 0.0%

157

2486O–AVR–10/04