Newsgroups: comp.robotics
Path: brunix!uunet!wupost!uhog.mit.edu!news.media.mit.edu!fredm
From: fredm@media.mit.edu (Fred G Martin)
Subject: Re: SPI ports on the Mini Board
Message-ID: <1993Jul26.133455.16295@news.media.mit.edu>
Sender: news@news.media.mit.edu (USENET News System)
Organization: MIT Media Laboratory
References: <m53ci3INN2l8@appserv.Eng.Sun.COM>
Date: Mon, 26 Jul 1993 13:34:55 GMT
Lines: 114

In article <m53ci3INN2l8@appserv.Eng.Sun.COM>
cmcmanis@yikes.Eng.Sun.COM (Chuck McManis) writes: 

>Using the SPI port on the miniboard is a, as yet, none to popular
>thing to do. There are two reasons for this, the first is that there
>aren't any SPI functions in the library :-) and the other is that
>given the miniboard's layout the SPI port is harder to use than it
>might be.

I think you are being a bit harsh here Chuck.  I've looked at the
spec's for a bunch of commercial boards based on the 6811, and the
Mini Board is the only one I know of that gives you a pair of RJ11
jacks for building SPI networks!  Most other boards just give you male
headers leaving you to build you own custom cables (fun, fun).

With the MB, it's just a question of understanding the proper SPI
configuration and plugging in RJ11 cables.  That's -much- easier than
building custom connections.

>The 4 pins that are available on the SPI port are "SCK" (clock), "MOSI"
>Master Out/Slave In, "MISO" Master In/Slave Out, "SS" Slave Select.
>On the miniboard, while slave select is actually connected through a
>resistor to the RJ-11 connector that resistor is grounded so SS/ is
>not useable on the stock miniboard. This has some serious ramifications
>on how you can use the port,* specifically you cannot use the CPHA equals
>zero mode of the SPI port. 

This is true: you must use CPHA equals one mode.  However, once you
realize this, you don't have to assign another 6811 output for
enabling the SS pin on receiving MB's.  All MB's can act as an active
slave without any special hardware enabling required from the master
MB.

>Another feature of the miniboard (RS-232
>hack) restricts the use of the DWOM bit (it must be "off"). 
>Because of these the bits you are left to play with are MSTR (master/slave)
>CPOL (clock polarity) and whether or not the slave output buffers are on.
>The result is that it is fairly easy to hook up two miniboards, and a
>bit more complicated to hook up more than 2. 

This is true (DWOM must be off if you want your async serial comm to
work) but your interpretation is misleading.  The main reason you'd
want to put the Port D pins into wired-OR mode is when you have a
network of multiple SPI ports, so as to avert the problem of multiple
mastering causing latchup.

However, the MB has an alternate solution to this problem:  1K
resistors -in series- with the SPI data and control lines.  So while
you normally wouldn't put the SPI pins in to wired-OR mode, you don't
need to, because you have latch-up protection anyway:  if two 6811's
are driving SPI lines in opposite directions, there's 2K of resistance
between them, which should prevent latchup from occuring.

>Additionally you cannot use a "regular" RJ-11 cable because the pins
>on the two RJ-11 jacks are connected in parallel rather than having
>one inverted. The necessates that you either buy a cable with a half
>twist ie part # H21441-03-ND from digikey for a 3' cord. Alternatively
>you can make one with crimp on RJ plugs. The correct wiring is both
>ends wired "identically" (same order of wires into the plug in similar
>orientations of the plug.)  

True: you have to use half-twist RJ11 cables with the MB's "both ports
the same" wiring diagram.  On the other hand, if the MB were wired
with "mirror image" SPI ports, you could use "normal" RJ11 cables, but
then you would have to keep track of which port the SPI cable you are
holding is plugged into on the other end.  Depending on the
layout/distance between MB's, this could be more of an annoyance than
a feature.

RJ11 cable crimpers, especially the 4-wire versions, are quite cheap
($10 to $15).  Anyone who's serious about using the SPI will want to
build cables of custom length (be they short for multiple MB's on a
single robot, or long for MB's controlling different things in a room
or house), and cost is really not an issue here.  You save money after
building just a few cables.  And for the hobbyist, you've pointed out
that DigiKey sells the proper cable... so is this really an
inconvenience? 

>* it seems that a couple of things could have been "fixed" by using 6
>  conductor RJ-11 plugs rather than 4, alterantively the Miniboard has
>  a perfectly good I/O pin simply tied to ground (PD5/SS). 

If I understand the SPI correctly, tying the SS pins together wouldn't
work, because the SPI master also uses the SS line as an input (to
perform multiple master collision detection).  So you'd need another
681 output to drive the slave SPI's.  The only logical choice for
driving the SS lines is the PA7/PAI/OC1 line, since this can be put
into a high-Z state (necessary for allowing different 6811's to become
masters).  Then you have a configuration in which the 6811 that wishes
to become a master drives its PA7 line low, selecting all of the other
6811's as slaves.  This isn't much better than just having all of the
SS's wired to ground all the time... maybe I'm missing something about
how the SS line works when a 6811 is an SPI master.

>Anyway the interesting bits are:
>	1) You _must_ assert SS to be true for the master to
>	   actually send data. (even it if isn't used)
>	2) The slave can lose "sync" with the clock which shifts
>	   the bits in interesting ways (screwing intelligability)
>	   Unfortunately we can't use SS as a sync point.

Can you explain this point?  Shouldn't the slaves sync off of the SCK
line?  I'm afraid I don't understand how one would use SS for sync
automatically, or why not using it causes sync problems.

>	3) Set the DDRD bits correctly for port D.
>

Anyway, sorry if this message seems a bit harsh, but it felt like you
were unfairly trashing the Mini Board's SPI configuration. :-)
It certainly should be useful to others to get a detailed explanation
of the proper SPI configuration to use, along with sample code.

	-Fred
