dave-in-nj:
on the surface, this sounds impossible.
Impossible? Not at all. Sounds like he's trying to make a normal SPI bus, which always operates bidirectionally, although often we ignore the input or output side of a particular transfer. The SPI hardware in the processor has a shift register. You start by loading the register with the output byte, then the hardware starts clocking the shift register. As the bits are shifted out MOSI from one end, it is shifting in bits from MISO on the other end. When done, the internal shift register holds the input byte. You can't do this with shiftin() and shiftout() since they are unidirectional, but you can do it with SPI.transfer() or by manually bit-banging the interface.
CrossRoads:
digitalWrite (latchPin, LOW);
digitalWrite (latchPin, HIGH); // captures data on '165 inputs
dataIn = SPI.transfer(dataOut); // read in from '165 while writing out to '595
digitalWrite (latchPin, LOW);
digitalWrite (latchPin, HIGH); // move data to output of '595
Interesting. I questioned this at first, but as I think about it, it looks like it will work, but only if these shift registers are the only thing on the bus. If there are other devices using the same SPI bus (with a different CS) this will fall apart. Say you do the above transfer. Then, when you do the next transfer, the first thing that happens is the CS line is pulsed. This will once again latch the '595 shift register to its outputs. That's not a problem since the shift register still has the previous value from the last transfer.
But if there are other devices on the SPI bus, when the latch is pulsed that first time, the '595 shift register will have whatever was the last byte sent to the other device. That value will get latched to the outputs for the time between the two latch pulses. This could have very bad effects depending on what's connected to those outputs. Now, sharing the bus is not part of the OP's problem statement, so this may not be an issue for him.
SPI is a very simple protocol. But it's hard to implement a true SPI interface with shift registers.
dave-in-nj:
why not use a port expander ?
I forgot about those. Thanks for the reminder! I'm working on a project where I was trying (somewhat unsuccessfully) to make a true SPI interface out of shift registers. I just reworked it using a pair of 23s17, and it simplifies the schematic, and greatly cleans up the board layout (and takes less room.) It increases the code complexity, but I think it will be worth it.