# RS232

Status
Not open for further replies.

#### Spasm

##### New Member
Hey all,

Anyone can help me regarding data transmission? I've been using the 16f877 to send serial data thru UART and reading the data from windows hyper terminal. Every cycle of lets say 1 second, the PIC will send out the number 5 and 6. On the terminal side, every 1 second, the terminal will print out "5656565656565656565656" and sometimes it has shorter fives and sixes. Why is this so? The rate I'm sending for both side are 9600,N,8,1. Can anyone help?

Thank You

#### Nigel Goodwin

##### Super Moderator
Spasm said:
Hey all,

Anyone can help me regarding data transmission? I've been using the 16f877 to send serial data thru UART and reading the data from windows hyper terminal. Every cycle of lets say 1 second, the PIC will send out the number 5 and 6. On the terminal side, every 1 second, the terminal will print out "5656565656565656565656" and sometimes it has shorter fives and sixes. Why is this so? The rate I'm sending for both side are 9600,N,8,1. Can anyone help?

Thank You

There's a fair bit of info on RS232 in my tutorials at http://www.winpicprog.co.uk. Are you using a hardware or software USART?, and what actually are you trying to send?.

#### Spasm

##### New Member
Hi nigel,

The USART im using is built in the PIC(hardware). Therefore everytime i send, I just movwf into TXREG. The data I'm sending is a 8 bit timer1 value. I've tried using 7 bit value ascii "5s" and "6s" but it still comes out alot of fives and sixes at the PC terminal end. Dont really know why.

#### Nigel Goodwin

##### Super Moderator
Spasm said:
Hi nigel,

The USART im using is built in the PIC(hardware). Therefore everytime i send, I just movwf into TXREG. The data I'm sending is a 8 bit timer1 value. I've tried using 7 bit value ascii "5s" and "6s" but it still comes out alot of fives and sixes at the PC terminal end. Dont really know why.

What values are you putting in the setup registers?, these are the routines from my tutorial, using a 20MHz 16F876.
Code:
;USART Serial routines

SER_INIT
BSF     STATUS, RP0           ;select bank 1
MOVLW   d'129'                ;9600 baud @ 20 Mhz Fosc +0.16 err
MOVWF   SPBRG
MOVLW   b'00100100'           ;brgh = 1
MOVWF   TXSTA                 ;enable Async Transmission, set brgh
BCF     STATUS, RP0           ;select bank 0
MOVLW   b'10010000'
MOVWF   RCSTA                 ;enable Async Reception
RETURN

XMIT_RS232  	btfss   PIR1,	TXIF 	      ;xmit buffer empty?
GOTO	XMIT_RS232            ;no, wait
MOVWF   TXREG		      ;now send
RETURN

Rcv_RS232   	BTFSS   PIR1,	RCIF 	      ; check for received data
GOTO    Rcv_RS232
MOVF    RCREG,	W
RETURN

With a 4MHz clock SPBRG=25 and BRGH=1. I'm presuming you are using a MAX232 (or similar) for the interface, the hardware USART requires an inverter to feed RS232.

#### Spasm

##### New Member
Hi Nigel..

Yeap..exactly the same startup configuration. I'm using 4Mhz so SPBRG is 25. For transmission, I've used the same codes too. I've configured one of the PIC pins to blink a LED everytime there's transmission. An I've only seen one blink every cycle(nearly 1 second per cycle). But then terminal reads multiples of the same data(each blink).Any idea?

Thank you

#### Nigel Goodwin

##### Super Moderator
Spasm said:
Hi Nigel..

Yeap..exactly the same startup configuration. I'm using 4Mhz so SPBRG is 25. For transmission, I've used the same codes too. I've configured one of the PIC pins to blink a LED everytime there's transmission. An I've only seen one blink every cycle(nearly 1 second per cycle). But then terminal reads multiples of the same data(each blink).Any idea?

Thank you

You've got BRGH=1 as well I take it?.

You didn't mention how it's interfaced, are you using a MAX232?.

#### Spasm

##### New Member
Hi nigel,

Yeah....BRGH is 1....my interface chip is MAX233CPP..internal capacitors...should be okay i think...its the same with 232..hrmmm....

#### jem

##### Member
Could be a baud rate mismatch. Maybe you should try using a different terminal program, and disable all flow control. Try this one:

https://bray.velenje.cx/avr/terminal. I have successfully used it a lot of times, and it is good (except for some nag message from time to time, even though it is freeware).

Jem

Status
Not open for further replies.

Replies
8
Views
2K
Replies
10
Views
2K
Replies
12
Views
3K
Replies
3
Views
2K
Replies
8
Views
1K