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.

89S8252 Serial UART problem

Status
Not open for further replies.

CMOS

Advanced Member level 3
Advanced Member level 3
Joined
Jan 6, 2004
Messages
862
Helped
94
Reputation
186
Reaction score
50
Trophy points
1,308
Location
USA
Visit site
Activity points
5,673
Hi,
I am using AT89S8252 for my project which uses serial port @ 19.2kbps. The problem I am facing with this uC is that every character I send from uC to serial port is sent twice. No matter what baud rate or configuration I set. For example if I send 'x' it sends 'xx' to PC.
However if I put same code on AT89S52, it works just fine without any problems. Can anyone please help me?
Here is my code.
Code:
	ORL	PCON, #0x80	; SET DOUBLE BAUD RATE
	ANL	TMOD, #0x0F	; CLEAR ALL TIMER1 BITS IN TMOD
	ORL	TMOD, #0x20	; TIMER1  = 8 BIT AUTO RELOAD
	CLR	TR1		; MAKE SURE TIMER1 ISN'T RUNNING
	CLR	TF1
	MOV	A, #253
	MOV	TH1, A		; SET TIMER1 RATE
	MOV	TL1, A
	MOV	SCON, #0x50	; CONFIG SERIAL PORT
	SETB	TR1		; START TIMER1

	MOV	A,#'x'
	LCALL	COUT
	SJMP	*

;**************************************************************
; PRINTS CHARACTER IN ACC TO SERIAL PORT
;**************************************************************
COUT:	MOV	SBUF, A
	JNB	TI, *
	CLR	TI		;CLR TI AFTER SENDING
	RET
I am using AS31 assembler available at www.pjrc.com
I tried the same code in C using K*EIL demo but result is same.
Is there any architecture fault in 89S8252? Please help.

Thanks.
 

Sounds like echo to me. This works for me, needs altering from 300 baud to suit you application. Hope it helps?.

void serial_init (void) {
TMOD = 0x20; // Timer 1 mode 2: 8-Bit reload
TH1 = 0x98; // Reload value 300 baud
SCON = 0x52; // Mode 1: 8-bit UART, enable receiver TI remains set
TR1 = 1; // Timer 1 run
ES = 0; // Disable serial port interrupt
EA = 0; // Disable
}
 

No thats not echo, because data is sent from 89S8252 to PC. Even with your code, I am getting double characters.
 

Hi CMOS,

Please try changing your COUNT routine as follows:

COUNT: JNB TI, COUNT ; test if SBUF is free, so you can load the next byte
MOV SBUF, A ; load next byte
CLR TI ; Clears TI to start sending...
RET

When the byte has been sent the UART hardware will set the TI flag indicating that SBUF is free for you to send the next byte...

Hope it helps!
 

I cleared TI and RI flags during startup. and changed the COUT code. It solved my problem. Thanks
 

__JR__ wrote:

Hi CMOS,

Please try changing your COUNT routine as follows:

COUNT: JNB TI, COUNT ; test if SBUF is free, so you can load the next byte
MOV SBUF, A ; load next byte
CLR TI ; Clears TI to start sending...
RET

When the byte has been sent the UART hardware will set the TI flag indicating that SBUF is free for you to send the next byte...

Hope it helps!


Transmition is initiated when the CPU writes to SBUF, not when you clear bit TI. A better COUT routine is:

COUT: JNB TI,COUT
CLR TI
MOV SBUF,A ; start sending
RET

In previus COUT, if an interrupt happens between MOV SBUF,A and CLR TI, is possible that TI remains cleared forever. In this case, when you call to COUT, the CPU will execute always the instruction

COUT: JNB TI,COUT
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top