Documente Academic
Documente Profesional
Documente Cultură
2.4
The serial information is independent of the medium being used to carry the serial information. The medium may consist of a wire, a radio link, or other means. The most common medium is dened as RS-232. It was developed in order to provide agreater distance for reliable serial communication using wire to carry the signal. RS-232 is an inverted scheme, in that a logic 1 is represented by a negative voltage more negative than 3 V and a logic 0 is represented by a positive voltage more positive than +3 V. Using a different nonzero voltage for each logic level allows some hardware error checking ,because a broken line will present 0 V at the receiver and so may be detected. Most microcontroller toPC communication is RS-232.
The USART interface consists of three registers. These are the USART control and status register, the USART baud rate register, and the USART data register. These registers may be either 8 or 16 bits in length depending on the USART contained in theprocessor being used. In the ATMega8535, for normal asynchronous operation, the USART control and status register is a 16-bit register consisting of two 8-bit registers, UCSRA and UCSRB, and the USART baud rate register is a 16-bit register consisting of UBRRH and UBRRL, which are the high and low bytes, respectively, of UBRR.For other modes of operation an additional USART control and status register, UCSRC, is also available. Regardless of the processor type, the UDR is actually two registers sharing a single I/O address. One is a read-only register and one is a write-only register. The read-only register contains any serial byte received, and the write-only register contains any serial byte to be transmitted. So, when a program reads the UDR, it is reading the receiver UDR to get data that has been received serially. When the program writes to the transmitter UDR, it is writing data to be serially transmitted. 2
2_ USART Control and status Register A" UCSRA" it is used to configure the USART and it also stores some status about the USART. There are two more of this kind the UCSRB and UCSRC.
No of bit Name
7 RXC
6 TXC
5 UDRE
4 FE
3 DOR
2 PE
1 U2X
0 MPCM
Figure 2.4.2: USART Control and Status Register A Bit definition RXC this bit is set(1) when the USART has completed receiving a byte from the host (may be your PC) and the program should read it from UDR TXC This bit is set (1) when the USART has completed transmitting a byte to the host and your program can write new data to USART via UDR UDRE : ready to send Bit No Name 7 URSEL 6 UMSEL 5 UPM1 4 UPM0 3 USBS 2 UCSZ1 1 UCSZ0 0 UCPOL
Bit definition URSEL: USART register select. UMSEL: USART Mode Select - This bit selects between asynchronous and synchronous mode. As asynchronous mode is more popular with USART we will be using that. UMSEL 0 1 Mode Asynchronous Synchronous
USBS: USART Stop Bit Select - This bit selects the number of stop bits in the data transfer.
USBS 0 1
Figure 2.4.5 : USART Stop Bit Select UCSZ: USART Character size - These three bits (one in the UCSRB) selects the number of bits of data that is transmited in each frame
UCSZ2 0 0 0 0 1 1 1 1
UCSZ1 0 0 1 1 0 0 1 1
UCSZ0 0 1 0 1 0 1 0 1
Character Size 5Bit 6Bit 7Bit 8Bit Reserved Reserved Reserved 9Bit
3-UBRR: USART Baud Rate Register: This is the USART Baud rate register, it is 16BIT wide so UBRRH is the High Byte and UBRRL is Low byte. But as we are using C language it is directly available as UBRR and compiler manages the 16BIT access. This register is used by the USART to generate the data transmission at specified speed UBRR value is calculated according to following formula. UBRR= (fso /16*Baud Rate)
Where fso is cpu frequency and Baud Rate is the communication speed
Table of Figures figure 2.4.1 2.4.2 name Serial Byte Format USART Control and Status Register A Page number 2 3
2.4.3
2.4.4
2.4.5 2.4.6
4 6