gfoot wrote:
How about this version - put MOSI on bit 2, with bit 1 being an unconnected output pin, and then:
Whoa -- VERY nice, George! That's about 23% faster than my latest effort (which AFAIK was already in first place compared with anything similar).
And bit1 needn't be wasted and left unconnected -- it's still available for other applications. (This applies to unused bits in my version, too.) If the other application uses the bit as an input then there's no interference from the writes done by the SPI code. And even if the other application does use the bit as an output, it's possible -- depending on the scenario -- that the interference will be tolerable, as long as both applications aren't simultaneously active. (I know Garth gets some extra serious mileage by having umpteen applications on a single VIA port...
)
So, on the VIA port we have...
- bit7 is in input mode -- attaches to MISO
- bit6 is available for other uses, esp. as an input, or it may be chosen as the one to output MOSI
- [... same ...]
- bit2 is available for other uses, esp. as an input, or it may be chosen as the one to output MOSI
- bit1 is available for other uses, esp. as an input
- bit0 is in output mode -- attaches to Ck
And -- for even more speed
-- your version of the code lends itself very readily to loop unrolling, for a further savings of as much as 3 cycles per SPI bit! For example, here I've unrolled by two:
Code:
SPIBYTEIN: LDA #$FE ; for counting, and as a nice supply of set bits
SEC
INPUTLOOP: 4 STZ VIAPORT_IO ; Ck=0, mosi=0
6 ROL VIAPORT_IO ; set Ck=1, shift MISO into carry
2 ROL A
4 STZ VIAPORT_IO ; Ck=0, mosi=0
6 ROL VIAPORT_IO ; set Ck=1, shift MISO into carry
2 ROL A
3 BCS INPUTLOOP
That's 13.5 cycles per SPI bit, plus a few cycles for the setup code. And with 8X unrolling it's
12 cycles per SPI bit.
(And knock off 2 more cycles if your I/O is in zero-page, as is mine. I won't dispute that priorities vary -- that's fine -- but for a further
20% increase... )
Quote:
Though I think for SD cards you're meant to be sending set bits - not clear bits - on MOSI when reading data.
You sound a little uncertain about this point (and so am I). Can anyone confirm? In any case, it's true (as you say) that you can avoid the issue. Just load an appropriate value into X or Y and use STX or STY instead of STZ.
-- Jeff
_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html