Electronic – Serial Communication 8051

8051microprocessorserial

I am working on how 8051 performs serial communication. I couldn't figure out how both transmission and receive operations are performed by same register, SBUF.

To make it more clear, I will give an example. Assume that I'm receiving information through Rx pin continuously. What if I want to transmit information? How can I interrupt receiving while transmitting data because I don't want the data that I put in SBUF register to be replaced by the incoming data.

There were two bits in SCON, namely receive interrupt(RI) and transmit interrupt(TI), but they were used to check whether the data is received or transmitted succesfully, not to decide whether the chip is gonna transmit or receive.

What I'm asking is, shouldn't there be a bit in SCON like transmit enable or receive enable which allows one operation and inhibits the other when asserted. There is actually one receive enable(REN) in SCON but in all examples it was asserted both when transmitting and receiving so I thought this bit was for something else.

What is it I'm missing?

Best Answer

Assume that I'm receiving information through Rx pin continuously. What if I want to transmit information? How can I interrupt receiving while transmitting data because I don't want the data that I put in SBUF register to be replaced by the incoming data.

I understand your confusion. The explanation is quite an elegant design...

From outside the device, we treat the SBUF register as being a single "thing", used for Tx when we write to it, and used for Rx when we read from it. This makes sense, since we don't need to do the opposite (i.e. we don't need to read what we just sent to be transmitted).

However, inside the device, the Tx register and the Rx register are physically different components. That fact is what allows you to transmit while also receiving, without overwriting what is being received.

Long, long ago I remember reading the datasheet on one UART or another, which explained this. I'm not sure I could find it again, but if I do find it (or something similar) I'll add it to the answer.


Update:

From Atmel 8051 Microcontrollers Hardware Manual:

The serial port receive and transmit registers are both accessed at Special Function Register SBUF. Writing to SBUF loads the transmit register, and reading SBUF accesses a physically second receive register.

[my emphasis in the above quotation]

From the same document, here is a block diagram of the 8051 UART. I have outlined the two places where they show "SBUF" in red, along with text showing which is the physical Tx SBUF register, and which is the physical Rx SBUF register:

Extract from Atmel 8051 Microcontrollers Hardware Manual page 103