Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC USART-HyperTerminal problem..

Status
Not open for further replies.

asp1987

New Member
Hi..
I am trying to make an sms based appliance control system using pic and an old nokia mobile(fbus). I was trying to see if the pic was sending out correct bytes by connecting it to hyperterminal at 115200 baud rate. The program was to send 128 'U's and then the following bytes in order:
1E 00 0C D1 00 07 00 01 00 03 00 01 60 00 72 D5...
HT showed this.
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

Ñ`rÕ

The 'U's are correct but others i don't understand..A program XVI32 showed this 'Ñ`rÕ' as D1 01 03 01 60 72 D5.Also the last character of 'U' sequence as 1E.
Why are the other bytes missing?

Please help.. I don't know how to interpret these..
 
asp1987 said:
I was trying to see if the pic was sending out correct bytes by connecting it to hyperterminal at 115200 baud rate. The program was to send 128 'U's and then the following bytes in order:Why are the other bytes missing?
Are you using the internal oscillator? 115200 is pretty demanding for timing. The internal might not be accurate enough. Try it at a lower baud rate.
 
Thanks for the reply...
I am using PIC 16F887, at 18.432 MHz(external osc). Its datasheet says a value of 0x27(39 dec) to SPBRG gives the required baud rate with 0% error.. If that was a problem, then there should have been some problems with receiving the 'U's,right?
I interfaced the circuit to the nokia 3510i but didn't get any response.
Please help.
 
Last edited:
asp1987 said:
Thanks for the reply...
I am using PIC 16F887, at 18.432 MHz(external osc). Its datasheet says a value of 0x27(39 dec) to SPBRG gives the required baud rate with 0% error.. If that was a problem, then there should have been some problems with receiving the 'U's,right?
I interfaced the circuit to the nokia 3510i but didn't get any response.
Please help.
With a crystal 115200 should be fine. But still test it at lower baud and see what happens. What does your serial send routine look like? Are you waiting for the busy flag to clear before sending the next char?
 
asp1987 said:
I am using PIC 16F887, at 18.432 MHz(external osc). Its datasheet says a value of 0x27(39 dec) to SPBRG gives the required baud rate with 0% error..

Post your initialization routine. You have to load the SPBRG register with 39 if SYNC = 0, BRGH = 1, BRG16 = 1 or SYNC = 1, BRG16 = 1. We need to know how you set those bits.
 
This is my 'Send' routine.. It loads a byte to 'w' register and then calls the sendU routine..

sendU
movwf TXREG
bsf STATUS,RP0 ; ROUTINE RESPONSIBLE FOR TRANSMISSION
Wait
btfss TXSTA,TRMT
goto Wait
bcf STATUS,RP0
return

Yes.I think Nokia needs a level converter.Its fbus signals are 2.7V max.. But now i am connecting phone Tx pin to uC directly and uC Tx to phone via a voltage divider network. Hope the pic will accept 2.7V as logic high.

Thanks again..
 
What you actually meant to say was:
Code:
sendU	movwf	TXREG
	bsf	STATUS,RP0	;ROUTINE RESPONSIBLE FOR TRANSMISSION
Wait	btfss	TXSTA,TRMT
	goto	Wait
	bcf	STATUS,RP0
	return
 
start
; remaining code goes here
bcf STATUS,RP0
bcf STATUS,RP1 ;BANK0
bcf INTCON,GIE
bsf STATUS,RP0 ;BANK1
movlw 0x00
movwf TRISA
movwf TRISB
movwf TRISC
movwf TRISD
movwf TRISE
movlw 0x00
movwf SPBRGH
movlw 0x27 ; 0x27=39(dec) for 18.432 MHz crystal with 0% error!!
movwf SPBRG ; 0x2A(42 dec) for 20 MHz with 0.94% error.
movlw b'00100100';
movwf TXSTA
bsf STATUS,RP0
bsf STATUS,RP1 ;BANK3
movlw b'00001000'
movwf BAUDCTL
movlw 0x00
movwf ANSEL
movwf ANSELH
bcf STATUS,RP0
bcf STATUS,RP1 ;BANK0
movlw b'10010000'
movwf RCSTA
clrf PIR1
bsf STATUS,RP0 ; BANK1
bsf PIE1,RCIE ; ENABLE INTERRUPT ON RECEIVE
bcf STATUS,RP0 ; BANK0
bsf INTCON,PEIE ;enable Peripheral interrupts
bsf INTCON,INTE ;enable RB0/INT interrupts
bsf INTCON,GIE
;---------------------------------------

Thank you....
 
sendU movwf TXREG
bsf STATUS,RP0 ;ROUTINE RESPONSIBLE FOR TRANSMISSION
Wait btfss TXSTA,TRMT
goto Wait
bcf STATUS,RP0
return
;----------------------
Yes.thats what i meant.'ll try it put it that way now onwards..
 
Yes.thats what i meant.'ll try it put it that way now onwards..
Like this :D :
Code:
start	bcf	STATUS,RP0
	bcf	STATUS,RP1	;BANK0
	bcf	INTCON,GIE
	bsf	STATUS,RP0	;BANK1
	movlw	0x00
	movwf	TRISA
	movwf	TRISB
	movwf	TRISC
	movwf	TRISD
	movwf	TRISE
	movlw	0x00
	movwf	SPBRGH
	movlw	0x27		;0x27=39(dec) for 18.432 MHz crystal with 0% error!!
	movwf	SPBRG		;0x2A(42 dec) for 20 MHz with 0.94% error.
	movlw	b'00100100'
	movwf	TXSTA
	bsf	STATUS,RP0
	bsf	STATUS,RP1	;BANK3
	movlw	b'00001000'
	movwf	BAUDCTL
	movlw	0x00
	movwf	ANSEL
	movwf	ANSELH
	bcf	STATUS,RP0
	bcf	STATUS,RP1	;BANK0
	movlw	b'10010000'
	movwf	RCSTA
	clrf	PIR1
	bsf	STATUS,RP0	;BANK1
	bsf	PIE1,RCIE	;ENABLE INTERRUPT ON RECEIVE
	bcf	STATUS,RP0	;BANK0
	bsf	INTCON,PEIE	;enable Peripheral interrupts
	bsf	INTCON,INTE	;enable RB0/INT interrupts
	bsf	INTCON,GIE
 
Last edited:
I spit on 115200. Use 800Kbps no problem :) Loving the through put.
 
Code:
sendU              movwf TXREG
                   bsf STATUS,RP0 ;ROUTINE RESPONSIBLE FOR TRANSMISSION
Wait               btfss TXSTA,TRMT
                   goto Wait
                   bcf STATUS,RP0
                   return
like this?
 
Code:
sendU              movwf TXREG
                   bsf STATUS,RP0 ;ROUTINE RESPONSIBLE FOR TRANSMISSION
Wait               btfss TXSTA,TRMT
                   goto Wait
                   bcf STATUS,RP0
                   return
 
I tried transmitting at 9600 baud by loading 0x1DF(479 dec). still HT shows the same result.
Help please..
 
asp1987 said:
I tried transmitting at 9600 baud by loading 0x1DF(479 dec). still HT shows the same result.
Help please..
Here's a typical set of routines for 16F628. Should be pretty similar.
Code:
;************************** 
;* init RS232 at 9600,8,N,1 
rs232init:
	banksel	SPBRG		;bank 1
	movlw	0x19		;0x19=9600 baud 
	movwf	SPBRG 
	movlw	b'00100100' 	;brgh = high 
	movwf	TXSTA		;enable async transmit 
	banksel	RCSTA		;bank 0
	movlw	b'10010000'	;enable async receive 
	movwf	RCSTA 
	call	Delay		;startup settle time 
	return 

;****************************************** 
;* Wait for a char from RS232 - return in W
receive:
	btfss	PIR1,RCIF	;wait for a byte from RS232 
	goto	receive
	movf	RCREG,W		;return received byte in W
	return 

;************************* 
;* Send char in W to RS232 
transmit:
	movwf	TXREG		;transmit byte in W 
	banksel	TXSTA		;bank 1
send1:	btfss	TXSTA,TRMT	;transmission done? 
	goto	send1		;no, then go again 
	banksel	PORTA		;bank 0
	return			;yes, done
 
Hey...solved the problem.
Actually there was nothing wrong with the PIC.:) ..A guy from another website said that HT cannot display all bytes as characters n another guy suggested me to use a program called 'SERIAL WATCHER'.It shows all the received characters in hex format.Tried it and it worked. Haven't tried the codes with the phone yet.
Anyway thanks to you all..i learned how to post a code..:D
 
Status
Not open for further replies.

Latest threads

Back
Top