Searching \ for 'PIC16C74 Built-In UART Routines Needed.' 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=16C
Search entire site for: 'PIC16C74 Built-In UART Routines Needed.'.

Truncated match.
PICList Thread
'PIC16C74 Built-In UART Routines Needed.'
2000\04\08@194349 by Thomas McGahee

flavicon
face
Dear PICSTERS,
I am in the middle of a project using a PIC16C74 and I
am having trouble getting my routines that use the
built-in Asynchronous Receiver/Transmitter to work.

Part of the problem is that there are inconsistencies and
errors in the manual for this device. The other part of the
problem is that the manual has no sample initialization
routines and sample serial input and output routines.

Normally I am one of the people answering other people's
requests for help. Well, now I am in need of a little
help myself.

If any of you have working code for the UART initialization
and sample input and output routines *that work*, I would
be most grateful if you would e-mail me a copy.
spam_OUTtom_mcgaheeTakeThisOuTspamsigmais.com

I am not sure, but the built-in UART for some of the other
PICs may be identical, so if you have code for some other
PIC, please respond.

Thank you for your consideration. I know that each of you
has a thousand other things to do that are more important
than answering this request. That is a fact that makes me all the
more grateful to those who will take the time to respond, and
who have the generosity to share with me the fruits of their
labor in this area.

Fr. Tom McGahee

2000\04\08@203821 by Dan Michaels

flavicon
face
Tom McGahee wrote:
>Dear PICSTERS,
>I am in the middle of a project using a PIC16C74 and I
>am having trouble getting my routines that use the
>built-in Asynchronous Receiver/Transmitter to work.
>
>Part of the problem is that there are inconsistencies and
>errors in the manual for this device. The other part of the
>problem is that the manual has no sample initialization
>routines and sample serial input and output routines.
>

Some of the older '74 chips had UART h.w. problems.
You might check the Mchp errata page for the latest.

2000\04\08@214146 by Brian Kraut

picon face
I think this may be the problem:

>From 74A errata sheet

8. Module: USART
When the USART (SCI) is configured in asynchro-nous
mode with the BRGH bit set, a high number of
receive errors may be experienced. For asynchro-nous
receive operations it is recommended that the
USART be configured with the BRGH bit cleared.

2000\04\09@183254 by Thomas McGahee

flavicon
face
I have read over the errata file for the PIC16C74 and
noted the warning about BRGH needing to be set LOW
to prevent excessive receive errors. Thanks to Dan
Michaels for bringing that to my attention.

OK, so I did that. Still nothing but errors from the UART
receiver. Brian Kraut and I are working together
on solving this problem, but at the moment we are
both stumped. It is probably some really simple step
that we are leaving out, but we are too close to the
problem to see what it is we are missing.

Surely *someone* out there has used the built-in
UART successfully on this device. I need to get this
UART working as soon as possible, as this is holding
up the rest of the project.

I will continue to try my own experiments and see if I
can get this UART thing working properly, but in the
meantime, if you have some working code that you can
snip out and e-mail me, I would be *deeply* grateful.

Help! I want to be able to sleep again!


Thank you for your consideration!

Fr. Tom McGahee

{Original Message removed}

2000\04\09@194232 by Thomas C. Sefranek

face picon face
Thomas McGahee wrote:

{Quote hidden}

I posted fully working code for the 16C74 serial port weeks ago
and it's available in the web ring.  If you can't retrieve it, send me
E-Mail.

> Help! I want to be able to sleep again!
>
> Thank you for your consideration!
>
> Fr. Tom McGahee

--
 *
 |  __O    Thomas C. Sefranek   .....tcsKILLspamspam@spam@cmcorp.com
 |_-\<,_   Amateur Radio Operator: WA1RHP
 (*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

2000\04\10@050146 by Kbek Tony

flavicon
face
Just a thought, You did look at this did You ?

http://www.microchip.com/10/Faqs/tSupport/PICmicro/USART/index.htm

/Tony

Tony KŸbek, Flintab AB            
ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓ
E-mail: tony.kubekspamKILLspamflintab.com
ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓ

2000\04\10@103235 by M. Adam Davis

flavicon
face
Tom,

Notes on using the built-in UART:
Check and initialize the several registers associated with the UART:
  TXSTA
  RCSTA
  SPBRG
  PIR1
  PIE1
  TRISC (TX & RX pins both input)
Follow the suggested initialization order on the data sheet
  (p.107 and p.109 on the 17c74 datasheet)
Do NOT use the baud rate tables in the data sheets,
  Use the calculations instead:
  Fosc/(64(spbrg+1))   BRGH = 0
  Fosc/(16(spbrg+1))   BRGH = 1
  (for instance the table for BRGH=1 at 4MHz async says 57.6kbps at
   spbrg=25, which is incorrect. 9600 is correct for spbrg=25 @ 4MHz.
   It /looks/ like the BRGH=1 tables are the only ones incorrect, but
   you should double-check)
Make certian TRIS for RX and TX pins are BOTH input (counterintuitive,
  but necessary)

I've included a portion of my terminal program below (in C) which gives you a
starting point.  You can see the entire program in both C and ASM here:
http://www.ubasics.com/adam/electronics/ha/

The following functions are not included for brevity (but are in the code on my
site):
initlcd()       - Initialize the LCD (4-bit, two line)
write8(char)    - Send a character to the LCD
delayms(x)      - Delay about x milliseconds
char initmsg(x) - Returns character x of a 16 character string.

The variable RS is directly mapped to the register select pin of the LCD, and
ESCCHAR is a constant set to 0x27 at the top of the c file.  All other registers
are named in the data sheets.

Any character sent to the chip is sent to the LCD, except the esc character.
The character sent after ESC is sent to the LCD instruction register.  Send two
esc characters to send the esc character to teh LCD data register.

I hope this helps!

-Adam

void main(void)
{
  uns8 x;
  uns8 Instruction;
  PORTA = 0b.0000.0000; /* All ports low at start */
  PORTB = 0b.0000.0000;
  PORTC = 0b.0000.0000;

  TRISA = 0b.1100.0000; /* 7:6 Input(1), 5:0 Output(0) */
  TRISB = 0b.1111.1111; /* 7:0 Input, no output        */
  TRISC = 0b.1100.0000; /* 7:0 Output                  */
                       // NOTE: PORTC:6 & 7 must be set INPUTS
                       // for the UART to work correctly.

  SPBRG=25;    // At 4MHz clock, BRGH=1, SPBRG=25 so baudrate is 9615.38
               // 0.16% error (awsome)
               // At 4MHz clock, BRGH=0, SPBRG=6 baudrate is 8928.57
               // 7% error (don't use for production)
               // Luckily, neither the 16C66 or the 16F8xx have BRGH
               // problems.  I have successfully tested both of these at
               // 9600 (computer) with no errors.  (ie, I recieved the
               // intended characters.  You can see I'm not checking for
               // framing or overrun errors)
  TXSTA=0x24;  // Async, TX enabled, BRGH=1, 8-bit
  RCSTA=0x90;  // Receive & UART enable, 8-bit
               // The interrupts are disabled by default,
               // so I'm not messing with them.

  initlcd();           /* Initialize LCD */

  RS = 1;              /* Select the Data register on the LCD */
  for(x=0;x < 16;x++)
     write8(initmsg(x));       // Send the init msg to the LCD
  for(x=0;x<16;x++)
  {
     TXREG = initmsg(x);       // Send the init msg over RS-232
     while(!TXIF);             // Wait for the TX buffer to become empty
  }

  TXREG = '4';
  while(!TXIF);
  TXREG = '2';         // Don't Panic!
  while(!TXIF);

  RS=0;        // Write to the instruction register of the LCD
  write8(0x01);        // Clear the LCD
  delayms(2);  // Pause for 2 ms (only needed for fast uCs (4MHz and up),
               // the write8 routine is slow enough and the LCD
               // fast enough that pauses are generally not needed.)
  RS=1;        // Set the next write to the data register

  while(1)
  {
     uns8 key, lastkey;
     PORTC = 0xff;

     if(RCIF)                  // Is there data in the receive register?
     {
        uns8 regbuf;           // This will hold the received characters
        regbuf = RCREG;        //  Put it in a buffer
        if(regbuf == ESCCHAR)  // Is it the escape character? (0x27)
        {
           if(Instruction == 1)  // Was the last character an escape?
           {
              write8(regbuf); // Write the ESC to the LCD
              Instruction = 0;// Set the ESC flag low
           }
           else
              Instruction = 1; // This is the first ESC
        }
        else // This character is not an escape character
        {
           if(Instruction == 1) // Was the last char. an ESC?
           {
              RS=0;            // Write to the instruction register
              write8(regbuf);
              RS=1;            // Set it back to data register
              Instruction = 0;// Reset the instruction flag
           }
           else
              write8(regbuf); // Nothing special, write char to LCD
        }
        TXREG=regbuf; // Echo character back to sender
     }
  }
}

Thomas McGahee wrote:
>
> Dear PICSTERS,
> I am in the middle of a project using a PIC16C74 and I
> am having trouble getting my routines that use the
> built-in Asynchronous Receiver/Transmitter to work.
> Fr. Tom McGahee

2000\04\10@113211 by jamesnewton

face picon face
Its at
http://www.piclist.com/../microchip/usarttcs
and is listed under
http://www.piclist.com/faq
under I/O, rs232, "Thomas C. Sefranek's 16C73 USART Serial Port Gotcha List
and Source" right next to "Ken Websters PIC16C74 serial port multiplexer."
which is also working code.

---
James Newton .....jamesnewtonKILLspamspam.....geocities.com 1-619-652-0593
http://techref.massmind.org NEW! FINALLY A REAL NAME!
Members can add private/public comments/pages ($0 TANSTAAFL web hosting)


{Original Message removed}

2000\04\11@063338 by Tom Handley

picon face
  Tom, In addition to comments from Adam and Scott's code, another issue
is not checking for Overrun errors via OERR. If you get one, you have to
clear the Continuous Receive Enable Bit (CREN) and then set it. If not, the
USART will stop receiving. Finally, there is the Framing Error (FERR). If
you get one of those, you should flush the Rx register (RCREG) by reading
it. The following is a simple `snippet' from an ISR routine that checks
OERR and FERR and returns a Byte though you would normally use a buffer.

     CVASM (Parallax) syntax:
     :INT1   JNB     OERR,:INT11             ; If Overrun Error
             CLRB    CREN                    ;   Clear Overrun Error
             SETB    CREN
     :INT11  JNB     FERR,:INT12             ; If Framing Error
             MOV     W,RCREG                 ;   Clear RCREG
             JMP     :INTX                   ;   Exit
     :INT12  MOV     rxbyte,RCREG            ; Get Byte from USART

     MPASM syntax:
     INT1    BTFSS   RCSTA,OERR              ; If Overrun Error
             GOTO    INT11
             BCF     RCSTA,CREN              ;   Clear Overrun Error
             BSF     RCSTA,CREN
     INT11   BTFSS   RCSTA,FERR              ; If Framing Error
             GOTO    INT12
             MOVF    RCREG,W                 ;   Clear RCREG
             GOTO    INTX                    ;   Exit
     INT12   MOVF    RCREG,W                 ; Get Byte from USART
             MOVWF   rxbyte

  Depending on the application, you would probably want to also set a
user-defined error flag.

  To re-cap; Set RC6 and RC7 to Inputs. Use the Baud Rate formulas, not
the tables (I made a simple Excel sheet), and at least check for OERR
errors. I've used this with 16C73A/74A/76/77/F876/F877 devices.

  - Tom

At 04:06 PM 4/9/00 -0400, Thomas McGahee wrote:
{Quote hidden}

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

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