ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 02.06.2025
Просмотров: 3595
Скачиваний: 0
ATmega8(L)
Table 53. Recommended Maximum Receiver Baud Rate Error for Normal Speed Mode (U2X = 0)
D# |
Max Total |
Recommended Max |
||
(Data+Parity Bit) |
Rslow(%) |
Rfast(%) |
Error (%) |
Receiver Error (%) |
5 |
93,20 |
106,67 |
+6.67/-6.8 |
± 3.0 |
6 |
94,12 |
105,79 |
+5.79/-5.88 |
± 2.0 |
7 |
94,81 |
105,11 |
+5.11/-5.19 |
± 2.0 |
8 |
95,36 |
104,58 |
+4.58/-4.54 |
± 2.0 |
9 |
95,81 |
104,14 |
+4.14/-4.19 |
± 1.5 |
10 |
96,17 |
103,78 |
+3.78/-3.83 |
± 1.5 |
Table 54. Recommended Maximum Receiver Baud Rate Error for Double Speed Mode (U2X = 1)
D# |
Max Total |
Recommended Max |
||
(Data+Parity Bit) |
Rslow(%) |
Rfast(%) |
Error (%) |
Receiver Error (%) |
5 |
94,12 |
105,66 |
+5.66/-5.88 |
± 2.5 |
6 |
94,92 |
104,92 |
+4.92/-5.08 |
± 2.0 |
7 |
95,52 |
104,35 |
+4.35/-4.48 |
± 1.5 |
8 |
96,00 |
103,90 |
+3.90/-4.00 |
± 1.5 |
9 |
96,39 |
103,53 |
+3.53/-3.61 |
± 1.5 |
10 |
96,70 |
103,23 |
+3.23/-3.30 |
± 1.0 |
The recommendations of the maximum Receiver baud rate error was made under the assumption that the Receiver and Transmitter equally divides the maximum total error.
There are two possible sources for the Receivers Baud Rate error. The Receiver’s system clock (XTAL) will always have some minor instability over the supply voltage range and the temperature range. When using a crystal to generate the system clock, this is rarely a problem, but for a resonator the system clock may differ more than 2% depending of the resonators tolerance. The second source for the error is more controllable. The baud rate generator can not always do an exact division of the system frequency to get the baud rate wanted. In this case an UBRR value that gives an acceptable low error can be used if possible.
147
2486O–AVR–10/04
Multi-processor
Communication Mode
Using MPCM
Setting the Multi-processor Communication mode (MPCM) bit in UCSRA enables a filtering function of incoming frames received by the USART Receiver. Frames that do not contain address information will be ignored and not put into the receive buffer. This effectively reduces the number of incoming frames that has to be handled by the CPU, in a system with multiple MCUs that communicate via the same serial bus. The Transmitter is unaffected by the MPCM setting, but has to be used differently when it is a part of a system utilizing the Multi-processor Communication mode.
If the Receiver is set up to receive frames that contain 5 to 8 data bits, then the first stop bit indicates if the frame contains data or address information. If the Receiver is set up for frames with nine data bits, then the ninth bit (RXB8) is used for identifying address and data frames. When the frame type bit (the first stop or the ninth bit) is one, the frame contains an address. When the frame type bit is zero the frame is a data frame.
The Multi-processor Communication mode enables several Slave MCUs to receive data from a Master MCU. This is done by first decoding an address frame to find out which MCU has been addressed. If a particular Slave MCU has been addressed, it will receive the following data frames as normal, while the other Slave MCUs will ignore the received frames until another address frame is received.
For an MCU to act as a Master MCU, it can use a 9-bit character frame format (UCSZ = 7). The ninth bit (TXB8) must be set when an address frame (TXB8 = 1) or cleared when a data frame (TXB = 0) is being transmitted. The Slave MCUs must in this case be set to use a 9-bit character frame format.
The following procedure should be used to exchange data in Multi-processor Communication mode:
1.All Slave MCUs are in Multi-processor Communication mode (MPCM in UCSRA is set).
2.The Master MCU sends an address frame, and all slaves receive and read this frame. In the Slave MCUs, the RXC Flag in UCSRA will be set as normal.
3.Each Slave MCU reads the UDR Register and determines if it has been selected. If so, it clears the MPCM bit in UCSRA, otherwise it waits for the next address byte and keeps the MPCM setting.
4.The addressed MCU will receive all data frames until a new address frame is received. The other Slave MCUs, which still have the MPCM bit set, will ignore the data frames.
5.When the last data frame is received by the addressed MCU, the addressed MCU sets the MPCM bit and waits for a new address frame from Master. The process then repeats from 2.
Using any of the 5- to 8-bit character frame formats is possible, but impractical since the Receiver must change between using n and n+1 character frame formats. This makes full-duplex operation difficult since the Transmitter and Receiver uses the same character size setting. If 5- to 8-bit character frames are used, the Transmitter must be set to use two stop bit (USBS = 1) since the first stop bit is used for indicating the frame type.
Do not use Read-Modify-Write instructions (SBI and CBI) to set or clear the MPCM bit. The MPCM bit shares the same I/O location as the TXC Flag and this might accidentally be cleared when using SBI or CBI instructions.
148 ATmega8(L)
2486O–AVR–10/04
Accessing
UBRRH/UCSRC
Registers
Write Access
2486O–AVR–10/04
ATmega8(L)
The UBRRH Register shares the same I/O location as the UCSRC Register. Therefore some special consideration must be taken when accessing this I/O location.
When doing a write access of this I/O location, the high bit of the value written, the USART Register Select (URSEL) bit, controls which one of the two registers that will be written. If URSEL is zero during a write operation, the UBRRH value will be updated. If URSEL is one, the UCSRC setting will be updated.
The following code examples show how to access the two registers.
Assembly Code Examples(1)
...
; Set UBRRH to 2
ldi r16,0x02
out UBRRH,r16
...
;Set the USBS and the UCSZ1 bit to one, and
;the remaining bits to zero.
ldi r16,(1<<URSEL)|(1<<USBS)|(1<<UCSZ1) out UCSRC,r16
...
C Code Examples(1)
...
/* Set UBRRH to 2 */
UBRRH = 0x02;
...
/* Set the USBS and the UCSZ1 bit to one, and */
/* the remaining bits to zero. */
UCSRC = (1<<URSEL)|(1<<USBS)|(1<<UCSZ1);
...
Note: 1. The example code assumes that the part specific header file is included.
As the code examples illustrate, write accesses of the two registers are relatively unaffected of the sharing of I/O location.
149
Read Access |
||||||
Doing a read access to the UBRRH or the UCSRC Register is a more complex opera- |
||||||
tion. However, in most applications, it is rarely necessary to read any of these registers. |
||||||
The read access is controlled by a timed sequence. Reading the I/O location once |
||||||
returns the UBRRH Register contents. If the register location was read in previous sys- |
||||||
tem clock cycle, reading the register in the current clock cycle will return the UCSRC |
||||||
contents. Note that the timed sequence for reading the UCSRC is an atomic operation. |
||||||
Interrupts must therefore be controlled (e.g., by disabling interrupts globally) during the |
||||||
read operation. |
||||||
The following code example shows how to read the UCSRC Register contents. |
||||||
Assembly Code Example(1) |
||||||
USART_ReadUCSRC: |
||||||
; Read UCSRC |
||||||
in |
r16,UBRRH |
|||||
in |
r16,UCSRC |
|||||
ret
C Code Example(1)
unsigned char USART_ReadUCSRC( void )
{
unsigned char ucsrc; /* Read UCSRC */ ucsrc = UBRRH; ucsrc = UCSRC; return ucsrc;
}
Note: 1. The example code assumes that the part specific header file is included.
The assembly code example returns the UCSRC value in r16.
Reading the UBRRH contents is not an atomic operation and therefore it can be read as an ordinary register, as long as the previous instruction did not access the register location.
USART Register
Description
USART I/O Data Register –
UDR
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
RXB[7:0] |
UDR (Read) |
||||||||
TXB[7:0] |
UDR (Write) |
||||||||
Read/Write |
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 |
|
The USART Transmit Data Buffer Register and USART Receive Data Buffer Registers share the same I/O address referred to as USART Data Register or UDR. The Transmit Data Buffer Register (TXB) will be the destination for data written to the UDR Register location. Reading the UDR Register location will return the contents of the Receive Data Buffer Register (RXB).
For 5-, 6-, or 7-bit characters the upper unused bits will be ignored by the Transmitter and set to zero by the Receiver.
150 ATmega8(L)
2486O–AVR–10/04
USART Control and Status
Register A – UCSRA
2486O–AVR–10/04
ATmega8(L)
The transmit buffer can only be written when the UDRE Flag in the UCSRA Register is set. Data written to UDR when the UDRE Flag is not set, will be ignored by the USART Transmitter. When data is written to the transmit buffer, and the Transmitter is enabled, the Transmitter will load the data into the Transmit Shift Register when the Shift Register is empty. Then the data will be serially transmitted on the TxD pin.
The receive buffer consists of a two level FIFO. The FIFO will change its state whenever the receive buffer is accessed. Due to this behavior of the receive buffer, do not use Read-Modify-Write instructions (SBI and CBI) on this location. Be careful when using bit test instructions (SBIC and SBIS), since these also will change the state of the FIFO.
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
RXC |
TXC |
UDRE |
FE |
DOR |
PE |
U2X |
MPCM |
UCSRA |
|
Read/Write |
R |
R/W |
R |
R |
R |
R |
R/W |
R/W |
|
Initial Value |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
• Bit 7 – RXC: USART Receive Complete
This flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e. does not contain any unread data). If the Receiver is disabled, the receive buffer will be flushed and consequently the RXC bit will become zero. The RXC Flag can be used to generate a Receive Complete interrupt (see description of the RXCIE bit).
• Bit 6 – TXC: USART Transmit Complete
This flag bit is set when the entire frame in the Transmit Shift Register has been shifted out and there are no new data currently present in the transmit buffer (UDR). The TXC Flag bit is automatically cleared when a transmit complete interrupt is executed, or it can be cleared by writing a one to its bit location. The TXC Flag can generate a Transmit Complete interrupt (see description of the TXCIE bit).
• Bit 5 – UDRE: USART Data Register Empty
The UDRE Flag indicates if the transmit buffer (UDR) is ready to receive new data. If UDRE is one, the buffer is empty, and therefore ready to be written. The UDRE Flag can generate a Data Register Empty interrupt (see description of the UDRIE bit).
UDRE is set after a reset to indicate that the Transmitter is ready.
• Bit 4 – FE: Frame Error
This bit is set if the next character in the receive buffer had a Frame Error when received (i.e., when the first stop bit of the next character in the receive buffer is zero). This bit is valid until the receive buffer (UDR) is read. The FE bit is zero when the stop bit of received data is one. Always set this bit to zero when writing to UCSRA.
• Bit 3 – DOR: Data OverRun
This bit is set if a Data OverRun condition is detected. A Data OverRun occurs when the receive buffer is full (two characters), it is a new character waiting in the Receive Shift Register, and a new start bit is detected. This bit is valid until the receive buffer (UDR) is read. Always set this bit to zero when writing to UCSRA.
• Bit 2 – PE: Parity Error
This bit is set if the next character in the receive buffer had a Parity Error when received and the parity checking was enabled at that point (UPM1 = 1). This bit is valid until the receive buffer (UDR) is read. Always set this bit to zero when writing to UCSRA.
• Bit 1 – U2X: Double the USART transmission speed
151