Just a quick question on hooking up PICs to RS-232 Lines. I've seen a few
applications (the classic being the BASIC STAMP) that connects a PIC
directly to the RS-232 Lines of a host computer.

I presume that it would work because of the low currents involved and the
fact that RS-232 "0" can be represented by 5V. Does this mean that a 1 is
anything less than 3V (which is what i believe the EIA Spec says).

> I presume that it would work because of the low currents involved and the
> fact that RS-232 "0" can be represented by 5V. Does this mean that a 1 is
> anything less than 3V (which is what i believe the EIA Spec says).
>

The spec says a 1 is anything fom -3 to -25 volts. The reason this
direct connect method usually works is most 232 receivers have an
input threshold low spec of 0.8 to 1.5 volts. This direct connect
will work with most ports - if you want it to work with all ports,
you need the negative swing.

> Just a quick question on hooking up PICs to RS-232 Lines. I've seen
> a few applications (the classic being the BASIC STAMP) that connects
> a PIC directly to the RS-232 Lines of a host computer.

> I presume that it would work because of the low currents involved and
> the fact that RS-232 "0" can be represented by 5V. Does this mean that
> a 1 is anything less than 3V (which is what i believe the EIA Spec says).

RS232 specifies transmitter outputs be +5 to +25V or -5 to -25V.
Receiver inputs are +3 to +25V or -3 to -25V. The range between
-3 to +3V is to be ignored (for noise rejection). Practically,
lots of receiver chips incorrectly accept input signals around
0V as a valid logic 1 signal.

RS232 is a voltage interface, so you should not expect to draw
any current. Again, practically, you can probably draw a few
milliamps without damaging anything or degrading the signal too
badly (depending on the transmitter output stage).

Following are details (excerpted from my post of 11-29).

With asynchronous serial, the data is sandwiched in between a start
bit and a stop bit. Normally, there are 8 data bits between as in
the following diagram:

RS232 specified the physical properties of the interface. This
includes voltages. At the transmitter, logic 0 or "spacing" is
+5 to +25V while logic 1 or "marking" is -5 to -25V. Marking and
spacing are terms that date back to Teletype days.

RS232 receiver must accept -25 to -3 or +3 to +25. Range between
-3 and +3V is supposed to be used for hysteresis to reject noise.
Lots of receiver chips do NOT handle the -3V to +3V range correctly.
Their rejection band is about 1/2 a volt somewhere around 0V.

Note that the transmitter side minimum output is specified as a
higher voltage than the minimum specified at the receiver to allow
resistive drop in the wire. Also, it's a 1-wire voltage based
interface, so you need a ground wire. And be carefull of current
flows between the equipment on the ground wire -- particularly if
the two ends are located some distance from each other.

Normally an async RS232 data line is idle and marking (-5 to -25V).
A status line, such as Data Terminal Ready (DTR, DB25 pin 20) or
Request To Send (RTS, DB25 pin 4), will be asserted (ON, +5 to +25V).

When a character is transmitted, the start bit guarantees a low to
high transition (from marking to spacing). The stop bit is used to
guarantee that (irrespective of the data) in a continuous stream of
characters, the line will be driven back down to the marking state
before the next start bit is sent.

The "baud rate" is the number of bits per second when the line is
running continuously. The difference between bits per second and
baud rate is that baud rate may vary from 0 bps to maximum. Thus
the baud rate is the correct term for an async line while BPS (bits
per second) is correct for a sync line. [Misuse of this term is a
pet peeve of mine.] Data is sent least significant bit first.

>The "baud rate" is the number of bits per second when the line is
>running continuously. The difference between bits per second and
>baud rate is that baud rate may vary from 0 bps to maximum. Thus
>the baud rate is the correct term for an async line while BPS (bits
>per second) is correct for a sync line. [Misuse of this term is a
>pet peeve of mine.] Data is sent least significant bit first.

Actually Lee, Baud refers to the signalling rate. BPS is the number of bits
transmitted per second. The distinction only comes into play when more than
one bit at a time (per baud) is transmitted, as in BPSK, QPAM, etc.

Bell 212 modems transmit two bits at a time, as 4 quadrant phase shift. The
signalling rate is 600 Baud, the bit rate is 1200BPS.

>Actually Lee, Baud refers to the signalling rate. BPS is the number of bits
>transmitted per second. The distinction only comes into play when more than
>one bit at a time (per baud) is transmitted, as in BPSK, QPAM, etc.
>
>Bell 212 modems transmit two bits at a time, as 4 quadrant phase shift. The
>signalling rate is 600 Baud, the bit rate is 1200BPS.
>
As an engineer who has worked in the async data transmission field for more
years than I care to remember, these discussions on terminology and modern
interpretation of standards that were established in some cases 30 years ago
without reference to the original source material bothers me....

In fact Mr Baud yes there was such a man..

Created the rate when he worked for ITT CREED LTD Brighton England. They
manufactured TELEX you remember those large lumps of electro mechanical
equipment that came before fax machines..

110 Baud as a simple example in fact refered to the transmission of an
8 bit data field FRAMED with 1 start-bit, 1 stop-bit and 1 parity-bit

Total data transmission size for each byte of data is therefore 11 bits and
the physical transmission rate for the bits is 100 bits /sec.

In the early electro machanical days 75 Baud and 50 Baud rates - those were
the days ! refered to the BAUDIT coded method using the 5 bit data encoded
ALPHA NUMERIC transmission derived by Baud himself, for information via the
world wide Telex network.

A holding MARK the line idle situation on an async line, by the way, is
defined as a positive voltage level which is sufficient to avoid false start
bit occuring due to electrical noise. Typically the holding MARK was
originally specified to be 25% greater than the nominal or mean DC positive
level that would occur during data transmission, those old Telex machines
simply had a soleniod which drove a dolly backwards and forwards and it took
a large transient on the Line to get the soleniod to start switching.

Its a pet hate of mine that we have lost these historic definitions and that
we now allow the Baud rate and the BPS rate to be used without regard to
there real meaning.

On the subject of voltage levels on RS232 etc...

The CCITT yellow book standard (Geneva) in which V24 was formally adopted by
the world wide PTT's back in the mists of time, clearly defined the
electrical characteristics of the sihnally as ...

Positive signal + 3v to + 30v (max) with a nominal of 15v
Negative signal - 3v to - 30v (max) with a nominal of -15v

Therefore RS232 the ANSI standard which apart from a few words here and
there is a derivative of the yellow book standard, adopted the above.

The source current from the transmitter is specified as absolute max 5mA,
but with short circuit protection, more than can be said for RS422. Rs423
etc. which only specifies a short circuit protection for a transient period.

The major RS232 / V24 chip sets, those that quote figures related to the
standards I refer the Texas Instruements 75' series for instance, have
inbuilt hysterisis in the receiver between 3v and -3v and state that input
voltages within the -3v to + 3v range can not have defined output voltage
results.

RS232 / V24 also has two ground connections, so any discussion on earth
current flows during transmissions must refer to both. Signal earth this is
the actual data line flow return path. Safety or Equipment earth the path
which will provide for any major distrubance on either piece of equipments
power supply current drain etc.. These two earths should not be connected
together either on the transmission path or in the equipment itself.

Sorry to take up so much space, but after all the recent discussion, on
Direct RS232 connection to a PIC I just felt I needed to air my views.

>I presume that it would work because of the low currents involved and the
>fact that RS-232 "0" can be represented by 5V. Does this mean that a 1 is
>anything less than 3V (which is what i believe the EIA Spec says).

>Myke Predko

The very simple, answer is "YES." This is because any non valid input
voltage is defined as a logic 1 on the output.Don't become confused, this is
the essential point. BUT, as Mike Fahrion pointed out, there are a some
cases the negative swing is required. Something to keep in mind if it
doesn't work on your friends computer.

RS232 input to a pic can be through a single resistor BUT a diode to Vdd is
required on at least one input, RA4 and possibly others with the 28/40-pin
16Cxx devices.

Of course, this sort of interface belongs to the M2L (Mickey-Mouse logic)
family and design "snobs" would never dream of using it. For many non
critical applications it's ok. Keep in mind that it has poor noise immunity
and may not comply with the slew rate limits of RS232.

Tony, it sounds as if you have direct experience with the old model 32 and
33 KSR teletypes. About 20 years ago I attended the CNCP telecommunications
course. CNCP used to service the old electromechanical stuff as well as the
modern transistor based machines as well. The mechanical stuff was
interesting! Pressing a key on the keyboard caused a series of horizontal
sliders with the baudot code to move and a little motorized parallel to
serial converter transmitted the 20ma current loop signal.

In some ways these electromechanical beasts were more of a work of
engineering art then the electronic stuff every was.

BTW the CNCP course was where I first learned the difference between BAUD
and bit rate.

Each technician had to be able to read baudot code right off of the paper
tape, and that was accomplished by about a week of code practice in class -
The instructor would key baudot messages audibly ala ham radio and each
student would hardcopy.

BTW the RS232 BREAK feature was a result of how the electromechanical units
used to work. When a space was detected (start bit) the serial to parallel
motor would advance whether the code was correct or not. Hence, if the
current loop was down it would be interpreted as a repeated sequence of 00H
(NULLs). The print carriage would go up and down but no striker would advance.

>> The "baud rate" is the number of bits per second when the line is
>> running continuously. The difference between bits per second and
>> baud rate is that baud rate may vary from 0 bps to maximum. Thus
>> the baud rate is the correct term for an async line while BPS (bits
>> per second) is correct for a sync line. [Misuse of this term is a
>> pet peeve of mine.] Data is sent least significant bit first.
>
> Actually Lee, Baud refers to the signalling rate. BPS is the number
> of bits transmitted per second.

Agreed. But I was speaking in the context of an asynchronous serial
channel using a 2 state RS232 voltage oriented interface for each
each data line. Consider the following.

From the "Encyclopedia of Computer Science" by Ralston & Meek:

"A baud is a unit of signaling speed and refers to the number of
times the state (or condition) of a line changes per second. It is
the reciprocal of the length (in seconds) of the shortest element in
the signaling code. Historically, it is a contraction of the surname
of the Frenchman J.M.E. Baudot, whose five-bit code was adopted by
the French telegraph system in 1877."

"The fastest signaling rate of a communications channel is called
the 'baud rate'. [...] When only two-level signaling is used, the
baud is also equal to the [maximum] rate of information transfer
in bits per second (bps)."

To me, bits per second (bps) implies a continuous stream of bits.
Async serial is not continuous since there are usually long periods
with no transitions (particulary if it's someone at a keyboad :-) ).
During those idle times, the bps rate is 0.

I still prefer baud rate for an async connection from RS232 DTE (Data
Terminal Equipment) to DCE (Data Circuit-terminating Equipment). I
believe it better implies the fact that the signalling rate can vary
between 0 bps and whatever maximum has been configured (e.g. 9600).

> The distinction only comes into play when more than
> one bit at a time (per baud) is transmitted, as in BPSK, QPAM, etc.
> Bell 212 modems transmit two bits at a time, as 4 quadrant phase shift. The
> signalling rate is 600 Baud, the bit rate is 1200BPS.

In a 2 state scheme, such as RS232, the baud rate and maximum bps rate
are identical. But there is still a distinction, admittedly tenuous,
between baud and bps for an _asynchronous_ digital interface.

You're introducing that portion of the communications channel that I
hadn't addressed, namely the link between 2 DCE devices (aka modems).
Up through 300 baud modems, each bit on the digital interface caused
one transition on the analog (aka phone) side. After that, starting
with 1200 baud modems, the inter-modem link was usually synchronous
and the baud and bps rates diverged (due to phone bandwidth limits).

For example, Bell 212s ran the digital connection (RS232 interface)
at 1200 baud async. And, as I recall, it ran the analog connection
(telephone side) at 1225 bps synchronous using a 4 level PSK signalling
scheme. This allowed the modem to accomodate timing variations on the
async interface even if running at maximum rate without losing data.

> In fact Mr Baud yes there was such a man..
> Created the rate when he worked for ITT CREED LTD Brighton England.

Sounds implausible.

> manufactured TELEX you remember those large lumps of electro mechanical
> equipment that came before fax machines..
>
> 110 Baud as a simple example in fact refered to the transmission of an
> 8 bit data field FRAMED with 1 start-bit, 1 stop-bit and 1 parity-bit
>
> Total data transmission size for each byte of data is therefore 11 bits and
> the physical transmission rate for the bits is 100 bits /sec.

I beg to differ. When I first started working on computers, terminals
were Teletype Corporation models 33, 35, and 37 (with lowercase). I've
worked on both the ASR (automatic send/receive) and KSR (keyboard only)
versions. The ASR was the one with a paper tape punch & reader.

In 110 baud, each bit was 1/110 second wide. A character was 7 bits
encoded in US ASCII. The 8th data bit was for parity (odd, I believe).
There was 1 start bit and 2 stop bits (to give the mechanical clockwork
drive some breathing room). Thus, a total of 11 bits per character.

I never worked on TELEX, but I thought it used a 7 bit code too.

They would do 10 characters per second (with quite a noise & vibration).
The rate was quoted as 100 words per minute (since they were competing
with secretaries taking dictation over the phone or telegraph operators).

> Therefore RS232 the ANSI standard which apart from a few words here and
> there is a derivative of the yellow book standard, adopted the above.

I disagree. RS232 came from the Electronic Industry Association as
Recommended Standard 232 (thus the well known term EIA RS232). The
suffix letter denotes the revision. RS232C was current as computers
started to become afordable; I think it's now up to RS232D. I don't
believe it was derivative of any CCITT (now ITU) work. ANSI might
have coordinated with them later...

> RS232 / V24 also has two ground connections, so any discussion on earth
> current flows during transmissions must refer to both. Signal earth this is
> the actual data line flow return path. Safety or Equipment earth the path
> which will provide for any major distrubance on either piece of equipments
> power supply current drain etc.. These two earths should not be connected
> together either on the transmission path or in the equipment itself.

"Should not" is the operative phrase. Almost all terminal equipment
in the US has the earth ground and signal ground tied together inside
the unit (and I do include PCs).

I've had to repair equipment where the computer was in one building
and the terminals were in another (30 feet apart). 50 pair phone cable
had been run between the buildings. RS232 3 wire (TxD, RxD, & signal
ground) was used. When the equipment blew, the current path was from
earth ground in building A, up the power cord's 3rd wire, over the
RS232 signal ground wire, down other power cord's 3rd wire, and into
the ground in building B. Spectacular -- chips fragmented, tops blown
off, etc. Happened in good weather (no storms).

Building B had an excellent earth ground for the medium size mainframe
computer (it would be considered huge by today's standards). Building
A had normal power grid ground system. Building A floated tens of volts
above other buildilng when the ground got really dry.

>> I presume that it would work because of the low currents involved and the
>> fact that RS-232 "0" can be represented by 5V. Does this mean that a 1 is
>> anything less than 3V (which is what i believe the EIA Spec says).
>
> The very simple, answer is "YES." This is because any non valid input
> voltage is defined as a logic 1 on the output. Don't become confused,
> this is the essential point. BUT, as Mike Fahrion pointed out, there
> are a some cases the negative swing is required.
>
> RS232 input to a pic can be through a single resistor [...]

If the PIC is receiving data via RS232 from another device, then this is
true. The sender will generate both positive and negative voltages. You
should have a resistor to limit pin current and a diode to ground to keep
the PIC's input pin from being driven to far below 0V. Be aware that you
are giving up some noise margin, but it should work fine.

If the PIC is trying to send data via RS232 output to another device, it
won't work to significant numbers of devices. It may work fine to a PC
or a Mac, but... Lots of equipment wants to see the negative voltage.

I have a terminal. It's -12V power supply failed (rest are OK). So the
RS232 TxD output is 0V or +12V (no negative). It will work hooked to
itself in loopback. It will work with _some_ equipment in the office.
But other pieces of equipment simply refuse.

> Of course, this sort of interface belongs to the M2L (Mickey-Mouse logic)
> family

M2L is perfectly adequate for prototyping and development work (if you
know the limitations). I just wouldn't ship a product built on it.

> 110 Baud as a simple example in fact refered to the transmission of an
> 8 bit data field FRAMED with 1 start-bit, 1 stop-bit and 1 parity-bit

Correct so far.

> Total data transmission size for each byte of data is therefore 11 bits and
> the physical transmission rate for the bits is 100 bits /sec.

Nope. The physical transmission rate is 110 bits per second, which is why
it is called 110 baud. But in terms of "usable" data it is only 80 bits
per second, which is 10 characters or bytes per second.

Tony said:
> 110 Baud as a simple example in fact refered to the transmission of an
> 8 bit data field FRAMED with 1 start-bit, 1 stop-bit and 1 parity-bit

To which I replied:
> Correct so far.

Actually I didn't look closely enough at that. 110 baud as implemented on
the ASR 33 and other early ASCII Teletypes and similar equipment used:
1 start bit
7 data bits
1 parity bit
2 stop bits
for a total of 11 bits per character.

Some other contemporary equipment allowed the replacement of the parity bit
by an 8th data bit, so characters were still 11 bits.

Most (if not all) equipment operating at 300 bps or faster allow only require
the use of a single stop bit, so they only need 10 bits per character. Thus
at 300 bps they can transmit 30 characters per second.

>>> I presume that it would work because of the low currents involved and the
>>> fact that RS-232 "0" can be represented by 5V. Does this mean that a 1 is
>>> anything less than 3V (which is what i believe the EIA Spec says).
>>
>> The very simple, answer is "YES." This is because any non valid input
>> voltage is defined as a logic 1 on the output. Don't become confused,
>> this is the essential point. BUT, as Mike Fahrion pointed out, there
>> are a some cases the negative swing is required.
>>
>> RS232 input to a pic can be through a single resistor [...]
>
>If the PIC is receiving data via RS232 from another device, then this is
>true. The sender will generate both positive and negative voltages. You
>should have a resistor to limit pin current and a diode to ground to keep
>the PIC's input pin from being driven to far below 0V. Be aware that you
>are giving up some noise margin, but it should work fine.
>
>If the PIC is trying to send data via RS232 output to another device, it
>won't work to significant numbers of devices. It may work fine to a PC
>or a Mac, but... Lots of equipment wants to see the negative voltage.
>

If you need that negative voltage...

I slapped together a 16c54 based data logger that would download recorded
data to a PC over the RS-232 port. I wanted to be able to to talk to the
logger with a standard terminal program to set the current date/time and
also to instruct it to do a data dump. I also wanted it small (final design
with an eeprom, I2C RTC, and battery was the size of a match box).
Data was bi-directional but half duplex. I used the standard current
limiting resister trick for the pc to pic link (with a diode) but then I
used the pc tx line as a negative voltage source for the pic to pc link
(with a resister and a npn transistor). Minor note: anything the pc sends
the pic is echoed back through the bias resister. The circuit worked fine,
(even with the pic running on a 3volt lithium cell) but as mentioned earlier
this is definitely a mickey mouse solution. I would not trust it in
production designs.

Hope this helps a bit.....

carl

----------------------------------------------------------------
Henry Carl Ott N2RVQ | talk/chat carlott@204.74.7.186@spam@carlottKILLspaminterport.net | http://www.interport.net/~carlott/
----------------------------------------------------------------
"On justice and on friendship, there is no price,
but there are established credit limits."

>
>If the PIC is receiving data via RS232 from another device, then this is
>true. The sender will generate both positive and negative voltages. You
>should have a resistor to limit pin current and a diode to ground to keep
>the PIC's input pin from being driven to far below 0V. Be aware that you
>are giving up some noise margin, but it should work fine.
>

Me again...

Microchip describe how to interface a PIC to AC power lines with just a
single resistor, or two in series for added protection. According to there
information no clipping diodes are required except for one to Vdd in the
case of RA4. I described this in my first reply.

I think if it works for 110VAC then for +/- 12VDC we could probably get away
without the external clipping diode. It's a question of limiting the
current to a safe level with a suficiently high enough resistor.

> Most (if not all) equipment operating at 300 bps or faster allow only require
> the use of a single stop bit, so they only need 10 bits per character. Thus
> at 300 bps they can transmit 30 characters per second.

Actually, I've seen a variety of items which require two--I've even coded
some. The most common instance where this is the case is with software-only
polled receive routines. Typically, when I write such a routine it would
offer the user a choice of either 9600-n-8-1 or 19200-n-8-2; the stop bit time
is when i actually get to process the data, so if I need more than 50us to
stash a byte the extra stop bit allows the link rate to run at 19200 rather
than having to slow all the bits down to 9600.

> BTW the CNCP course was where I first learned the difference between BAUD
> and bit rate.

I guage my correspondents and listeners by their interest in this arcane
corner of computer jargon: if they pay attention and understand the
difference between baud and bits per second, they're technical; if they nod
their heads ``un-huh'' a few times and don't get it, they're users.

I explain the difference another way: remember boy-scout (or armed-forces?)
semaphore signaling with flags? One flag posture per second is one baud
(and a baud is a rate, like the knot: never ``knots per hour''), but the
communication is clearly occuring at more than one bit per second, right?

> Each technician had to be able to read baudot code right off of the paper
> tape, and that was accomplished by about a week of code practice in class -
> The instructor would key baudot messages audibly ala ham radio and each
> student would hardcopy.

This is the time of year I most miss paper tape. My father used to bring
home tail ends of rolls from the phone company in Minneapolis, and we would
weave and fold these many-colored remnants into Christmas tree decorations.

> BTW the RS232 BREAK feature was a result of how the electromechanical units
> used to work. When a space was detected (start bit) the serial to parallel
> motor would advance whether the code was correct or not. Hence, if the
> current loop was down it would be interpreted as a repeated sequence of 00H
> (NULLs). The print carriage would go up and down but no striker would advance.
> To this day most USARTS support BREAK generation.

Much of our communications terminology hearkens back to telegraphy. A
single wire and earth ground return, with a key in, say, New York, and a
sounder in, say, Chicago, could carry news and stock prices one way:
``simplex''. Overnight, received messages could be recorded by an
automatically advancing paper strip and a pen attached to the solenoid,
hence: ``marks'' and ``spaces''. What should the idle state of this line
be? Well, you probably want to know if Indians (or whoever) ever pulled
down a telegraph pole, even if you weren't receiving a message at the time;
besides, ``low-power sleep mode'' hadn't been invented yet, so the idle line
state was ``mark'' and absence of current meant something was wrong. How
about if Chicagoans think they have something to tell New Yorkers sometimes?
Well, you could string a second wire, with key in Chicago and sounder in New
York: this would be ``duplex'' connection. But you could also share the
single wire and take turns in each direction, with a sounder in series with
the key at each end, and a shorting switch across each key for receiving:
this is ``half duplex'', so now the two-wire version needs a bigger name:
``full duplex''. So now suppose it's the morning of some particular day in
1871; both offices have their keys shorted to receive, so current is flowing
and both sounders or recorders are marking. New York has a 4-hour news
feed, so he opens his switch and starts keying. Both sounders are in
series, so they both click away, and the transmitter has some confidence
that he's keying into a good circuit. Now in Chicago, someone rushes up to
the newsroom with some wild story about a cow and a fire and whatnot, and he
doesn't want to wait for the 4-hour news feed to finish first. He can
interrupt New York by opening his key switch, so that both sounders go
silent. New York knows that this is either circuit trouble or else an
important interruption, so he closes his switch for a little while to see if
Chicago wants to key something. Chicago interrupted New York with a long
``space'', which we know as ``break''.

> Anyway, I hope this is not too far off topic fot the list (I guess I'll find
> out!).

>
> This is the time of year I most miss paper tape. My father used to bring
> home tail ends of rolls from the phone company in Minneapolis, and we would
> weave and fold these many-colored remnants into Christmas tree decorations.

hey! the phone company here in Minneapolis is still using paper tape...
that's probably why it's so hard to get stuff like ISDN and voice circuits
that will support v.34 modems. :-)