6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Jul 04, 2024 2:12 am

All times are UTC




Post new topic Reply to topic  [ 109 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Author Message
 Post subject:
PostPosted: Sun Jan 07, 2007 3:10 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
Yes, that is a very slick approach. I hadn't thought of supporting handshaking in that manner. I was still thinking in terms of 8-bit bytes; but really, SPI is applicable no matter how many bytes are in a packet (MAX3100 has two in this case). As long as the format of all commands is the same, such that all packets are the same length, it'll work fine. Commands are executed if, and only if, the length received is correct and the command opcodes are correct. Variable-length data is fed to the device via fixed-length ``cells'', to borrow an ATM term. The fixed-length cells allows for easier status reporting. MAX3100's cell size is 2 bytes. But any other device could support more.

The protocol for the serial Flash is vastly more complex, however. In fact, it violates the SPI protocol -- the MISO signal (SO in the datasheet) is three-stated until actually driven, while SPI states that both MISO and MOSI are active at all times (even if transmitting bogus data).

In fact, I noticed in the data sheet that there *appears* to be two modes of operation --- one where the device waits one extra bit time for the response, and one where the device transmits its response as soon as the command packet has terminated. However, I didn't see where in the data sheet it selects this mode of operation. Did I miss something?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 07, 2007 1:15 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1019
Location: near Heidelberg, Germany
Quote:
In fact, I noticed in the data sheet that there *appears* to be two modes of operation --- one where the device waits one extra bit time for the response, and one where the device transmits its response as soon as the command packet has terminated. However, I didn't see where in the data sheet it selects this mode of operation. Did I miss something?


My assumption is that it depends on the state of the CLK line when /CS goes low.

Looking at the MAX3100 specs it seems to assume CLK low when /CS goes low, and then that the controller as well as the device sample the data at the rising edge of CLK, where the MAX3100 seems to send the first bit directly when /CS goes low so that the controller can sample it (as long as CLK goes low with an appropriate delay after /CS going active).
The MAX3100 would also work, if I get that right, when the controller samples at the falling edge of CLK, though. Although the behaviour for the case when CLK is high when /CS goes low is not defined. The specs seem to implicate that you loose the first bit when the first CLK pulse starts with a falling edge (exept you sample at this edge on the controller) OTOH that would disallow the internal register selection to work properly, as the device would have to send the third bit already before it had received the second bit - which is used for register selection.

Looking at the ATMEL Flash, however, if CLK is low when /CS goes low, the first data out bit is invalid (see page 9) - I wonder how you should read 8 bit of data with 8 clock pulses then in this case? If CLK is high when /CS goes low, the first data out (MISO) bit is valid only at the rising edge of CLK (which is the end of the first clock pulse). I would rather sample at the falling edge, to better accommodate for cable delays.

The LM1973 is even worse - you have to sample Data Out even before you send the first CLK pulse - if you believe the diagram. Otherwise this would mean daisy-chaining would not work as described on a later page.

Did you handle both devices with the same hardware (SPI controller)? How did you do this?

Well, wikipedia tells about the different "modes" of operation. Did you handle this in hardware? I guess so. Which means you need additional port bits to XOR the CLK line when necessary, which means you need to know in advance which device is attached to handle it appropriately....

Frankly, a "standard" with such holes is pretty ..... well, say, undefined.....
I understand that you want to use "standard" SPI devices, so I guess you will have to live with this. Otherwise I would define a "preferred mode of operation" as to CLK inactive level and which edge to sample the data...

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 07, 2007 4:20 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1019
Location: near Heidelberg, Germany
Well, if the standard were well defined, it could have been so easy....

Code:

---------+                                                 SPI
 VIA     |                                               +-----
      PA0|-----------------------------------------------| /SEL
         |           '164                                |
         |         +-------+                             |
      PB0|---------|QA     |                             |
      PB1|---------|QB     |                             |
      PB2|---------|QC    A|-----------------------------| MISO
      ...|         |..     |                             |
      PB7|---------|QH     |                             |
         |         |  CLK  |                             |
         |         +-------+                             |
         |             |                                 |
      CB1|-------------+---------------------------------| CLK
      CB2|-----------------------------------------------| MOSI
         |                                               +-----
---------+

CLK passive high
output valid on rising (trailing) edge of pulse
input latched at rising (trailing) edge of pulse

(line drivers/receivers, other signals left out for brevity)


To account for the differences of the different devices I guess some (independent) XOR in the CLK out to the bus and the CLK signal for the SR would be needed?

This even works around the VIA SR bug in that the input is deserialized by the external '164 SR (or are there other bugs?)

What do you think of this?

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jan 07, 2007 11:01 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
I think SPI as a "standard" evolved after serial devices were already in existance, which explains why there are four modes of operation. I was thinking about the relationship between JTAG and SPI not too long ago, since I realized that, quite frankly, my Kestrel 1 IPL circuit does conform to the requirements for being a 3-wire SPI device. The only thing it lacks is the MISO signal.

Which is now leading me to consider implementing another IPL circuit for the Kestrel 2 (aptly named IPL Type 3 of course, since the Kestrel 8K and 1p1 had a type-1 interface, and 1p2 and 1p3 had a type-2 interface). Whether or not it'll actually be needed, however, remains to be seen. My Kestrel emulator may make the need for IPL ports superfolous.

However, obviously, auto-configuring devices on the bus must conform to a single mode of operation. I agree that it should be made compatible with the 6522's serial port timing. I like Andre's circuit -- it seems to be an absolute winner to me!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 08, 2007 9:03 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
It's way late, so this isn't 100% well thought out. But I just realized that it is possible to use the SPI bus with only 6 wires:

Code:
(in) /RES o--------------+    +---------------o /RES (out)
     /SEL o------------+ |    | +-------------o /SEL
     MOSI o----------+ | |    | | +-----------o MOSI
     MISO o--------+ | | |    | | | +---------o MISO
      CLK o------+ | | | |    | | | | +-------o CLK
      GND o----+ | | | | |    | | | | | +-----o GND
               | | | | | |    | | | | | |
             +----------------------------+
             | | | | | | |    | | | | | | |
             | | | | | | ~    ~ | | | | | |
             | | | | | +--------+ | | | | |
             | | | | +------------+ | | | |
             | | | +----------------+ | | |
             | | +--------------------+ | |
             | +------------------------+ |
             |                            |
             +----------------------------+
             device


RULES:

1. /SEL, MOSI, MISO, CLK, and GND are tied together using bus topology.

2. /RES(in) terminates with the device. /RES(out) originates at the
device. There is NO direct connection between them.

3. When /RES(in) is asserted, the device MUST immediately assert
/RES(out).

4. When /RES(in) is negated, the device DOES NOT release /RES(out); it
leaves it asserted.

5. The device negates /RES(out) if and only if it has been properly
auto-configured by the bus controller.

6. When /SEL is asserted, MISO is three-stated by every device until a
device recognizes its address byte.

The disadvantage is that no power can be sent over the bus, and every single device, without exception, requires a microcontroller on the receiving end to implement support for autoconfiguration.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 08, 2007 11:35 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8462
Location: Southern California
It's late and a headache is keeping me up. I'll try to answer some things I didn't get a chance to answer earlier. I hope it's not too disjointed.

Quote:
6. When /SEL is asserted, MISO is three-stated by every device until a device recognizes its address byte.

That's what I²C does. With the fact that start and stop conditions are produced by bringing the data line down or up (respectively) while the clock line is high, it can do away with the select lines too. The data line is bidirectional, leaving you with only two wires plus power and ground. I think it's best to leave the I²C interface separate though.

Another way that comes to mind to handle the addressing with only one wire is that the one select line carries a number of pulses corresponding to the address you want to select. The devices' counters get reset anytime the select line is false and there's a pulse on the clock line. This again requires additional parts in front of every device though. Although I think the idea is interesting, I don't expect it to necessarily be taken seriously. It could be arranged for autoaddressing, but otherwise each device would need to be told its address, like IEEE-488 address DIP switches.

Quote:
Quote:
Putting that info in the configuration polling whether automatic or not sounds like it should do the job nicely.

Sorry, did I miss anything? How is configuration polling done when there is no ADMIIN line on the bus again?

I don't know which of two things you might be asking here, so I'll address both. If I was wrong and it's something entirely different, please rephrase your question and hopefully I'll understand.

Q1: How can the controller even poll successfully if the polling itself could produce overruns?
A1: The process, soon after controller boot-up, starts with configuration polling, where the controller asks the devices (one at a time) to send the info on how fast they can do the various things Samuel mentioned. This happens at a slow rate that any device can handle. After the controller gets this info, it can safely speed up the communication with the particular devices to the limits they dictated. The controller can poll sub-buses as well.

Q2: How does the home-made device like a bus switch or hub using a microcontroller programmed to be able to respond to polling know whether the controller is talking to it or to something on its sub-bus?
A2: After selecting such a device, the controller talks to it first. At the end of whatever communication needs to take place between the controller and the switch, the controller tells the switch that now it is going to talk to a device at the specified address on the switch's sub-bus. The switch selects the specified device on the sub-bus, much like an operator at a switchboard connects you to somebody, then quits listening. After that, the only way for the controller to again talk to the switch is to de-select the switch and then select it again, like hanging up and then calling the operator again. I'll follow up on this further down.

The polling won't work with non-intelligent SPI devices. To use them, the controller would already have to know what addresses these devices occupy, what they can do, how to use them, and how fast they can do various things. It's easy when it's not all made to be too automatic. (Sometimes overly intelligent devices cause problems, as I was reminded by my wife telling me of the frustrations of using a photocopier at school, and as I am reminded when I call a company that only has an automated answering service that only offers the choices that some tunnel-visioned person thought of beforehand.) If you want 100% autoconfiguration, you'll have to use a microcontroller in front of non-intelligent devices, even if it is dedicated to one particular device on its sub-bus. This, like the switches we've been talking about, can be made with a single microcontroller. If we agree on a protocol and I make my own using the PIC microcontrollers I'm already familiar with and can program, I can provide them for others who want them as well. The source code will be public. A microcontroller put in front of a device to add the intelligence for polling would be a little different from a switch in that it must hold the polling data specific to the device.

Quote:
Quote:
The select line going true might produce an interrupt in the device's computer so it can pause what it is doing so as to give the port whatever attention it needs, even if it needs to bit-bang (which takes more attention for a non-controller to do).

The problem is that /IRQ is a shared line. So any device requiring attention may affect the communication. I'd rather have a separate line that is defined to be driven by the selected device only.

I was not clear. The context was one of "when the device is a small computer itself that when the first byte has been sent by the device, the cpu there needs to reload valid data..." The device's own processor gets an interrupt perhaps when the device's own select line goes true, and more likely when the device's own interface receives a byte, whether instruction, data, or whatever. The device's own processor's IRQ input is separate from the bus IRQ line. The device's own computer can pull the bus IRQ line down, but does not monitor the bus IRQ. It is an input only to the controller, not the devices.


My original thinking on A2 above was that that would also de-select the device on the sub-bus. In the analogy of the controller being like a person who uses a telephone operator to make a call (I know no one does that anymore, but we sometimes talk to operators at front desks of companies when we make business calls), it would be like the caller hanging up, which disconnects the party he was calling, and also frees up that line on the switchboard. I just had another idea though. Leaving the option for the switch to keep the sub-bus device selected might take care of a problem I encountered when I was trying to design my do-everything serial bus a few years ago.

Here's the senario: You have something like a flash memory which requires a long stream of data to load a 2KB page. If you interrupt the page by de-selecting this SPI device to service another SPI device that can't wait, you'll have to start the page over when you get back to the flash. As you can see, depending on what you have going, you may never finish up that page! So what do you do? My new idea here is to use a bus switch ahead of the long-winded SPI device, and leave the option to de-select the switch without having it drop the select for the flash memory (or other device that requires long transactions). The clock buffer (maybe a section of a 74xx125) to the final device would be disabled though, and a pull-up or -down at its output (or better in some cases, a bus-holding device) would avoid problems of unwanted clock transitions. When you are ready to de-select that device so it can program the page (or do whatever it is supposed to do), after you have de-selected the switch, you re-select the switch and tell it to de-select everything on its sub-bus. Alternately you could tell it that you want to resume your communication with the device on the sub-bus.

Quote:
The protocol for the serial Flash is vastly more complex, however. In fact, it violates the SPI protocol -- the MISO signal (SO in the datasheet) is three-stated until actually driven, while SPI states that both MISO and MOSI are active at all times (even if transmitting bogus data).

I was thinking the controller should have weak pull-up (or better, pull-down) resistors so its input line is ever left totally floating.

Quote:
In fact, I noticed in the data sheet that there *appears* to be two modes of operation --- one where the device waits one extra bit time for the response, and one where the device transmits its response as soon as the command packet has terminated. However, I didn't see where in the data sheet it selects this mode of operation. Did I miss something?

I did get it going for a product we did not go through with, so I could look through my code if it's really important. It is only a 2MB flash though, which is not worth using for new designs considering its cost and the fact that it is so few megabytes compared to what's available today. SPI has modes 0, 1, 2, and 3. Some devices can figure out for themselves which mode (at least out of two) you're using. IIRC, mode 0 is most common. Keep reading though.

Quote:
To account for the differences of the different devices I guess some (independent) XOR in the CLK out to the bus and the CLK signal for the SR would be needed?

My tentative plan is to use PB0 for CLK (because it can quickly be put high and low with INC VIA3PB & DEC VIA3PB instructions), use PB1 for MOSI, PB2 for MISO, and PB3,4,&5 to a '138 for selects. Bits 6 and 7 can be tested very efficiently for input bits, but I plan to use them for a serial interface for a PC keyboard. Since the VIA's SR is not quite a match for SPI and I'm using the SRs for other things anyway (including raster graphics on an analog oscilloscope :wink: ) I'm pretty much resigned to bit-banging the serial bus.

Although it would be kind of nice to have the OS be able to handle all the humdrum serial bus communications details, the bit-banging will leave total freedom to run any mode a device wants. There's no need to reconcile differences in how various devices operate, either in hardware (as by XORing the clock) or in trying to come up with a do-everything software driver. As long as every device uses a CS\ (low to enable), any combination of them can be on the bus at the same time, each operating the way it wants to.

BTW, on the LM1973 digital pot, I did not use the serial out (MISO) line. This device's interface is very simple, and it only needs to be a listener and not a talker in most situations.

Below is a list of things that come to mind that I know I've seen available with synchronous-serial interfaces. A complete list would be much longer. There are thousands of such ICs on the market. One piece of equipment we construct could have several of these in the one unit.

temperature sensors
programmable-gain amplifiers
A/D & D/A converters
analog switches
signal generators
LCDs
LED display drivers
UARTs
digital pot.s
I/O expander ports
relay drivers
reat-time clocks (RTC)
USB interfaces
keypad scanners
non-volatile memory

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 08, 2007 7:02 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
GARTHWILSON wrote:
That's what I²C does. With the fact that start and stop conditions are produced by bringing the data line down or up (respectively) while the clock line is high, it can do away with the select lines too. The data line is bidirectional, leaving you with only two wires plus power and ground. I think it's best to leave the I²C interface separate though.


The data line, being bidirectional, means that it's not what SPI does, since it assumes the MISO line is always driven. What I was saying was to deliberately break the standard just enough to permit single-select-line operation.

Quote:
Another way that comes to mind to handle the addressing with only one wire is that the one select line carries a number of pulses corresponding to the address you want to select. The devices' counters get reset anytime the select line is false and there's a pulse on the clock line. This again requires additional parts in front of every device though. Although I think the idea is interesting, I don't expect it to necessarily be taken seriously. It could be arranged for autoaddressing, but otherwise each device would need to be told its address, like IEEE-488 address DIP switches.


I think it'd be easier to have a rule: if /SEL is asserted, then MOSI is shifted into an address register. If /SEL is negated, then it is shifted into the currently selected device. This is simpler, and I think would use less logic.

Quote:
Here's the senario: You have something like a flash memory which requires a long stream of data to load a 2KB page. If you interrupt the page by
...


This just smacks of how Commodore did things; see, each device, particularly disk drives, had their own operating system and device drivers on board. The application on the Commodore CPU would issue amazingly high-level commands to the devices as appropriate. For example, to format a disk:

OPEN 1,8,15,"N0:MY DISK NAME":CLOSE 1

The fact that you're addressing subaddress 15 on the disk drive (unit 8) was all that was necessary for the DOS resident on the drive to know that you're issuing a command. In fact, it doesn't matter if it's specified as a filename or as normal data, leaving the ability to send multiple commands:

OPEN 1,8,15
REM FIRST, FORMAT THE NEW DISK.
PRINT #1,"N0:MY DISK NAME"

REM NOW, COPY THE DATA OVER FROM THE MASTER DISK.
GOSUB 1000:REM WAIT FOR DISK TO FINISH
PRINT #1,"C0:MY FILE=1:YOUR FILE"
CLOSE 1

Notice also a bit of pipelining here; after sending the command to the disk, the CPU is free to do whatever else it needs to do in the mean time, thus making certain kinds of programs MUCH faster than their DOS, Windows, or, hell, even Linux equivalents.

Quote:
I did get it going for a product we did not go through with, so I could look through my code if it's really important. It is only a 2MB flash though, which is not worth using for new designs considering its cost and the fact that it is so few megabytes compared to what's available today. SPI has modes 0, 1, 2, and 3. Some devices can figure out for themselves which mode (at least out of two) you're using. IIRC, mode 0 is most common. Keep reading though.


This isn't what I was talking about.

Look again at the data sheet. You'll notice two sets of timing diagrams: one where there is one extra bit inserted between when data is sent to when it is received, and one where there isn't. This has nothing to do with SPI mode, so far as I am aware, as they use the same phase and polarity for the clock in both diagrams. Look in particular on diagrams on pages 13 and 14.

But Andre already answered by question; although the clock and phase are identical for the actual transfer of data, the *initial* state of CLK is what determines which, which to me, is utterly stupid. :) But I digress.

Quote:
Although it would be kind of nice to have the OS be able to handle all the humdrum serial bus communications details, the bit-banging will leave total freedom to run any mode a device wants.


You can still have a nice OS-level API for the serial bus. All you need is to remember a bit of state when addressing a device:

Code:
;
; Address the device to receive our special, important message.
;

LDA #spi_mode   ; 0, 1, 2, or 3
LDX #device_id   ; 0 .. 6
JSR SPI_beginTransaction

;
; Send the message, and at the same time, receive the data it
; sends back.
;

LDA #'H'
JSR SPI_exchangeByte
STA result

LDA #'I'
JSR SPI_exchangeByte
STA result+1

;
; Release any select lines on the bus; we're done.
;

JSR SPI_endTransaction


Of course, Kestrel's firmware will have a bit more sophistication than this for various reasons I'll explain in my book. But this is the core essence, the absolute minimum interface. Heck, even SPI_endTransaction can be implemented as:

Code:
.export SPI_endTransaction
.proc SPI_endTransaction
    ldx #7
    jmp SPI_beginTransaction
.endproc


:)

I of course don't recommend having applications depend on a "magic address" to de-select all devices on the bus, since that magic address can change and, necessarily, is hardware dependent. Consider a system with two, or more, SPI port interfaces (not strictly necessary of course, but this is a what if scenario). And, besides, it's more self-documenting that way too.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 09, 2007 4:26 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8462
Location: Southern California
Quote:
Did you handle both devices with the same hardware (SPI controller)? How did you do this?

Well, wikipedia tells about the different "modes" of operation. Did you handle this in hardware? I guess so. Which means you need additional port bits to XOR the CLK line when necessary, which means you need to know in advance which device is attached to handle it appropriately....

I missed this last time. No, I did not add hardware. It wasn't necessary since I bit-banged. I did not put the UART and the flash on the same bus at the same time; but to test my idea for mixing SPI and I²C on the same bus a few years ago, I did put four different serial devices on one bus, one of them being the UART. Again, this was bit-banged.

Quote:
I think it'd be easier to have a rule: if /SEL is asserted, then MOSI is shifted into an address register. If /SEL is negated, then it is shifted into the currently selected device. This is simpler, and I think would use less logic.

Hmmm... Now I have to chose between simpler logic at the devices and a smaller connector and cable. The latter would also save a couple of VIA pins, and a single address shift register at each device allows up to 255 addresses instead of only 7, reducing the need for sub-buses. Since we're shifting instructions and data in and out serially, making the address serial as well will not slow things down much at all. Now we could get down to a narrower ribbon and 10-conductor IDCs. Next down from 20 which we were talking about is 16, then 14 (which seems less common), and then 10. I wanted to keep the devices simpler, but this is kind of appealing, yunoit?

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 09, 2007 5:59 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
To help keep things organized and goal-oriented, I am going to start another Serial Interface Bus thread for the smaller connector version of the concept. We can use this thread for the 20-pin version.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 09, 2007 6:20 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
I actually like both ideas. But, the nice thing about the bigger connector, as you say, is the fact that addressing is implicitly handled by virtue of the hardware itself. For the simpler connector, the on-board microcontroller would serve the function of a switch -- the first byte it receives is the device's address, and if it matches its configured address, then it can gate (via external three-state buffers perhaps) the SPI bus onto the rest of the logic.

If there are multiple sub-functions on the device (e.g., a single module handling keyboard, mouse, and DACs for left and right audio, for example), the controller will need to understand that it has to send the device's address and the subaddress byte immediately afterwards, so that the microcontroller knows which device to gate the bus to.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 09, 2007 6:22 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
The other thing too is that the small-connector SIB fits perfectly with the large connector. Just make it device #7 or some such. So, if it is of greater importance for you to have an SIB right now, I'd probably go with the 20-pin SIB to start with, since it can be made most easily right away.

The small-connector SIB can come later, and is easily added into an existing 20-pin SIB. The reverse isn't nearly so easy, however.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 09, 2007 8:27 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8462
Location: Southern California
I spent only a few minutes considering connectors for this, and then concluded that there's no reason the computer can't have both interfaces, possibly even sharing some of the same VIA pins, if one interface is built and then the other one added later.

Quote:
I am going to start another Serial Interface Bus thread for the smaller connector version of the concept.

Not a bad idea, since a topic that's many pages long is a bit unwieldy when referring back in the archives. In the new one, just post a link to this one and tell why you're starting the new one.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 09, 2007 5:56 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1019
Location: near Heidelberg, Germany
Quote:
I think it'd be easier to have a rule: if /SEL is asserted, then MOSI is shifted into an address register. If /SEL is negated, then it is shifted into the currently selected device. This is simpler, and I think would use less logic.


How do you do this with a "hub"? How does the hub know that an address is for a sub-device or not? Or is the MOSI_when_/SEL_asserted byte broadcast?

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 09, 2007 7:07 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
To address a device on the local bus:

1. Assert /SEL
2. Transmit address byte.
3. Negate /SEL

To clear the bus:

1. Assert /SEL
2. Transmit an address that you know nobody is using.
3. Negate /SEL

To address a device down-stream from a hub:

1. Assert /SEL
2. Transmit the hub's address
3. Negate /SEL
4. Transmit commands to the hub to assert or negate its down-stream /SEL as appropriate, following the procedures above


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Feb 03, 2007 7:28 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8462
Location: Southern California
Well, I thought I'd have this built by now, but I'm glad for the input I've gotten here even if it has made me wait. You've brought up good things to think about.

Quote:
We, of course, need more input from other users.

Now as I write, these two topics (including the "small-connector version" topic) say they've had 1546 views. It would be interesting to know how many others have been quietly reading and just have not felt they had anything to contribute. I'm afraid many of the forumites still are not acquainted with simple synchronous-serial interfaces, which is why I've wanted for the last couple of years to write an article on them, and just haven't been able to give it the time yet. (If we can find a good article already out there and just link it, that would help, although it wouldn't have 6502- and 6522-specific software and other info.) [Edit: There's a non-detailed decription of the various popular serial interfaces at viewtopic.php?t=1301&start=28 .] Others know what they are, but don't have practical experience to know what characteristics would be valuable in real-life applications.

Quote:
However, you've got a lot of neat projects, and it'd be nice to use your circuitry with the Kestrel, and vice versa.

I appreciate the vote of confidence. Since our discussion above slowed down, I've gone through a lot of gyrations here looking for the ideal configuration, but I find that every idea comes with major disadvantages. It has been too many to list here.

What I seem to be arriving at is a mix of my original idea plus the intelligent front-ends and hubs discussed above. This seems to include most of the best of both worlds. I need to be able to set up various simple tests and experiments quickly, and I've built enough (scores) of these projects to know what happens to the construction time when I go for complexity beyond the necessary.

The intelligent front ends and hubs can still be used with the simpler multi-select-line bus. They can probably be identical, but the intelligent front end will have only one device on its sub-bus, and its other sub-bus select lines will go unused. The intelligent front end allows for the senario I gave above where you want to transfer a 2KB page to an SPI flash memory and need to interrupt the transfer to service another SPI device (on another sub-bus) that can't wait that long. The flash's own select line remains true so you don't have to start the page over again when you resume, but its clock and data lines are isolated from the master while something else is being serviced.

A hub and an intelligent front end would both need something like a 74HCT125 quad tri-state buffer and a microcontroller with a slave SPI port. Probably the only difference between them would be in the data programmed into the microcontroller, enabling each intelligent device to tell the master what class of device it is, what it can do, how fast it can go, etc. when polled for autoconfiguration. I don't plan to carry it that far myself, at least to start. Maybe later.

The hub allows interfacing far more devices than the six or seven suggested by the number of select lines coming through the master's SPI bus connector. The hub will have a sub-bus behind it with the same specifications. Hubs can be nested several levels deep if needed. Anything that can go on the master's own SPI bus can go on a hub's sub-bus the same way. General-use hubs will have a sub-bus connector identical to the master's own SPI bus connector. Dedicated hubs would be used inside a piece of equipment that uses several SPI devices on its sub-bus.

After our little discussion on the potential problems of a device expecting power on a bus whose master provides none, or being plugged in powered up before the master is turned on, I looked in my National/Fairchild books and found that 74HC inputs and outputs' protection diodes can handle up to 20mA each, continuously, meaning that low-powered devices won't suck enough current to hurt those diodes. The same is true of PIC microcontrollers. So I'm not as concerned as I was before. Since most devices will take very little power, I do want to put +12V on the bus. I could forgo the -12V. For low-power parts, a 78L05 3-pin TO-92 5V regulator is cheap, tiny, easy, and quick; but if line drivers or op amps or something else needs something above 5V, it becomes a bigger job to derive it from 5V. That's the reason for not just putting 5V power down the cable.

For now I may not worry about 3V operation. It would require additional hardware (read: construction time) on many 5V devices that have 0-5V output logic. Most of the interfacing ICs can operate at 5V anyway, and some 3V parts are 5V-tolerant.

This still does not address peer-to-peer communication or multi-master set-ups, but these are not characteristic of SPI anyway. André, your desire for extra handshaking lines could conceivably be met by using others of the select lines that would not be used if you just connect two peers together with no real master. Some kind of switching, whether manual or electronic, might offer the choice of uses of those other lines. But then it's not really a standard. The better way to do what you want might be more like an SS-22 interface, in a loop, with two connectors on each device, In and Out, each having clock and data going from sender to receiver, and CTS going back to the sender carrying a pulse telling the sender it's ok to start the next byte, and of course ground. It could conceivably done with four wires per cable and even RJ-11 telephone connectors. Then you use an interface loop.

The interface loop Samuel and I were talking about is where all devices are connected in a circle, with each device (including the current controller) sending packets to the next device, without the controller dictating bit rates and such. The various devices won't necessarily send at the same time or rate, and may take varying amounts of time to process information before passing it to the next device. The connection is simpler, but the software is more involved and every device, without exception, must have the intelligence to support it.

I sure would like to be able to use 4-pair CAT-5 cable with RJ-45 connectors (even though they don't go nicely into .100" centers on perfboard) for the SPI bus, but I have had to concede that I just cannot meet the needs that way. Although-- I might say-- the small-connector version could connect a single, non-intelligent device to the master without the autoconfig, auto-address, polling, etc.-- again, only if there's only the one device out there. What I'm leaning heavily toward right now is back to a 16-pin IDC, pinned something like:

Code:
       +----+----+
  GND  |  1 |  2 |  CLK
       +----+----+
  GND  |  3 |  4 |  MOSI
       +----+----+
 +12V  |  5 |  6 |  MISO
       +----+----+
 +12V  |  7 |  8 |  IRQ\
       +----+----+
 -12V  |  9 | 10 |  CS1
       +----+----+
  CS2  | 11 | 12 |  CS3
       +----+----+
  CS4  | 13 | 14 |  CS5
       +----+----+
  CS6  | 15 | 16 |  GND
       +----+----+


The power supply lines would be AC-bypassed to ground. The supply voltages are not necessarily regulated, and their exact voltages are not critical, at least in my experience. The only thing I set exact voltages for is programming microcontrollers, and any new programmers will probably be able to set their own voltage under software control. What I have now shows the programming voltage on the workbench computer's LCD, and I watch that to adjust the power supply, then press "Enter". If the voltage gets out of spec in the course of programming scores of devices, the computer stops and tells me to re-adjust.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Last edited by GARTHWILSON on Wed Mar 07, 2012 10:13 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 109 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: