how to configure the individual registers for UART communication?

Thread Starter

Parth786

Joined Jun 19, 2017
642
I am reading a UART protocol. I understand we use UART when we have to send data from one device to another or we have to receive data from one device to another. We can transmit or receive data using UART protocol. For example: If I have 8051 and GPS module then I can send data to GPS or I can receive data from GPS module. We can do same with LCD, RFID module, PC

8051 has registers like TMOD, SCON, TH, TL, TCON. These are registers that are need to be configured to communicate over UART. I have read it TMOD register is use to set mode of timer0 and timer 1. TH and TL are used to set timer value.

I know I have to configure these registers. I don’t understand what value. I have to set in SCON, TH and TL registers ? and why I need to set only those value?. how to configure the individual registers for UART communication?

Note : Please correct me, If I am wrong somewhere in explanations
 
Last edited:

Thread Starter

Parth786

Joined Jun 19, 2017
642
I did Google before posting a thread. In the first two paragraphs I have explained what I have understood with example. In the last paragraph I have mentioned the problem which I do not understand. Besides, I also mentioned that if I misunderstood anything, then please tell me about my mistake.

I am reading the manual in this link http://www.keil.com/dd/docs/datashts/atmel/at89c51_ds.pdf but I don't understand

I have understood that I have to configure the registers. But how to configure the registers SCON, TH, TL, TCON for UART communication? I have seen some information on internet. But I do not understand the value that was given in links , Why they are using only that values?
 
Last edited:

Thread Starter

Parth786

Joined Jun 19, 2017
642
I seen the link given by you and also I have read another links but I am not sure what I understand is right or wrong. I have seen this common function everywhere
Code:
void UART_Init()
{
    TMOD  =  0x20;        /* Timer 1, 8-bit auto reload mode */
    TH1   =  0xFD;        /* Load value for 9600 baud rate */
    SCON  =  0x50;        /* Mode 1, reception enable */
    TR1   =  1;           /* Start timer 1 */
}
TMOD=0x20 ; This means that the timer 1 is set in mode 2. But I want to know we could also use timer 2 but why we are only using timer 1 and mode. Is there a special reason behind this ?

TR= 1 ; We will start the timer we are using. We are using timer 1 so we will start timer 1. Is this correct ?

calculate Baud rate
TH1 =0xFD;
TL1 =0xFD
I don’t understood here why TH1 has been used everywhere. But why is not use of TL1

Machine cycle frequency = 11.0592 MHz/ 12 = 921.6 kHz
Timer1 clock = 921.6 kHz / 32 = 28,800 Hz
Initial value in TH1 = 256 – (Timer1 clock / Required baud rate)

Example: For 9600 baud rate
TH1 = 256 – ( 28800/9600) = 256 –3 = 253 = FDh

SCON = 0x50 ; Why there is only 0x50 Is there a special reason behind this ?
 
Last edited:

nsaspook

Joined Aug 27, 2009
13,079
0: Read the Manual
1: Asking about what counter and mode it's possible to use with the UART, Go to 0:
2: Calculate Baud rate? These are basic digital design concepts for counters and how they can be used to divide a input frequency. If it's in a 8-bit counter mode then it can only be loaded with a 8-bit value not a 16-bit one. Go to 0:
3: SCON = 0x50? Go to 0:
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
0: Read the Manual
1: Asking about what counter and mode it's possible to use with the UART, Go to 0:
2: Calculate Baud rate? These are basic digital design concepts for counters and how they can be used to divide a input frequency. If it's in a 8-bit counter mode then it can only be loaded with a 8-bit value not a 16-bit one. Go to 0:
3: SCON = 0x50? Go to 0:
I have read the manual and after that I wrote the explanation. See the four points at starting. I wrote a few reasons and asked if these reasons are right or wrong. I did not understand last point SCON = 0x50?

I wanted to know that the reason given by is right or wrong. if it is wrong then what's the right reason
 

nsaspook

Joined Aug 27, 2009
13,079
I have read the manual and after that I wrote the explanation. See the four points at starting. I wrote a few reasons and asked if these reasons are right or wrong. I did not understand last point SCON = 0x50?

I wanted to know that the reason given by is right or wrong. if it is wrong then what's the right reason
That's very good. Now read the manual to see exactly what the bits [0..7]of the hex number 0x50 mean in the SCON (Serial port CONtrol) register.
http://www.idc-online.com/technical...egister_SCON_Of_8051_8031_Microcontroller.pdf
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
upload_2017-11-18_1-13-9.png

Bit 7 = 0 and Bit 6 =1 because I am using mode 1, to select Scon in mode 1 we make SM0=0 and SM1=1
Bit 5 = 0 This pin is use to enable multiprocessor communication. we are using single we will set it to 0
Bit 4 = 1 this is Receive Enable pin
Bit 3 = 0 Transmit Bit
bit 2 = 0 Receive Bit
bit 1 = 0 This is Transmit Interrupt Flag
bit 0 = 0 This is Receive Interrupt Flag

initially we have to load 0101 0000 = 0x50 in scon register. Is it correct ?
 

nsaspook

Joined Aug 27, 2009
13,079
View attachment 139533

Bit 7 = 0 and Bit 6 =1 because I am using mode 1, to select Scon in mode 1 we make SM0=0 and SM1=1
Bit 5 = 0 This pin is use to enable multiprocessor communication. we are using single we will set it to 0
Bit 4 = 1 this is Receive Enable pin
Bit 3 = 0 Transmit Bit
bit 2 = 0 Receive Bit
bit 1 = 0 This is Transmit Interrupt Flag
bit 0 = 0 This is Receive Interrupt Flag

initially we have to load 0101 0000 = 0x50 in scon register. Is it correct ?
Yes, Now, wasn't that easy? Stop saying you don't understand, start saying I will understand.
 
Top