at89c51 sending junk through serial port

Status
Not open for further replies.

baftab

New Member
hi..am trying to send data through serial port of at89c51 to my pc
i send "re364 acknwlge" and the pc receives re364 acknwlge with some junk as subscript
i hav to turn on and off my controller several times before it sends the correct one



üre364 acknwlgere364 acknwlgere364 acknwlgere364 acknwlgeàre364 acknw
lgeðre364 acknwlgeàre364 acknwlge ü

the ones in bold are the garbage values send! help! how to overcome this problem
 
Write the correct code maybe
or use the correct hardware
maybe also be sure about the baud rate
or ... ...

With some code and hardware it would be easier to help you
 
here is the code

org 000h

mov r1,#30h ;bytes for ack
mov r3,#8 ;counter for ack
mov r0,#28h ;bytes for id tag
mov r4,#32 ;counter for id tag
mov r2,#10

mov p1,#00110011b
mov p2,#00110011b
mov p0,#00110011b

mov A,pcon
setb acc.7
mov pcon,A
mov tmod,#20h
mov th1,#-3
mov scon,#50h

setb tr1

again:mov DPTR,#rfid

h_1: clr A
movc A,@A+dptr
jz b_1
acall send
inc dptr
sjmp h_1

b_1: acall recv
mov p0,@r1
inc r1
djnz r3,b_1
sjmp verify

send:mov sbuf,A
h_2:jnb ti, h_2
clr ti
ret

recv: jnb ri,recv
mov A,sbuf
mov @r1, A
clr ri
ret

verify:

mov r1,#30h
mov p2,@r1
cjne @r1,#'a',bil
sjmp tag_id
bil:sjmp again ;if ack not recieved, send again

tag_id: mov r2,#10
mov r0,#28h ;to keep bytes from 28 to 32
loop:acall recv1
mov p0,@r0
inc r0
djnz r2,loop
djnz r4,tag_id
sjmp verify2

recv1: jnb ri,recv1
mov A,sbuf
mov @r0,A
clr ri
ret


verify2:
mov r0,#28h
cjne @r0,#'3',bil1
mov p1,#11100010b
;set a flag bit,assign space;check sensors
sjmp again
bil1: mov p1,#10010011b

org 0300h
rfid: DB "re364 acknwlge",0
end
 
Your baud rate is off a little. There could be several reasons for that - check your UART settings and clock source.
 
i am interfacing with a RFID reader...which works on 19200bps
so my baudrate is 19200

to check whether its transmitting correctly, i connected my at89c51 with hyper terminal
but found out tht its sending trash as the frst byte

using 11.0592M oscillator
 
It looks like you forgot to load TL1. With what you load in TH1 you won't get the right timer overflow rate for 19200.
 
Your initilisation lacks
Code:
	setb TI	;TI:   set TI to send first char of UART
Didn't check the rest of the code
 
I found that noise plays havoc on the 8051 and wireless. My circuit didn't work very reliably until I lowered the clock frequency.

I lowered the clock frequency from 11.0592 MHz to 4MHz, it made the world of difference in receiving errors. (providing your hardware, code and uart config is set up correctly)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…