Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Baur rate of AT89S52

Status
Not open for further replies.

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
Baut rate of AT89S52

Hi guys. Currently trying to figure out how to calculate the baud rate of my AT89S52 mcu.
From the data sheet (http://www.atmel.com/Images/doc4316.pdf), there's this formula to calculate the baud rate:
Formula.png

Then there's this table:
table.png
Is the table showing the BRL value which we can get from the formula?

I tried to use the formula given to calculate the BRL using Fosc=11.0592Mhz and 9600 baud rate, but I couldn't get the value from the table which is FDh. What I get is FAh. Why is it? Please help guys.
 
Last edited:

I'm trying to use the 9600 baud rate with a 20Mhz xtal. The value given in the table shows I must use F5h and the SMOD=1. But there's SMOD0 and SMOD1 registers. What is the value for SMOD0 and SMOD1 if SMOD=1?
 

I'm trying to use the 9600 baud rate with a 20Mhz xtal. The value given in the table shows I must use F5h and the SMOD=1. But there's SMOD0 and SMOD1 registers. What is the value for SMOD0 and SMOD1 if SMOD=1?

SM0 = 0
SM1 = 1

:wink:
IanP
 
  • Like
Reactions: DrWhoF

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Why is it is SM0 and SM1 instead of SMOD0 and SMOD1?
 

Why is it is SM0 and SM1 instead of SMOD0 and SMOD1?

Notation depends on teacher/book/school ..
SM0=SMOD0
SM1=SMOD1
for lazier people, less letters ...

:wink:
IanP
 

Attachments

  • 8051 SCON.png
    8051 SCON.png
    84.8 KB · Views: 57
  • Like
Reactions: DrWhoF

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Notation depends on teacher/book/school ..
SM0=SMOD0
SM1=SMOD1
for lazier people, less letters ...

:wink:
IanP

Noted.
I want to use it in 9600 baud rate on timer 1. So, I put SCON = 80h and TH1=F5h. But it won't work.
When I try on 4800 baud rate which is SCON=00h and TH1=F5h. It work!
Do you guys know what's wrong?
 

Noted.
I want to use it in 9600 baud rate on timer 1. So, I put SCON = 80h and TH1=F5h. But it won't work.
When I try on 4800 baud rate which is SCON=00h and TH1=F5h. It work!
Do you guys know what's wrong?

There is a confusion here; let’s explain it ---
SMOD is bit 7 of PCON register and when set to “0” {SMOD=0} divides 1/12 of the clock frequency by 32.
When set to “1” {SMOD=1} divides 1/12 of the clock frequency by 16.
This is still within the PCON register.

SM0 and SM1 are bits of the SCON register.
Don’t confuse SMOD with SMs …

As far as the setting for 9600bps goes, serial mode1 is set by SM0=o and SM1=1, that makes the SCON register set to #50h (with the REN bit also set to “1”), not #80h.
The TMOD register should be set to #20h …
And bit7 of PCON (SMOD) set to “1” …
9600= 2 x 20MHz /[32 x12 x (256-TH1)]
TH1 =10.8 --- closest 11--- 0xf5
Something like:
Code:
MOV A, PCON                                ;A P CON
SET B ACC.7                                 ;make D7 = 1
MOV PCON, A                                 ;SMOD = 1, double baud rate
MOV TMOD, #20 H                        ;Timer 1 mode 2, auto reload
MOV THI,#0F5 H                                        
MOV SCON, #50 H

Now it should work …

:wink:
IanP
 
  • Like
Reactions: DrWhoF

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
There is a confusion here; let’s explain it ---
SMOD is bit 7 of PCON register and when set to “0” {SMOD=0} divides 1/12 of the clock frequency by 32.
When set to “1” {SMOD=1} divides 1/12 of the clock frequency by 16.
This is still within the PCON register.

SM0 and SM1 are bits of the SCON register.
Don’t confuse SMOD with SMs …

As far as the setting for 9600bps goes, serial mode1 is set by SM0=o and SM1=1, that makes the SCON register set to #50h (with the REN bit also set to “1”), not #80h.
The TMOD register should be set to #20h …
And bit7 of PCON (SMOD) set to “1” …
9600= 2 x 20MHz /[32 x12 x (256-TH1)]
TH1 =10.8 --- closest 11--- 0xf5
Something like:
Code:
MOV A, PCON                                ;A P CON
SET B ACC.7                                 ;make D7 = 1
MOV PCON, A                                 ;SMOD = 1, double baud rate
MOV TMOD, #20 H                        ;Timer 1 mode 2, auto reload
MOV THI,#0F5 H                                        
MOV SCON, #50 H

Now it should work …

:wink:
IanP

I've tried your code but still don't work.

I try to use 4800 baud rate by only writing:
Code:
MOV TMOD, #20 H                        
MOV THI,#0F5 H                                        
MOV SCON, #50 H
This worked.

But after adding your code to do 9600 baud rate:
Code:
MOV A, PCON                              
SET B ACC.7                               
MOV PCON, A
MOV TMOD, #20 H                        
MOV THI,#0F5 H                                        
MOV SCON, #50 H
It won't work. Do you know what's wrong? What should I check again?
Is it that this mcu is not suitable to use 20Mhz xtal? This is because I search examples from websites and most of it uses 11.0592Mhz xtal.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top