I needed a s/w SPI, so rather than re-invernt the wheel, I figured that there was bound to be one already available, and sure enough there is AVR320. Will someone look at the appnote and associated code and tell me that I'm not suffering from severe brain-fade.
1. The document says (in Features, then in Theory of Operation) that it implements a Mode 0 SPI. But the diagram (Figure 2. SPI Transmission Timing) illustrates Mode 1 operation.
2. The code (avr320.asm, subroutine rw_spi:, near the end of the doc) outputs the initial value on MOSI, allows a couple of clock cycles, then sets SCK high, delays for the hi-time of the SCK period, sets SCK low, delays for the lo-time, **and only now** samples MISO, then loops back to output the next bit on MOSI!
That is nonsense for a Mode 0 configuration - it will not capture the first (MSB) bit from the slave. I think it might function with a Mode 1 slave, although from its structure and comments it is clearly not intended as such.
And just a bit more fuel for the fire - in "AVR151 Setup and use of the SPI doc2585.pdf" the heading for section 2.5 should say Mode 0 and Mode 2, and the heading for section 2.6 should say Mode 1 and Mode 3.
No wonder newbies have trouble when you mix bad documentation/examples with peripherals that may have to use one of the less common modes.
Or maybe I'm just having a bad dream.