Searching \ for '[PIC]: Serial issues with PIC16F873A' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=serial
Search entire site for: 'Serial issues with PIC16F873A'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Serial issues with PIC16F873A'
2003\02\14@083234 by Tim

flavicon
face
Hello again,

I’m trying to get a P16F873A and a PC talking via a serial connection,
and am getting some unusual and frustrating results…

On the PC, I’m using both HyperTerminal and a custom bit of C to talk to
the PIC. Both are set to 19200bps, 8bit, no handshake, no parity, 1 stop bit. Seeing same results on both pieces of software…

On the PIC I’m using Tony Kübek's code for the 16F876: (I’ve also used
his 877 code on an 877 with no problems…)
http://www.piclist.org/techref/microchip/16f876-hint-tk.htm

What’s happening is this:
When I send something to the PIC, it *always* receives decimal 128, no
matter what I send to it (I have a routine to print the received byte to
an LCD in decimal).
When I have the PIC send data back, the PC *always* receives decimal
255. No matter what I tell it to send, 0xff is always received.

Now the fun part:
Short the PC’s rx/tx together, and data is echoed back correctly... send
0x02, receive 0x02...
Short the PIC’s rx/tx together (output side of the MAX233A) and tell it
to send 0x03, 0x03 is received back (same routine to print to the lcd).

I have triple-checked the code on the PIC, everything appears in order.
The shorting of rx/tx seems to confirm this I would imagine. All
hardware has
Been double checked, and the grounds of both the PC and the PIC are
connected together.

I don’t believe it to be noise, it's too consistent.

Anyone have any idea what’s going on? I’m at a total loss on this one
and my heard starting to hurt after 5 hours of continuously banging my
head on the work bench.

Thanks,
Tim

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@084241 by Wouter van Ooijen

face picon face
> Anyone have any idea what's going on? I'm at a total loss on this one
> and my heard starting to hurt after 5 hours of continuously banging my
> head on the work bench.

- wrong baudrate?
- wrong polarity?

NB http://www,voti.nl/wisp628 has example programs (for 16f877, should
work on an 873) that receive a char and send back the hex representatig
(IIRC). Use this to check your hardware and PC software, if that works
start blaming your PIC code?

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@084453 by michael brown

picon face
Hello again,

>I'm trying to get a P16F873A and a PC talking via a serial connection,
>and am getting some unusual and frustrating results.

Everything sound normal at this point.  ;-)

>What's happening is this:
>When I send something to the PIC, it *always* receives decimal 128, no
>matter what I send to it (I have a routine to print the received byte
to
>an LCD in decimal).
>When I have the PIC send data back, the PC *always* receives decimal
>255. No matter what I tell it to send, 0xff is always received.

Sounds like the baud rates don't match to me.

>Now the fun part:
>Short the PC's rx/tx together, and data is echoed back correctly...
send
>0x02, receive 0x02...
>Short the PIC's rx/tx together (output side of the MAX233A) and tell it
>to send 0x03, 0x03 is received back (same routine to print to the lcd).

Right, I bet the PIC and the PC are each operating at a different baud
rate.  If you have a scope, just look at the signals coming out of the
PIC.  My guess is that the PIC is at something close to 1200 baud.

Are you using a crystal speed that matches the example code?  Are you
bit-banging the serial, or using the USART?  Are you checking for
framing errors on the PIC.

michael brown

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@084703 by Olin Lathrop

face picon face
> When I send something to the PIC, it *always* receives decimal 128,
> ...
> When I have the PIC send data back, the PC *always* receives
> decimal 255.

This sounds like a major baud rate mismatch.  the PIC is set to about 8
times slower than the PC.  The PIC receives the stop bit on the first data
bit, then 0s after that.  the PC receives the start bit for the whole
byte.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@084918 by Tim

flavicon
face
Bitrate and polarity appear to both be correct.

-----Original Message-----
From: pic microcontroller discussion list
[EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU] On Behalf Of Wouter van Ooijen
Sent: Friday, February 14, 2003 5:41 AM
To: PICLISTspamspam_OUTMITVMA.MIT.EDU
Subject: Re: [PIC]: Serial issues with PIC16F873A

> Anyone have any idea what's going on? I'm at a total loss on this one
> and my heard starting to hurt after 5 hours of continuously banging my
> head on the work bench.

- wrong baudrate?
- wrong polarity?

NB http://www,voti.nl/wisp628 has example programs (for 16f877, should
work on an 873) that receive a char and send back the hex representatig
(IIRC). Use this to check your hardware and PC software, if that works
start blaming your PIC code?

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@085119 by Tim

flavicon
face
Got the xtal freq correct, using the USART, and checking for framing
errors. Still no go

-----Original Message-----
From: pic microcontroller discussion list
[RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU] On Behalf Of michael brown
Sent: Friday, February 14, 2003 5:45 AM
To: spamBeGonePICLISTspamBeGonespamMITVMA.MIT.EDU
Subject: Re: [PIC]: Serial issues with PIC16F873A

Hello again,

>I'm trying to get a P16F873A and a PC talking via a serial connection,
>and am getting some unusual and frustrating results.

Everything sound normal at this point.  ;-)

>What's happening is this:
>When I send something to the PIC, it *always* receives decimal 128, no
>matter what I send to it (I have a routine to print the received byte
to
>an LCD in decimal).
>When I have the PIC send data back, the PC *always* receives decimal
>255. No matter what I tell it to send, 0xff is always received.

Sounds like the baud rates don't match to me.

>Now the fun part:
>Short the PC's rx/tx together, and data is echoed back correctly...
send
>0x02, receive 0x02...
>Short the PIC's rx/tx together (output side of the MAX233A) and tell it
>to send 0x03, 0x03 is received back (same routine to print to the lcd).

Right, I bet the PIC and the PC are each operating at a different baud
rate.  If you have a scope, just look at the signals coming out of the
PIC.  My guess is that the PIC is at something close to 1200 baud.

Are you using a crystal speed that matches the example code?  Are you
bit-banging the serial, or using the USART?  Are you checking for
framing errors on the PIC.

michael brown

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@085742 by Tim

flavicon
face
Sounds like everyone's yellin baud rate. This is what I have (snippets):

#define XTAL_FREQ       D'20000000'     ; OSC freq in Hz, 20mhz
#define BAUD_RATE       19200           ; Desired baud rate

; caulculates baudrate when BRGH = 0, adjust for rounding errors
#define CALC_LOW_BAUD(BaudRate)
(((10*XTAL_FREQ/(64*BaudRate))+5)/10)-1



INIT_UART
       ; make sure pins are setup before calling this routine
       ; TRISC:6 and TRISC:7 must be set ( as for output, but operates
as input/output )
       ; furthermore its advised that interrupts are disabled during
this routine

       ; setup baudrate
       MOVLW   SPBRG                   ; get adress for serial baud reg
       MOVWF   FSR                     ; setup fsr
       MOVLW   CALC_LOW_BAUD(BAUD_RATE) ; get baudrate
       MOVWF   INDF                    ; and store it

       ; enable transmitter
       MOVLW   TXSTA                   ; get adress for serial enable
reg
       MOVWF   FSR                     ; setup fsr
       MOVLW   (1<<TXEN)               ; preset enable transmitter and
low speed mode
       MOVWF   INDF                    ; and set it

       ; enable recevier
       MOVLW   (1<<SPEN)|(1<<CREN)     ; preset serial port enable and
continous recevie
       MOVWF   RCSTA                   ; set it

       ; enable reciever interrupt
       MOVLW   PIE1                    ; get adress for periphial irq's
       MOVWF   FSR                     ; setup fsr
       BSF     INDF,RCIE               ; enable reciever irq
       BSF     INTCON,PEIE             ; and periphial irq must also be
enabled

       movf    RCREG,W                 ; clear uart receiver
       movf    RCREG,W                 ; including fifo
       movf    RCREG,W                 ; which is three deep.

       RETURN


Think that's all the important parts, the rest goes by the original
example


{Original Message removed}

2003\02\14@095739 by Olin Lathrop

face picon face
> Sounds like everyone's yellin baud rate. This is what I have (snippets):

You could also try letting my UART_BAUD macro calculate the UART setup.
It is in the STD.INS.ASPIC file at http://www.embedinc.com/pic.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservEraseMEspam.....mitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@104829 by erholm (QAC)

flavicon
face
Mixed up rx and tx at one end ?
Jan-Erik Soderholm

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@115606 by Dwayne Reid

flavicon
face
At 05:55 AM 2/14/03 -0800, Tim wrote:
>Sounds like everyone's yellin baud rate. This is what I have (snippets):
>
>#define XTAL_FREQ       D'20000000'     ; OSC freq in Hz, 20mhz
>#define BAUD_RATE       19200           ; Desired baud rate
>
>; caulculates baudrate when BRGH = 0, adjust for rounding errors
>#define CALC_LOW_BAUD(BaudRate)
>(((10*XTAL_FREQ/(64*BaudRate))+5)/10)-1

Have a look at how you have defined the baud rate above.  Try: D'19200'
.  Notice the difference?

dwayne

--
Dwayne Reid   <RemoveMEdwaynerEraseMEspamEraseMEplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 19 years of Engineering Innovation (1984 - 2003)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspam_OUTspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@115835 by Dwayne Reid

flavicon
face
At 05:55 AM 2/14/03 -0800, Tim wrote:
>Sounds like everyone's yellin baud rate. This is what I have (snippets):
>
>#define XTAL_FREQ       D'20000000'     ; OSC freq in Hz, 20mhz
>#define BAUD_RATE       19200           ; Desired baud rate
>
>; caulculates baudrate when BRGH = 0, adjust for rounding errors
>#define CALC_LOW_BAUD(BaudRate)
>(((10*XTAL_FREQ/(64*BaudRate))+5)/10)-1

Further to my previous comment: the calculation above assumes decimal
radix.  Is it?  If not, you have to specify radix for each of the constants
used.

dwayne

--
Dwayne Reid   <RemoveMEdwaynerTakeThisOuTspamspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 19 years of Engineering Innovation (1984 - 2003)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspamspamspamBeGonemitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@133845 by Robert Rolf

picon face
Using the given formula, decimal baud comes out to 162. In the hex case, it's
30,
which is a long way off.

Did you bother to look at the actual value that you code calculated? That
would be the easiest proof of the problem. Create an intermediate constant,
and then use that in the baud setting instruction, and then you'll see where
you're going wrong.

And wasn't there a 'feature' in MPLAB where it couldn't handle large values
during intermediate calculations? (Integer size limits?)

Robert


Dwayne Reid wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservSTOPspamspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@153857 by Brent Brown

picon face
Check the actual SPBRG value used, for 19200 baud at 20MHz use:-

SPBRG = 64 (decimal)
BRGH = 1

I have a spreadsheet that works out the above. Gives 19231 baud wich
is 0.16% error.

As your loop back test, works and assuming the above is OK, scope
your TxD to see what is really happening and also check your 20MHz
crystal is running at the right speed.

I like using a more flexible PC comms program than hyperterminal,
like this one: http://bray.velenje.cx/avr/terminal

--
Brent Brown, Electronic Design Solutions
16 English Street, Hamilton, New Zealand
Ph/fax: +64 7 849 0069
Mobile/txt: 025 334 069
eMail:  KILLspambrent.brownspamBeGonespamclear.net.nz

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body

2003\02\17@050427 by Alan B. Pearce

face picon face
>I like using a more flexible PC comms program than hyperterminal,
>like this one: http://bray.velenje.cx/avr/terminal

Actually when I got fed up with hyperterminal (which did not take long) I
grabbed a Win3.1 system and copied Terminal.exe and terminal.hlp over, and
it runs fine on a Win2k system. Not tried it on an exotic com port number,
or USB port, but it works OK on Com1 or 2.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...