Sunteți pe pagina 1din 9

Serial Communication

2.4

Serial communication using USART 2.4.1 2.4.1.1 Registers Explained

Serial Communications 2.4


Serial communication is the process of sending multiple bits of data over a single wire. It is an offshoot of the original telegraph, in which the bits were the dots and dashes of Morse code. The bits of a serial byte are separated by time so that the receiving device can determine the logic levels of each bit. Serial communication using USART -2.4.1
.USART stands for Universal Synchronous Asynchronous Receiver Transmitter
The USART is used to communicate from the microcontroller to various other devices. other microcontrollers that need to communicate to control a system, or a PC that is communicating with the microcontroller to complete a task. The usual form of serial communication, and the form that we used , is asynchronous serial communication. It is asynchronous in the sense that a common clock signal is not required at both the transmitter and the receiver in order to synchronize the data detection. Asynchronous Serial communication uses a start bit and a stop bit added to the data byte to allow the receiver to determine the timing of each bit. Figure 2.4.1 shows the elements of a standard asynchronous serial communication byte. This gure shows both the waveform and a denition for each bit of the serial word . The serial transmit line idles at a logic 1 and drops to zero to indicate the beginning of the start bit. The start bit takes one full bit time and is followed by the eight bits of the data byte that appear on the serial line , that is, the least signicant bit appears rst and the most signicant bit appears last. The stop bit follows the most signicant data bit and is a logic 1, the same level as the idle state. Fortunately, all of the timing relative to the serial byte formatting, the sampling of the serial bits, and the addition of the start stop bits are handled automatically by the universal synchronous asynchronous receiver-transmitter

Figure 2.4.1: Serial Byte Format

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.4.1.1 Registers Explained


1_USART Data Register "UDR": Actually this is not one but two register but when you
read it you will get the data stored in receive buffer and when you write data to it goes into the transmitters buffer.

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

Figure 2.4.3: USART Control and Status Register B

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

Figure 2.4.4 : USART Mode Select

USBS: USART Stop Bit Select - This bit selects the number of stop bits in the data transfer.

USBS 0 1

Stop Bit(s) 1 BIT 2 BIT

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

figure 2.4.6 : USART Character size

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

USART Control and Status Register B

2.4.4

USART Stop Bit Select

2.4.5 2.4.6

USART Stop Bit Select USART Character size

4 6

S-ar putea să vă placă și