4
\$\begingroup\$

In a system with N SPI devices it would normally take N+3 pins on the master to communicate with them all (NxSS, SCLK, MOSI, MISO). With N being large and the master device (FPGA) is pin limited, I'm considering the following 2 techniques to increase the number of possible SPI devices in the system; and would like to know if there any (additional) reasons should not be used ? (I've listed reasons I can think of at the end)


Technique 1) Use 'K' SCLK lines (and 'N' SS lines) to effectively "select" NxK devices. Only 1 SCLK line would be active at a time.

  • U1: SCLK1 and SS1 (U2 selected but receives no clock)
  • U2: SCLK2 and SS1 (U1 selected but receives no clock)
  • U3: SCLK1 and SS2 (U4 selected but receives no clock)
  • U4: SCLK2 and SS2 (U3 selected but receives no clock)

schematic

simulate this circuit – Schematic created using CircuitLab

11 lines (MISO, MOSI, 5xSS, 4xSCLK) could operate a 4x5 matrix of 20 devices).


Technique 2) Multiplex MOSI, using 'J' MOSI lines sending null commands to all devices but one, expecting only the targeted device to reply and the others to remain high impedance on MISO.

  • U1: MOSI1 and SS1 (U2 selected but receives null command)
  • U2: MOSI2 and SS1 (U1 selected but receives null command)
  • U3: MOSI1 and SS2 (U4 selected but receives null command)
  • U4: MOSI2 and SS2 (U3 selected but receives null command)

schematic

simulate this circuit

Again, 11 lines could operate a 4x5 matrix of 20 devices.


Using both schemes together, the 11 pins could be used as 4xSS, 3xMOSI, 3xSCLK, 1xMISO, totaling 36 combinations of uniquely selectable devices (virtually selectable). Regarding the Atmel 25M01 serial flash, I can't find any problem with using both of the above schemes. (I know of no SPI master that does this; a custom implementation would be done in a FPGA.)

Concerns I have considered are:

  1. A pulse on SS and not providing a clock might put a slave device into an unknown state, especially if there is activity on MOSI (I doubt it; all "activity" is received via SCLK edges. The Atmel documentation states that the SPI communication scheme is "reinitialized" after every SS cycle)
  2. An active level on SS might already put a chip's MISO in drive mode (Like the Atmel AT25M01 serial flash, I think most chips would wait for a command before coming out of high impedance?).
  3. Sending a NULL command might still invoke a response; in fact there isn't a definition of a "Null" command, only the concept of an "invalid" command. (the Atmel documentation states it will not respond to an invalid command and remain in high impedance)
  4. The design might one day be changed and a different SPI device is added. Do most Flash SPI devices address the above concerns, or am I just lucky with the 25M01?
  5. Some devices such as the Maxim MAX1242 ADC take immediate action solely due to the SS active edge; the ADC starts a conversion on the high→low transition.
  6. Edit: One concern I didn't think of is fan-out. (as mentioned in the answer; I thought it deserved mentioning here)
\$\endgroup\$
8
  • 1
    \$\begingroup\$ Why not multiplex SS? This will let you control 2**n devices with n+4 pins. \$\endgroup\$ Mar 28, 2014 at 7:09
  • \$\begingroup\$ have you considered using a multiplexer IC such as the MAX350? In their design showcase E-journal thing pdfserv.maximintegrated.com/en/ej/EJ31.pdf on page 11, they show a serial-control multiplexer for expanding a single GPIO for SS into effectively 4 SS pins. The IC itself needs it's own SS pin though - so you are really only gaining 2 more SS pins by using 2 (one to change state of the multiplexer IC, and one that is being multiplexed). For the most commonly used SPI devices attached to that IC you would keep them as the default selected channel, and for slow/uncommonly read devices y \$\endgroup\$
    – KyranF
    Mar 28, 2014 at 7:11
  • \$\begingroup\$ Yes, adding a multiplexer is another solution. I does have the cost of adding another part. Another solution is to use an FPGA with more pins. Lets assume that the question stands as "I only have this hardware, and I have a limited number of pins". \$\endgroup\$
    – Michael
    Mar 28, 2014 at 7:16
  • \$\begingroup\$ Alright, courtesy up-vote for the noob :) But not an answer because the question is "are these techniques valid", not "can anyone think of another way to do this". \$\endgroup\$
    – Michael
    Mar 28, 2014 at 7:20
  • \$\begingroup\$ Haha thanks mate. The techniques that you show will only work if your master has two SPI buses. But it seems that you could indeed control x2 the amount of SPI devices in the way you show, by sharing the SS pins to ICs which have different bus MOSI lines. Other than what you say with special ICs like ADC sample being initiated on SS activity, it should be fine. Maybe have special devices on dedicated SS pins while other more general purpose ones are on your shared lines. \$\endgroup\$
    – KyranF
    Mar 28, 2014 at 7:31

2 Answers 2

3
\$\begingroup\$

I think your solution will probably work, within some constraints. The obvious one is "all SPI slaves must exhibit precisely the same bus behaviour as an Atmel 25M01". Also, I far prefer technique 1. Some specific answers:

  1. A PGE on a /CS line should always cause any incomplete bus transaction to terminate immediately, so even if there is the odd spurious clock generated on selected devices that are not the current target they will be cleared in normal operation. Similarly, a /CS window that doesn't enclose any transitions on SCLK shouldn't start any bus transactions.
  2. This is more of an issue. You need to be certain that this won't happen and, as noted, you will need to be clear for maintenance purposes that any new SPI devices don't actively drive the MISO line until they receive a "read" command. You might want to consider fan-out, too; I know high-impedance outputs don't represent much of a load, but 19 of them is worth paying attention to.
  3. If you don't use technique 2, then this doesn't matter...
  4. SPI memory devices, particularly larger ones, are increasingly meeting JEDEC standards for communications behaviour. If you choose devices that are JEDEC-compliant then you should have no interoperability issues, at least until the standards change.
  5. True, but many SPI ADC's actually use the SPI clock to run the ADC's successive approximation state machine. No clock cycles, no output. That said, they might drive the bus immediately. Back to my original point: set a standard, and require that slave devices that don't meet the standard are not attached to the bus matrix.
\$\endgroup\$
2
  • \$\begingroup\$ It occurs to me that if the reason you're doing this is you need a large amount of flash that can be accessed with a relatively narrow bus, why not just use an SD card? SPI mode still works, and you can just use a flat filesystem if you don't want the overhead of a full filesystem implementation. \$\endgroup\$
    – markt
    Mar 28, 2014 at 21:33
  • \$\begingroup\$ There are other design restraints that limit me to certain parts; I'm already working with the highest capacity devices and the customer is still asking for ways to further increase the capacity. I really wanted to be clear that the question is precisely "can I do this with SPI", and not "can anyone think of another way to do this". Cheers though! \$\endgroup\$
    – Michael
    Mar 30, 2014 at 9:12
1
\$\begingroup\$

Some devices will float their output line until they receive a "read" command, while others will drive it as soon as they are selected. If you are using devices which will float their output until they receive a command, and which will when selected sit perfectly happily without driving their output if they receive a sequence of 00 or FF bytes after being selected, and if you don't mind using software bit-bang routines, you might be able to wire the devices as a "cube", with CS wires, CLK wires, and MOSI wires, being the planes, rows, and columns; capacitance on MISO might be an issue, however.

For controlling 64 devices, I might be inclined to use two 74HC138 (http://www.ti.com/lit/ds/symlink/sn74hc138.pdf) chips--one to control CS and one to control clock; use a 74HC151 (http://www.ti.com/lit/ds/symlink/sn74hc151.pdf) to multiplex MISO (connecting the chips in groups of eight, controlling clock and MISO together).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.