Serial Communication
How is the data transferred serially? This has been shown in the figure below illustrating how a byte is transferred.
Suppose we wish to transfer 01000001 serially (as shown above, this is the ASCII value of letter ‘A’). The byte is placed between a start bit and a stop bit. Sometimes we can also have two start bits. The stop bit allows the receiver to organize the data before the next byte is send. So in total we have 10 bits that are transferred one by one, but at receiving end we have to decode the information i.e. remove the stop bit and pack the 8 bits into a byte for storage.
The serial data is transferred through a serial cable (with a DB9 pin socket). Let’s discuss the important characteristics of data transfer for 8051.

SBUF Register: The data is transferred via TxD line (P3.1) and received through RxD (P3.0) line in 8051. The data transferred via TxD line must be placed in SBUF register for its transfer and similarly while receiving through RxD the data is received in the SBUF register.
SCON (Serial control) Register:

a.) Mode selection
- The different modes of serial communication can be set by setting the values of SM0 & SM1.
- There are four modes; we will be discussing here only mode one.
- The mode1 can be selected by setting SM0=0 & SM1=1
- The first mode allows the baud rate (discussed below) to be variable.
- It has one start and one stop bit.
b.) REN (receive enable): If we wish to both transfer and receive, we can set REN= 1 otherwise receiving can be disabled by making REN= 0.
c.) SM2, TB8, RB8: are set to zero in mode 1
d.) TI (transmit interrupt): when 8051 finishes the transfer; it raises this flag to indicate that it is ready for transfer of another byte.
e.) RI (receiving interrupt): when the data is received serially via RxD, it gets rid of start and stop bit and the byte is placed in SBUF register. Then the RI flag is raised to indicate that a byte has been received and should be picked.
Rate of data transmission (baud rate):
The rate of transfer and reciving can be changed by a programmer. This is done with the help of ‘timer1’.
crystal frequency ÷12=machine cycle
machine cycle÷32=baud rate
In case we are using a crystal of frequency 11.0592MHz; machine cycle frequency = 921.6 KHz; baud rate= 28,800 Hz. To set timer1 to this baud rate we have to program it in mode2 (8 bit auto-reload).
To set a particular baud rate what should be the value of TH1->
- TH1=?
Let’s discuss this with an example. Suppose we wish to set ‘9600’ baud rate:
- 28,800/9600= 3;
- TH1= -3 or FD hex.

Numbering of DB9 or serial port:

(Note that we have to ground the pin number 5 for transmission of data)
Are serial port of computer and microcontroller logically equivalent?
1.) The computer works on RS232 logic:-
- logic 1 = -3V to -25V
- logic 0 = +3V to + 25V
2.) The microcontroller works on TTL logic:-
- logic 1= 5V
- logic zero= 0V
3.) An IC MAX232 (or MAX233) that can convert the RS232 logic to TTL logic is used.

TRANSFER OF DATA
The program below will keep on transferring string “YES” serially at a baud rate of 4800 continuously.


RECEIVING DATA
Let’s write a program to receive data and send it to port 1. We can use an 8-bit display or a LCD to display the output.
Note:- In the above two examples the baud rate is different just to show how you can use different baud rates in your own program. While writing a program baud rate should be same on both transmitter and receiver side.
- 2377 reads



Comments
18 February 2009
5 hours 14 min
Hi kapil,
You need a AT89S52 Serial Programmer for that. Which programmer are you using right now?
24 February 2010
6 weeks 17 hours
i wana do burn my at89s52 serialy.......so what can i do for that......
12 April 2009
1 week 1 day
you can then connect your module with a serial port of computer and by using the hyperterminal program you can check whether the same data is being received or not. If you need more detail as to how to do this let me know. I ll post the details.
12 April 2009
1 week 1 day
the easiest way is short circuit ur transmitter pin and receiver pin using a wire and check if the same data is being sent back to the device which is originally being transmitted. have you tried this out?
6 October 2009
28 weeks 4 days
i am facing a problem in cc2500 module
i am not getting that how can i check that my data is transmitting or receiving.
and can you give me some of the links related to test the data transmission and receiving as soon as possible................................
15 March 2009
1 year 3 weeks
Ok tkanx for the response... keep posting...
21 February 2009
24 weeks 1 day
These are two different and separate examples to give a better understanding as to how to incorporate different baud rates. But to make things more clear an additional note has been added. Yes for a particular set of communication baud rates at both sides should be synchronised.
21 February 2009
24 weeks 1 day
Thank you for pointing this error out. That line was mis-typed. It has been corrected now.
15 March 2009
1 year 3 weeks
Receiving and transmitting at diffrent Baud Rates... IS it justified...
15 March 2009
1 year 3 weeks
Please correct this line...The mode1 can be selected by setting SM=0 & SM=1