[sdiy] Serial Ports

Scott Gravenhorst music.maker at gte.net
Thu Sep 23 15:24:20 CEST 2004


xyzzy at sysabend.org wrote:
>On Thu, Sep 23, 2004 at 09:36:23AM +0100, Jason Tribbeck wrote:
>> It depends on the exact sequence of bytes that are being transmitted.
>
>See, this is what gets me.
>
>I've used uarts before.  The 6402 is a good friend of mine, simple to use
>and cheap... and I've never had problem.
>
>One thing that I find maddening is all the books I have that cover raw
>serial protocol all seem to assume that there is a pause between bytes, One
>of my old interfacing books even shows a bit string with pauses in between
>each byte, but I cant find any spec that says There Shall Be a Pause.

There is a pause, so to speak, in the form of the start and stop bits.  The
start bit triggers the start of the shifting process, and exactly 10 bits are
counted as they come in.  Once the stop bit is received, the system sits idle
until the next start bit.  As was said, attempting to acquire a bit stream
that was established before the circuit is listening can easily result in
data errors because there's no difference between a start bit, stop bit or
data bit except the positioning relative to the start bit.  I'm not sure, but
I think that it is assumed that the listener starts listening before the
sender sends it's first bit.  If that is the case AND the listener NEVER
stops paying attention, then the system functions perfectly.  

What I always though was cool was how the system determines whether a given
data bit is a 1 or a 0.  It is not that it simply samples the bits in the
center of each bit.  Noise could easily screw with that.  The idea is that
the bits are sampled many times, usually 16 times (this is why the input
clock to the UART chip is usually 16 times the baud rate).  The data input
bit gates a counter that is counting the clock pulses.  The counter is
cleared at the start of each bit (or 16 clocks).  After the requisite number
of sample times (usually 16 per bit), the MSB of the counter will contain the
value of the received bit.  The counter logic is such that the MSB will be
high when more than half of the input bit samples are high, or low when more
than half of the input bit samples are low.  This means that the input bits
can be corrupted with a good deal of noise and the UART will still decode the
correct state for each bit.

>
>Perhaps I'm concerned about nothing.  In theory a midi recieving device
>should never come in in the middle of a conversation unless you made a
>mistake and forgot to turn something on, so even if there isnt some pause to
>look for.  Most of the bit banging code I've looked at doesnt do anything to
>handle this, it just assumes the first bit it sees is a start bit and works
>from there to the stop bit.  Some of the code will drop the data as bad if
>it doesnt see a stop bit but most of it doesnt care and sends when it thinks
>it has 8 bits.
>
>It just seems so.... unclean or something...   
>
>> If you were really adventurous, you could write out a sequence of
>> start/data/stop bits, and work out what will happen if you start at any
>> point in time.
>
>I've got some simple code running now that just looks for serial data and
>makes the assumption of First Bit Is Start, 8 data, Then Stop.  I think
>you're right,   I'll fire up a sequencer or something to spew out a ton of
>midi data and see what happens when I turn my board on at random times.
>
>-- 
> ------------------------------------------------------------------------
> - Tom Arnold -       When I was small, I was in love,                  - 
> - Sysabend   -       In love with everything.                          -
> - CareTaker  -       And now there's only you...                       - 
> --------------         -- Thomas Dolby, "Cloudburst At Shingle Street" -
>

---------------------------------------------------------
- Where merit is not rewarded, excellence fades.
- Hydrogen is pointless without solar.
- What good are laws that only lawyers understand?
- The media's credibility should always be questioned.
- The only good terrorist is a dead terrorist.
- Governments do nothing well, save collect taxes.

-- Scott Gravenhorst | LegoManiac / Lego Trains / RIS 1.5
-- Linux Rex         | RedWebMail by RedStarWare
-- FatMan: home1.gte.net/res0658s/FatMan/
-- NonFatMan: home1.gte.net/res0658s/electronics/
-- Autodidactic Master of Arcane and Hidden Knowledge.




More information about the Synth-diy mailing list