Searching \ for 'More Serial Comm Questions ( Rookie )' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/io/serials.htm?key=serial
Search entire site for: 'More Serial Comm Questions ( Rookie )'.

Truncated match.
PICList Thread
'More Serial Comm Questions ( Rookie )'
1997\03\09@234217 by James and Iliana Holbrook

flavicon
face
       To all that replied to my earlier post about serial comms, thanks for th
e
help.   I've put together some code that I want to test soon. How ever I
have a few more questions.
       Using a 4 mhz crystal, my instruction time is 1us right ??
       Wanting to transmit data at 9600 baud I will have a period of 104us righ
t
? That means that to transmit a "1" I would have to drive a pin high for
52us and low for 52us right ??? To transmit a "0" I would just drive the
pin low for 104us ? I know that regular RS232 is low marking but I will be
communicating with another PIC so mine will be high marking. ( if I HAVE to
I could modify the code to be low marking )
       Thanks again for the help.

James and Iliana Holbrook
Austin Texas

1997\03\10@003244 by Lee Jones

flavicon
face
> Using a 4 mhz crystal, my instruction time is 1us right ??

Yes.

> Wanting to transmit data at 9600 baud I will have a period of
> 104us, right?

Each bit time is 104 microseconds.

> That means that to transmit a "1" I would have to drive a pin
> high for 52us and low for 52us right ???

No.  That would be NRZI or phase encoding or something similar.

RS-232 is a simple voltage interface.  The data line should be
held high or low for the _entire_ bit time.  Transitions occur
between bits.

> To transmit a "0" I would just drive the pin low for 104us?
> I know that regular RS232 is low marking

Right, but the output stage may invert the signal.  In other
words, depending on the driver IC you are using, you may have
to "lower" a PIC pin to generate an RS-232 high (+3 to +25V).
And conversely, you may have to "raise" the PIC output pin to
generate an RS-232 low (-3 to -25V).
                                               Lee Jones

-------------------------------------------------------------------
Jones Computer Communications             spam_OUTleeTakeThisOuTspamfrumble.claremont.edu
509 Black Hills Dr, Claremont, CA 91711         voice: 909-621-9008
-------------------------------------------------------------------

1997\03\10@211447 by Dwayne Reid

flavicon
face
       Wanting to transmit data at 9600 baud I will have a period of 104us
right
>? That means that to transmit a "1" I would have to drive a pin high for
>52us and low for 52us right ??? To transmit a "0" I would just drive the
>pin low for 104us ? I know that regular RS232 is low marking but I will be
>communicating with another PIC so mine will be high marking. ( if I HAVE to
>I could modify the code to be low marking )
>        Thanks again for the help.
>
>James and Iliana Holbrook
>Austin Texas
>

I am enclosing code written a couple of years ago for serial TX.  Note that
THREE different routines are included: 9600, 19200, 38400 baud.  You can
change the code to be LO or HI marking by swapping the 2 instructions noted.

These routines are based upon ideas from both Mike Harrison and Andy Warren
and use only 15 code spaces and 1 register.

The speed isn't exact, but is only 0.16% fast. The output polarity is true
and can directly feed a RS232 driver (MAX232).  For inverted data (to
directly feed an RS232 (PIC) input), swap the bsf and bcf instructions.
There are 3 different versions for 9600, 19200, and 38,400 baud.  All
routines assume 4 MHz clock.

The routines use the data format 8N1.  Increase the .10 by up to .15 if you
need more stop bits (this will affect the cycle times mentioned).  Note that
W is used as the delay counter.

;TXBYTE: send 1 byte @ 9600 baud: 1 RAM, 15 (16) ROM, 1043 cycles
;enters with data in w, exits with w trashed.
;Copyright (C) 1995 Dwayne Reid.  May be freely used so long as this
;copyright notice is retained.

txbyte                          ; send byte in W at 9600 baud (4MHz osc), 8N1
   movwf   temp
   movlw   .10        ; 8 data + 1 start + 1 stop (inc for more stop bits)
   clrc                        ; start bit
txloop                          ; bit time = 104.167 uSec
   skpnc
     bsf   serport,dout        ; output bit = carry
   skpc
     bcf   serport,dout
dloop                           ; 95 clk cycle delay
   goto    $+1                 ; 2-cycle NOP in 1 instruction!
   addlw   b'00010000'         ; increment upper nibble
   skpc                        ; delay = 6n -1 (1 less when falls thru)
     goto  dloop               ; loop sixteen times
   addlw   -1                  ; dec w, valid z, c=1 if w>=0 after decrement
   rrf     temp,F              ; carry will be set - shifted in as stop bit
   skpz
     goto  txloop              ; txloop is 104 clk cycles
   return



;TXBYTE: send 1 byte @ 19200 baud: 1 RAM, 14 (15) ROM, 523 cycles
;enters with data in w, exits with w trashed.
;Copyright (C) 1995 Dwayne Reid.  May be freely used so long as this
;copyright notice is retained.

txbyte                          ; send byte in W at 19200 baud (4MHz osc), 8N1
   movwf   temp       ; 8 data + 1 start + 1 stop (inc for more stop bits)
   movlw   (b'01010000'+.10)   ; allow dloop to execute only 11 times
   clrc                        ; start bit
txloop                          ; bit time = 52.083 uSec
   skpnc
     bsf   serport,dout        ; output bit = carry
   skpc
     bcf   serport,dout
dloop                           ; 43 clk cycle delay
   addlw   b'00010000'         ; increment upper nibble
   skpc                        ; delay = 4n -1 (1 less when falls thru)
     goto  dloop               ; loop 11 times
   addlw   -1                  ; dec w, valid z, c=1 if w>=0 after decrement
   rrf     temp,F              ; carry will be set - shifted in as stop bit
   skpz
     goto  txloop              ; txloop is 52 clk cycles
   return



;TXBYTE: send 1 byte @ 38400 baud: 1 RAM, 15 (16) ROM, 263 cycles
;enters with data in w, exits with w trashed.
;Copyright (C) 1995 Dwayne Reid.  May be freely used so long as this
;copyright notice is retained.

txbyte                          ; send byte in W at 19200 baud (4MHz osc), 8N1
   movwf   temp       ; 8 data + 1 start + 1 stop (inc for more stop bits)
   movlw   (b'11000000' + .10) ; allow dloop to execute only 4 times
   clrc                        ; start bit
txloop                          ; bit time = 26.042 uSec
   skpnc
     bsf   serport,dout        ; output bit = carry
   skpc
     bcf   serport,dout
   goto    $+1                 ; 2 cycle NOP
dloop                           ; 15 clk cycle delay
   addlw   b'00010000'         ; increment upper nibble
   skpc                        ; delay = 4n -1 (1 less when falls thru)
     goto  dloop               ; loop 4 times
   addlw   -1                  ; dec w, valid z, c=1 if w>=0 after decrement
   rrf     temp,F              ; carry will be set - shifted in as stop bit
   skpz
     goto  txloop              ; txloop is 26 clk cycles
   return

I hope that people find these useful.  As I said before, the core idea came
from Mike Harrison.  All I did was take a couple of suggestions from Andy
Warren and some ideas of my own to shorten them and reduce RAM usage.  Enjoy!

Dwayne Reid   <.....dwaynerKILLspamspam@spam@planet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, Alberta, CANADA
(403) 489-3199 voice     (403) 487-6397 fax

1997\03\20@231033 by Andrew Warren

face
flavicon
face
Dwayne Reid <PICLISTspamKILLspamMITVMA.MIT.EDU> wrote:

> I am enclosing code written a couple of years ago for serial TX.
> Note that THREE different routines are included: 9600, 19200, 38400
> baud.  You can change the code to be LO or HI marking by swapping
> the 2 instructions noted.
>
> These routines are based upon ideas from both Mike Harrison and Andy
> Warren and use only 15 code spaces and 1 register.

   Dwayne:

   Actually, I can't really take credit for anything but the use of
   a "GOTO $+1" as a two-cycle NOP.  As I recall, Mike Harrison's
   original code used "MOVF PC", instead... Not real safe.

> There are 3 different versions for 9600, 19200, and 38,400 baud.

   Have you actually TESTED the 19200 and 38400 baud versions?
   Maybe I'm missing something, but it looks to me as though all
   bits after the start bit will be sent at 9600 baud.

   -Andy

=== Andrew Warren - .....fastfwdKILLspamspam.....ix.netcom.com
=== Fast Forward Engineering - Vista, California
===
=== Custodian of the PICLIST Fund -- For more info, see:
=== www.geocities.com/SiliconValley/2499/fund.html

1997\03\23@160103 by Dwayne Reid

flavicon
face
>    Dwayne:
<tiny snip>
>    Have you actually TESTED the 19200 and 38400 baud versions?
>    Maybe I'm missing something, but it looks to me as though all
>    bits after the start bit will be sent at 9600 baud.
>
>    -Andy

I was about to reply: of course I've tested the code, then figured that I
had better go back to the project that the routines were written for and
check.  As it turns out, the 3 routines were written because the end
customer was not sure which data rate he wanted.  He wound up using only the
9600 baud version.  The other 2 were NOT tested and, as Andy pointed out,
will NOT work properly.  These routines have been sitting on the shelf for a
long time and I forgot the circumstances.

Andy - thanks pointing this out.  To the others who may be trying to use the
19200 or 38400 routines: my appologies for wasting your time.  I've got the
corrected versions written and will be testing them today or tommorow.  I'll
repost as soon as I have verified their operation.

Dwayne Reid   <EraseMEdwaynerspam_OUTspamTakeThisOuTplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, Alberta, CANADA
(403) 489-3199 voice     (403) 487-6397 fax

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