Searching \ for '16F873 Uart transmission problem' 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/devices.htm?key=16F
Search entire site for: '16F873 Uart transmission problem'.

Truncated match.
PICList Thread
'16F873 Uart transmission problem'
2000\05\10@144507 by Don Campbell

flavicon
face
Hi all,

I having this problem with the PIC16F873 Uart.
I can receive data without any problems, but can't send.  The goal is to
read some buttons and send the info to the PC  (the pic also drives an
LCD character display, which works fine).

I am currently trying to debug the code using MPLAB 4.12 (I know that
5.00 is available, but haven't got around to getting it yet)
According to the datasheet from microchip, setting the TXEN bit
(TXSAT<5>) should set TXIF (PIR<4>) if the TXREG is empty.  This isn't
happening, and I can't figure out why not.

Any help that people can offer would be greatly appreciated, as I have
already tried the largest hammer available in the lab, with no
improvement.....

Thanks,
Don

Problematic code:
START
      call   INIT_COM_PORT
OUT
      movlw  a'A'
      movwf  TXREG
      goto   $

;--------------------------------------------------------------
;       Set up the comm port and interupts
INIT_COM_PORT
      bcf    INTCON,GIE
      bsf    PORTC,6

      bsf    STATUS,RP0
      clrf   TRISA
      clrf   TRISB
      movlw  0x80               ;RB7 as input
      movwf  TRISC
      bcf    STATUS,RP0

      bsf    RCSTA,SPEN         ;Enable Serial port
      bsf    RCSTA,CREN

      bsf    STATUS,RP0
      movlw  d'129'             ;9600bps
      movwf  SPBRG
      bcf    TXSTA,SYNC         ;asynch
      bsf    TXSTA,BRGH         ;9600bps
      bsf    TXSTA,TXEN         ; This is where the problem lies
                                ; With this line, PIR1<4>
                                ; should be set
                                ; But isn't....
      bsf    PIE1,RCIE
      bcf    STATUS,RP0

      bsf    INTCON,PEIE
      clrf   TXREG

      RETURN

      END

2000\05\10@164645 by M. Adam Davis

flavicon
face
I understand that the TXIF bit is NOT set unless the UART has emptied the TXREG
itself.  The data sheet doesn't make this blaringly clear, but if you read it
again I think you'll see that this is the process the UART follows.

In other words:

Power up
Set TXEN
Put a byte into TXREG
 At this point, the UART moves the byte from TXREG into its transmit buffer
 THEN checks to see if TXREG is empty.  If so, it sets TXIF.

So the only time the micro changes the TXIF bit is just before it sends a byte.
Solution?  Send a dummy byte, or assume the TXREG is empty when you first power
up.

I think you'll find that TXIF is, in fact, set right after your CLRF TXREG at
the end.

I hope this helps!

-Adam

Don Campbell wrote:
{Quote hidden}

2000\05\10@183927 by Brian Kraut

picon face
Check out Fr. Tom's tutorial on PIC UARTs before you make all of the
mistakes we already did.  Can't find the URL right now.  Can someone help me
out.

Don Campbell wrote:

{Quote hidden}

2000\05\10@190441 by Kelly J Kohls

picon face
Don,

At the start of your init routine, you cleared the GIE bit.  This bit
needs to be set along with the TXIE bit.  The UART won't be able to
generate an interrupt unless TXIE, GIE and PEIE (which you did set) bits
are set.  Hope this helps.  BTW, TXIE is the transmit interrupt enable.

Kelly Kohls, N5TLE
Dallas, TX
Email:  spam_OUTkkohlsTakeThisOuTspamjuno.com  OR  .....n5tleKILLspamspam@spam@qsl.net  OR n5tlespamKILLspamarrl.net
Homepage:  http://www.qsl.net/n5tle/

________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
dl.http://www.juno.com/get/tagj.

2000\05\10@211525 by Don Campbell
flavicon
face
Kelly J Kohls wrote:
>
> Don,
>
> At the start of your init routine, you cleared the GIE bit.  This bit
> needs to be set along with the TXIE bit.  The UART won't be able to
> generate an interrupt unless TXIE, GIE and PEIE (which you did set) bits
> are set.  Hope this helps.  BTW, TXIE is the transmit interrupt enable.
>
<snip>

I wasn't using interupts for trasnsmission, only reception...the init
code sets up both.  The TXIF bit is _supposed_ to be set either
way...according to the doc anyway...

2000\05\10@223950 by Kelly J Kohls

picon face
Don,

One other thing I should have mentioned is that both pins 6 and 7 of port
C must be set as input.  I know, that sounds funny, but for some reason
that's the way Microchip designed the UART.  I don't know if this has
anything to do with your interrupt flag problem, but who knows?

Kelly Kohls, N5TLE
Dallas, TX
Email:  .....kkohlsKILLspamspam.....juno.com  OR  EraseMEn5tlespam_OUTspamTakeThisOuTqsl.net  OR n5tlespamspam_OUTarrl.net
Homepage:  http://www.qsl.net/n5tle/

________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
dl.http://www.juno.com/get/tagj.

2000\05\10@230355 by Tony Nixon

flavicon
picon face
Kelly J Kohls wrote:
>
> Don,
>
> One other thing I should have mentioned is that both pins 6 and 7 of port
> C must be set as input.  I know, that sounds funny, but for some reason
> that's the way Microchip designed the UART.  I don't know if this has
> anything to do with your interrupt flag problem, but who knows?

Can't agree with that. I have never set PORTC that way and have never
had any problems.

--
Best regards

Tony

http://www.picnpoke.com
@spam@salesKILLspamspampicnpoke.com

2000\05\10@230534 by Tony Nixon

flavicon
picon face
One thing I had a bit of trouble with was trying to send data directly
after enabling the serial port. I had to insert a small delay after
initializing and then send.

something like

       ; enable serial TX

       clrf temp
loop    decfsz temp
       goto loop

       movlw 'X'
       movwf txreg

       ; etc

I also seemed to have trouble with the UART if I disabled it and then
re-enabled it later for use without powering down. Haven't nailed that
one yet.

--
Best regards

Tony

http://www.picnpoke.com
KILLspamsalesKILLspamspampicnpoke.com

2000\05\11@111228 by Don Campbell

flavicon
face
Well,

I installed the new version of MPLAB (v5)...and found the problem.  This new
version has a list of unsupported options for each processor.  Apparently, the
simulator doesn't actually simulate USART operation.  There is nothing wrong with
the code.  (I've now tested it in hardware)  Thanks to all who had suggestions.

Much relieved,
Don

"M. Adam Davis" wrote:

{Quote hidden}

2000\05\11@122355 by Quitt, Walter

flavicon
face
After reviewing other midrange code I've written,
I have a hard time believing you ever need to
set RC6/TX/CK to input when you are only doing
serial I/O.  Interrupt driven or not.

I'll be porting interrupt serial I/O to my current
16F877 project soon.  I've migrated that code around
on several midrange parts and NEVER ever set the
serial output to input.  Wonder what may have happened
to the 16F87X family?  Where did you see that you needed
to set both serial pins to input????

-Walt..

{Original Message removed}

2000\05\11@131523 by Erik Reikes

flavicon
face
At 09:20 AM 5/11/00 -0700, you wrote:
>After reviewing other midrange code I've written,
>I have a hard time believing you ever need to
>set RC6/TX/CK to input when you are only doing
>serial I/O.  Interrupt driven or not.
>
>I'll be porting interrupt serial I/O to my current
>16F877 project soon.  I've migrated that code around
>on several midrange parts and NEVER ever set the
>serial output to input.  Wonder what may have happened
>to the 16F87X family?  Where did you see that you needed
>to set both serial pins to input????
>
>-Walt..
>

I've used the F877 and the F876 and I always set TX to output and RX to input.

I suspect even this is uneccesary because those pins are controlled by the
UART registers...

I haven't had any problems with the uart.



Erik Reikes
Senior Software Engineer
Xsilogy, Inc.

RemoveMEereikesTakeThisOuTspamxsilogy.com
ph : (858) 535-5113
fax : (858) 535-5163
cell : (858) 663-1206

2000\05\11@170206 by Kbek Tony

flavicon
face
Hi,

-Snip
>on several midrange parts and NEVER ever set the
>serial output to input.  Wonder what may have happened
>to the 16F87X family?  Where did you see that you needed
>to set both serial pins to input????

>-Walt..

In datasheet for 16F87X DS30292A-page 105, I paraphrase:

"Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order
to configure pins RC6/TX/CK and RC7/RX/DT as USART."

But Microchip's documentation is not known to be THAT
precise, they could very well mean that the pins are
controlled automaticlly by enabling the UART, who knows ?

Anyway I only have UART experience on the 16F87X parts
and I DO set both of these pins as inputs ( TRIS bit's set ).
And it's working dandy.


While on the subject, see my posting a few days ago regarding the SPI,
there is states on one line that SDI is automaticly
controlled by the SPI module, and a few lines down it
instead stated that one can override the SPI functionality
by setting/clearing the bit in the TRIS reg, uh ?
( anyway, the answer for that one was it must be set/cleared
in the TRIS reg to operate it's NOT automaticlly controlled ).

/Tony




Tony KŸbek, Flintab AB            
ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓ
E-mail: spamBeGonetony.kubekspamBeGonespamflintab.com
ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓ

2000\05\11@173742 by Quitt, Walter

flavicon
face
Can't argue.  If setting TRISC for just inputs works for you
then, it does.  I just don't do that on other midrange parts.

As far as the SPI is concerned, I stole most my stuff from
the app notes for doing SPI.  I got it to work for the 64k bit
25LC640 at near 3MHz.  I never turn it off as it is on a
set of dedicated pins.  Perhaps if I were switching between
SPI and I2C.... but that's sorta nonsense anyways.

I run both async and SPI under interrupt control.

I'll see what happens when I get that stuff running on the F877.

-W

{Original Message removed}

2000\05\11@174609 by Kelly J Kohls

picon face
Tony,

> In datasheet for 16F87X DS30292A-page 105, I paraphrase:
>
> "Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order
> to configure pins RC6/TX/CK and RC7/RX/DT as USART."

Thanks for posting this, I was just about to do the same....

> But Microchip's documentation is not known to be THAT
> precise, they could very well mean that the pins are
> controlled automaticlly by enabling the UART, who knows ?
>
> Anyway I only have UART experience on the 16F87X parts
> and I DO set both of these pins as inputs ( TRIS bit's set ).
> And it's working dandy.

Same here.  I have built DMX512 transmitters and receivers (250 Kbaud)
using the 16C76 and 16F876 with no problems with the UARTS whatsoever.


Kelly Kohls, N5TLE
Dallas, TX
Email:  TakeThisOuTkkohlsEraseMEspamspam_OUTjuno.com  OR  RemoveMEn5tlespamTakeThisOuTqsl.net  OR n5tleEraseMEspam.....arrl.net
Homepage:  http://www.qsl.net/n5tle/

________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
dl.http://www.juno.com/get/tagj.

2000\05\12@032456 by Tom Handley

picon face
  Walter, apparently most folks don't have problems setting RC6
to output but a few have. In anycase, All the data books for All
the midrange PICs with on-board USARTs say to set Both RC6 and RC7
to inputs so why not do it? I've been doing that with a variety of
devices for 5+ years with no problems...

  - Tom

At 09:20 AM 5/11/00 -0700, Walter Quitt wrote:
{Quote hidden}

>{Original Message removed}

2000\05\12@113244 by Quitt, Walter

flavicon
face
I've dug out my Midrange Referenace manual so
I can figure our what 2Tad (ADC stuff) is and
will look at the serial comms references.  I am almost
sure the ANs associated with serial comms also
set RC7/RC6 to Input/Output.  But I'm gonna look.
This is beginning to bug (pun intended) me.  :-)
-W

{Original Message removed}

2000\05\12@172521 by Oliver Broad

picon face
I remember the wierdish behavior of 16C73 parts (yep, 1st version).

The TX pin direction bit was overridden to output when the serial was
enabled. Good.

The wierd part: The direction actually reads as output while transmitting,
and a RMW instruction will cause the direction (output) to be stored.
Serial still worked, but my program required the pin to go Tristate when it
finished. Obscure condition caused it to stick as output.

Oliver.

2000\05\13@035400 by Tom Handley

picon face
  Walt, I just took a look at the Mid-Range Reference Manual
(DS31018A) to see if there was any additional info. On page
18-2 they also mention setting the related TRIS Bits though
they are a bit obscure compared to the data books I've used.
Since this comes up fairly often, it would be nice to hear
what Microchip has to say on this.

  - Tom

At 08:31 AM 5/12/00 -0700, Walter Quitt wrote:
>I've dug out my Midrange Referenace manual so
>I can figure our what 2Tad (ADC stuff) is and
>will look at the serial comms references.  I am almost
>sure the ANs associated with serial comms also
>set RC7/RC6 to Input/Output.  But I'm gonna look.
>This is beginning to bug (pun intended) me.  :-)
>-W
>
>{Original Message removed}

2000\05\13@110102 by Byron A Jeff

face picon face
On Sat, May 13, 2000 at 12:27:40AM -0700, Tom Handley wrote:
>    Walt, I just took a look at the Mid-Range Reference Manual
> (DS31018A) to see if there was any additional info. On page
> 18-2 they also mention setting the related TRIS Bits though
> they are a bit obscure compared to the data books I've used.
> Since this comes up fairly often, it would be nice to hear
> what Microchip has to say on this.

Tom,

I'm not sure if it's been mentioned in this thread yet but my advise is
to take a look at Fr. Tom McGahee's annotated PICUART code located here:

http://redrival.com/mcgahee/picuart.zip

First off it's a drop in module that drives the UART perfectly. Secondly
is points out all of the gotcha's like the fact that both RC6 and RC7 need
to be set as input.

Here's Fr. Tom's rationale for developing such annotated source code:
-------------------------------------------
; When I first tried to implement the UART features for the PIC16C74A
; I discovered that what I thought should have been a simple and
; straight-forward task was made difficult because:
;
; 1) The information in my PIC manual was incomplete.
; 2) Some of the information in the manual was wrong.
; 3) Although there was SOME errata information on the MicroChip site,
;    there was no simple guide to setting up the UART.
; 4) Bits and pieces to the puzzle were strewn here and there in the manual,
;    but not in one place.
; 5) Microchip did not provide a comprehensive example for using the UART.
; 6) Information provided by other users of the PIC16C74A device in several
;    cases turned out to be erroneous.
; 7) Some simplistic solutions offered by others did not provide any kind
;    of recovery from error condiions such as framing errors and over-run
;    errors. These "examples" would work for a few minutes and then hang.
; 8) Many solutions ignored the hardware interface aspects altogether.
;    A) No mention of the signal inversions and rs232 translations.
;    B) No mention of handshaking required at the PC end of things.
-------------------------------------------

At this point in time I consider it to be the definitive PIC UART reference
document. Get it. Read it. It answers all your questions.

My two project students took the code, drop it into a 16F874 and were up and
running in 5 minutes flat. Saved them a couple of weeks worth of work.

Thanks Fr. Tom.

BAJ
{Quote hidden}

> >{Original Message removed}

2000\05\14@010859 by Tom Handley

picon face
  Byron, Fr. Tom's reference is excellent and anyone using the
USART should refer to it. I was trying to see if there was an
exception to the RC6/7 input rule but I could'nt find any.
They should always be set to inputs if for no other reason, the
data books recommend it.

  - Tom

At 10:26 AM 5/13/00 -0400, Byron A Jeff wrote:
{Quote hidden}

------------------------------------------------------------------------
Tom Handley
New Age Communications
Since '75 before "New Age" and no one around here is waiting for UFOs ;-)

2000\05\15@131214 by jamesnewton

face picon face
The following from Microchip seems clear...

>From DS30292B-page 33 (the '873 datasheet section 3.3 PORTC and TRISC
Registers):

When enabling peripheral functions, care should be
taken in defining TRIS bits for each PORTC pin. Some
peripherals override the TRIS bit to make a pin an output,
while other peripherals override the TRIS bit to
make a pin an input. Since the TRIS bit override is in
effect while the peripheral is enabled, read-modify-write
instructions (BSF, BCF, XORWF) with TRISC as
destination should be avoided. The user should refer to
the corresponding peripheral section for the correct
TRIS bit settings.

-----

>From DS30292B-page 95 (the '873 datasheet section 10.0n on USART):

Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to
be set in order to configure pins RC6/TX/CK and
RC7/RX/DT as the Universal Synchronous Asynchro-nous
Receiver Transmitter.

---------- end of cuts from '873 datasheet ----------

In Microchip lingo "set" means make the bit a 1.

The bottom line, don't do read-modify-write operations on a TRIS register
that is controlling pins with another active peripheral, such as the TRISC
register when using the UART or CCP.

---
James Newton (PICList Admin #3)
EraseMEjamesnewtonspampiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}

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