Re: Another 6522 SPI question
Posted: Wed Nov 22, 2023 1:24 am
gfoot wrote:
How about this version - put MOSI on bit 2, with bit 1 being an unconnected output pin, and then:
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
Code: Select all
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
(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.
-- Jeff