Serial Port in 8051

There is a serial port in 8051 as mentioned in the pin diagram of 8051. 
8051 has capability to perform parallel as well as serial communication.

Parallel communication in 8051:

8051 can do 8-bit parallel communication as it has 8-bit ALU. For parallel communication, any of the ports ( P0 / P1 / P2 / P3 ) is used as a transmission channel between transmitter and receiver. 

Serial communication in 8051:

For serial communication there are two separate pins known as serial port of 8051.

Serial Port in 8051

TxD:

This pin basically acts as a transmitter ( sending data ), but in some other modes it doesn’t do the job of transmitter. As it is serial communication, it sends bit by bit, the processor gives 8-bit at 1 time and those 8-bits are stored in a register named SBUF. Processor gives 1 byte of data that is to be transmitted to SBUF and from there bit by bit is transferred , firstly LSB and then at last MSB of the byte stored in SBUF. Once the total byte is transmitted, an interrupt is sent to the processor by making some flag 1, so that the processor can send more data for transmission as soon as the interrupt is received. 

After every bit is transmitted, it requires delay for next bit transmission. So SBUF needs triggering which is provided by

  • Timer T1 ( here T1 only needs to trigger, T1 does not require its overflow flag , mode 3 in timers ). Here we can vary the delay, so data transmission delay can be varied ( frequency can be varied ). It has a variable baud rate.
  • There is an internal clock in 8051 ( fosc / 12 = 1Mhz ) , where delay cannot be varied, this has fixed trigger delay. So frequency cannot be varied.It has a fixed baud rate.

Whenever SBUF transferred 8bit of data , Ti flag becomes 1. Whenever processors go to ISR( in other interrupts the flag is auto cleared whenever processor goes to ISR ) , in this the Ti flag is not auto cleared.

RxD:

This pin is basically for data reception . It received data bit by bit ( as the transmitter sends LSB first, it received LSB first ). There is also a register SBUF which stores 8 received bits. Once the 8 bits are received, instead of sending an interrupt it firstly checks for errors ( errors caused due to transmission, how error is checked is discussed in upcoming tutorials ). Once there is no error in the received information Ri flag is set and an interrupt is sent to the processor. Processor goes to ISR ( here also Ri is not cleared automatically ).

How are SBUF in TxD and RxD different from each other ?

In SBUF of TxD, data is sent from processor to SBUF

In SBUF of RxD, data is sent from SBUF to the processor.

In this way both registers are differentiated by the processor.

There is a bit named SM2 ;

If SM2 = 1, then after SBUF of RxD is filled there will be error check
And if not then there will be no error check, directly an interrupt will be sent to the processor once SBUF in RxD is filled.

Modes in serial communication:

Mode 1 ( 8-bit UART communication ):

UART stands for universal asynchronous receiver-transmitter. It means receiver and transmitter are asynchronous which mean they don’t have a common clock. Normally 8 bits are transmitted through the channel, but in this mode 10 bits are transmitted. 

Serial Port in 8051

Here start and stop bits are system generated.

Significance of start and stop bit:

For eg: There is a transmitter and receiver. First C8H ( 1100 1000 ) data is transmitted and then for 10min there is no transmission and after that again 8EH ( 1000 1110 )is transmitted.

If there is no transmission, last bit transmitted would be remained in the channel

Serial Port in 8051

Receiver assumes blue data ( when there was no communication ) also as data. 

Serial Port in 8051

Here green is the start bit which is zero. And then the yellow colored is stop bit which is 1. Whenever the first 0 bit comes, the receiver discards the start bit and accepts the next 8 bits and stores in SBUF. Then the 9th bit is 1 , this bit is stored in RB8 ( will be discussed later ). Then after this whenever the next zero bit comes ( that zero bit is discarded and accepts the next 8 bits and so on ).

Serial Port in 8051

Stop bit is also used for error checking. Whenever SM2=1, It checks for error, If the RB8 = 1 ( which means stop = 1 received, so the data is received correctly ) and if RB8=0 ( transmitter generated stop as 1, but received as 0 ) so there is an error. If there is an error in received data, no interrupt is sent to the processor.

This mode is variable baud rate, which means it is triggered by timer 1.

Mode 2 ( 9-bit UART communication ):

Serial Port in 8051

The 9th bit is a programmable bit and it is given through TB8. Here 9th bit is 1 and it is used for error checking and stop bit for triggering the data high ( so start bit gets 0 and so on ).

Why the 9th bit , when the already stop bit exists?
Standard value of 9th bit is 1 and can be made 0.
Whenever SM2 = 1( receiver accepts only errorless data ) and if 9th bit is 1, then only errorless data is accepted or else discarded. Discarding data is a purpose.

Eg: For broadcast all the receivers should receive data, in this case 9th bit = 1, so that if the receiver has SM2 = 1 or 0, it can receive data.

For selected transmission ( a paid channel in setup box ), in this case 

If the person paid for the premium channel ( the paid channel’s 9th bit = 0 )

His setup box’s SM2 = 0

So that he can receive data

If the person didn’t pay for that paid channel

His setup box’s SM2 = 1 ( checks for error )

So he cannot receive data because it has error ( here error is not an error, according to receiver the premium channel has error and dont show it )

This has a huge application in daily life.

This mode also has varied frequency, it has varied baud rate.

Mode 3 ( 9-bit UART communication ):

This mode is completely similar to mode 2, in mode 2 for triggering timer is used Whereas in this mode internal clock is used for triggering. It has a fixed baud rate. 

Mode 0 :

Totally there were four modes in serial port of 8051, but for better understanding mode 0 is explained after three modes. In this mode data is transferred and received only through the RxD channel. TxD is used for clocks. This is synchronous mode of communication. 

Such a system is also known as half duplex mode. It has fixed baud rate.

SCON register:

SCON register in 8051 , serial port in 8051

SM0 and SM1:

These are used to select the mode.

SM0SM1Mode
000
011
102
113

SM2:
If SM2 = 1, error is checked
Or else no error checking is done.

REN:
Receiver enable, If REN=1, receiver will receive the data or else not.

TB8:
This is the 9th bit to be transmitted.

RB8:
This is the 9th bit to be received.

Ti :
When 8-bits are received in SBUF , then Ri = 1, that would send an interrupt to the processor. 

Ri :
When 8-bits are sent from SBUF,and SBUF is empty , then Ri = 1, that would send an interrupt to the processor. Before Ri=1, it checks for error based on SM2.

Read other topics:
Timer section in 8051
Introduction to 555 IC with a simple application

Spread knowledge

Leave a Comment

Your email address will not be published. Required fields are marked *