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.

8051 micro with max232 serial communication problem

Status
Not open for further replies.

bimalkamal

Member level 1
Joined
Nov 27, 2011
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,529
I am trying to send a character from At89S52 mc to my PC through com1 port. All I am getting is garbage. My schematic, code, screen shots of output (both putty and Hyper Terminal), picture of DB9 female port is given. (The com1 port of PC is working fine as I use that port for my pic programmer.)
Thanks in advance

#include<8051.h>
main(){
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;​
while(1){
SBUF='M';
while(TI==0);
TI=0;
}​
}

circuit_232.jpgport.gifscreen_putty.PNGscreen_hyt.PNG
Hyperterminal settings:-
Bits per Sec:4800
Data bits:8
H/W Flowcontrol:none
Pairty:none
Stop bits:1
 
Last edited:

try this:

Code:
{
tmod=0x20;
scon=0x50;
tl1=0xfa;
th1=0xfa;
tr1=1;
while ...
}

:wink:
IanP
 

Connect ground wire to pin 5 of db9
 

DB9 pin 5 has already been connected to Ground.

The code as suggested by IanP gives the same result in putty but Hyperterminal showing "9b"
TMOD=0x20;
SCON=0x50;
TL1=0xfa;
TH1=0xfa;
TR1=1;
while(1){
SBUF='M';
while(TI==0);
TI=0;
}
 

try this

1. check one character at a time


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
TMOD=0x20;
SCON=0x50;
TL1=0xfa;
TH1=0xfa;
TR1=1;
 
SBUF='M';
while(TI==0);
TI=0;
 
while(1){
}




2. Introduce small delay between two sending sequence.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
TMOD=0x20;
SCON=0x50;
TL1=0xfa;
TH1=0xfa;
TR1=1;
while(1){
SBUF='M';
 
put some delay here
 
while(TI==0);
TI=0;
}

 

Second code with SBUF=0x41; giving output 'b'.
 

HI:
c51 code is ok!
/ / Crystal 11.0592 4800 baud
but you code no delay
=================
#include<8051.h>
main(){
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;
while(1){
SBUF='M';
while(TI==0);
TI=0;
delay code
}
}

Good luck!!
 

#include<8051.h>
main(){
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;
while(1){
SBUF='M';
while(TI==0);
TI=0;
MSDelay(300);
}
}

Same output. Only showing 'b' in Hyperterminal. It appears that whatever change I make. I see only 'b'. Apart from hyperterminal, I have also used putty and Uart.exe.
Uart.exe displays - ASCII char -â Decimal - 226 Hex - 0xE2
 

try sending different characters, also check your hardware again
 

check your RS232 (Pin5.) must connect GND!!
 

Now The code is :-
#include<8051.h>
#include<delay.c>
void sendx(unsigned char x);

main(){
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;

while(1){
sendx('a');
sendx('b');
sendx('c');
sendx('A');
sendx('B');
sendx('C');
}
}

void sendx(unsigned char x){
SBUF=x;
while(TI==0);
TI=0;
DelayMs(200);

}

And The output in Hyperterminal:-
àááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééà
ááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàááèééàáá
èééàááèééàááèééàááèééàááèééàááèééà
 

One common bug in RS232 communication with PC, is not matched baudrates. So verify that the baudrate from PC's side is the same as the baudrate from MCU's side. Since you are getting wrong characters in hyperterminal, this could be a possible reason.
 


check ur connection like this...may be this will help...
 



check ur connection like this...may be this will help...

First of all it is good to post the datasheet for reference.
MAX232 pdf, MAX232 description, MAX232 datasheets, MAX232 view ::: ALLDATASHEET :::

Used capacitors must have a value of 100nF, but you are using 10uF.
On RS232 connector, pin 2 and 3 signals should be inverted with each other (unless you don't use a cross cable). Except from pins 2, 3 and 5 on this connector, you don't need other connections. I can't tell if the extra connections you are using there, are right or wrong. I have never wired anything else on a DB9 except those three pins I mentioned.

Furthermore it is a common habit to use T1 with R1 together and T2 with R2 together. I suppose it will work with your way also, but never seen this kind of connection before.
I hope I didn't miss something, please change your circuit according to datasheet.
 

Don't give any kind of delay while using hyper terminal...
cut the delay function from the program and then try it again.
If you still not getting the o/p then I'll send you the files to do so.

All The Best :)
 

Which compiler are you using?

I am getting this.
 

Attachments

  • ss44.jpg
    ss44.jpg
    111 KB · Views: 112
Last edited:

HEllo Everyone

I am also getting same kind of problem and the possible reason, Which I have understood is as follows. The Mode 1 of SMOD serial Communication, frames the bit as 10 bit frame 1 start, 8 data bit and 1 stop bit. bUt the hyper terminal assumes 9 bit frame 8-data bit and 1 stop bit. So we should make the frame size same to have communication.

BUt ALAS....>! I have checked hardware manual 8051, and I have not got any solution in which 10 bit frame could be readjusted to 9 bit .

Any help is much appreciated....!
 

I too experienced Hyperterminal working to by fishy. Other software work far better.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top