Continue to Site

# Serial PIC[ler:(]

Status
Not open for further replies.

#### Wond3rboy

##### Member
Serial PIC[ler]

Hi i was just checking out the UART tool of the Pickit2 and got it to work perfectly once but now am not getting correct data
Here are a few questions that i want to ask:

As SPBRG register contains a value that does not give you the exact Baudrate what effect does this have on the actual transmission?

Also what happens because of the BR error?

Take the example of the code given below:

Code:
LIST P=18F1320
INCLUDE <P18F1320.INC>
CONFIG OSC=INTIO2,WDT=OFF,LVP=OFF
Org 0
movlw 7F
MOVLW B'01100000'
MOVWF OSCCON
CLRF TRISB,TX
CLRF TRISB,RX
MOVLW D'12'
MOVWF SPBRG
MOVLW B'00100000'
MOVWF TXSTA
BSF RCSTA,SPEN

START:

MOVLW HIGH(D)
MOVWF TBLPTRH
MOVLW LOW(D)
MOVWF TBLPTRL
REPEAT:

TBLRD*+
MOVF TABLAT,W
BZ START
MOVWF TXREG
AGAIN:

BTFSS PIR1,TXIF
BRA AGAIN

BRA REPEAT

D:
DB "SYED",0

END

The oscilator is the internal oscillator 4MHz and the SPBRG value for 4800(since it gives the least error) is 12.

The error calculated is .15% so how does it end up as...every 10000 characters will have 15 corrupted characters?

I mean what the error implies?

Thanks.

Last edited:

#### Wond3rboy

##### Member
Man!! Atleast someone could have replied

#### ericgibbs

##### Well-Known Member
Man!! Atleast someone could have replied

hi W3,
If the baud rate is not within the specified limits, you will most likely get corrupt data at the receiver.

Even though the baud rate is not precise.
ie a small percentage off, the UART can easily sync on the RS232 bits, so no data is lost
If you stay within the small percentages shown on the datasheet the data will be OK.

I'll look thru your settings and get back to you.

EDIT:
https://extremeelectronics.co.in/avr-tutorials/rs232-communication-the-basics/

Last edited:

#### Nigel Goodwin

##### Super Moderator
Asyncronous resyncronises every byte, this is what start and stop bits are for. This was discussed recently here, and I think the permissible error was something like 5%, with no data lost.

#### Russ Hensel

##### New Member
The internal ossc is not very accurate, check the data sheet, perhaps try a crystal.

#### Nigel Goodwin

##### Super Moderator
The internal ossc is not very accurate, check the data sheet, perhaps try a crystal.

I think you're missing the point?, he doesn't have a problem - he was merely concerned about the possible implications of the UART running at a slightly different frequency (and there are no implications).

#### Wond3rboy

##### Member
Thanks everyone.All programs work very well on Proteus. Single byte transmission works well but when i send a complete sentence or a name then some letters(again works like a charm in proteus) are like 'eaten' i-e they dont appear and it skips them. Where as i havent changed the connections, even havnt taken out the wires! All the connections were same. I think i am missing something.

Last edited:

#### Nigel Goodwin

##### Super Moderator
I would suggest trying it without the table and loop for a start (simple linear sequence of MOVLW and serial output). This will show if it's a problem with your table reading or not.

It's also a good idea to check if the TXREG is empty before you write to it, check my tutorial example.

Last edited:

#### Russ Hensel

##### New Member
I think you're missing the point?, he doesn't have a problem - he was merely concerned about the possible implications of the UART running at a slightly different frequency (and there are no implications).

he said: "but now am not getting correct data" which I tought was a problem.

#### Nigel Goodwin

##### Super Moderator
he said: "but now am not getting correct data" which I tought was a problem.

But he doesn't have a problem with the internal oscillator, it looks more like a coding problem.

Status
Not open for further replies.

Replies
4
Views
2K
Replies
8
Views
565
Replies
42
Views
4K
Replies
30
Views
2K
Replies
5
Views
692