Hi,
I was using a SD card with FatFs on a Apple 2 with a VIA 6522 card.
The VIA shift register is used for sending a byte to the SD card, whereas a bit-bang routine (from some C64 group on the Net) was used for receive.
A low ohm resistor is placed between CB1 (SR clock for Send) and Port B0 (Bit-Bang Clk for Receive) just to isolate the outputs. (I've no better way to connect the pins (B0 and CB1) to the SCK the SD card).
Diodes are used to isolate the 5V outputs from the 3.3V inputs of the SD card (with pullups to 3.3V)
A drawing is desperately needed here! Anyway it works with NMOS and CMOS 6522.
Below is a snippet of the bit-banged code for receiving a byte from the SD card (rcvr_mmc).
Just follow the pin connections on Port B. ~12 clocks per bit when unrolled.
Code:
=======================================================
; Faster loading when used SR as output compared to when SR used as input
; SCK Bit 0 // Serial Clock (output) SD Pin 5
; MOSI CB2 // Master Out / Slave In (output) SD Pin 2
; MISO Bit 7 // Master In / Slave Out (input) SD Pin 7
; CS Bit 2 // Slave Select SD Pin 1
; CB1 - clock jumpered to SCK (through 40 ohm resistor )
; CB2 - MOSI
via_ora equ $c0f1
via_orb equ $c0f0
via_dra equ $c0f3
via_drb equ $c0f2
via_sr equ $c0fa
via_acr equ $c0fb
; Preserve X-Reg if used ..phx ...plx
; ACC and Y-Reg always destroyed
via_init:
lda #$7f
sta via_drb
lda #$18 ; shift reg clocked by Phase 2
sta via_acr
rts
xmit_mmc:
sta via_sr
rts
;xmit_mmc:
; tay
; and #$80
; sta via_orb
; inc via_orb
; tya
; asl a
; tay
; and #$80
; sta via_orb
; inc via_orb
; tya
; asl a
; tay
; and #$80
; sta via_orb
; inc via_orb
; tya
; asl a
; tay
; and #$80
; sta via_orb
; inc via_orb
; tya
; asl a
; tay
; and #$80
; sta via_orb
; inc via_orb
; tya
; asl a
; tay
; and #$80
; sta via_orb
; inc via_orb
; tya
; asl a
; tay
; and #$80
; sta via_orb
; inc via_orb
; tya ;(2)
; asl a ;(2)
; and #$80 ;(2)
; sta via_orb ;(4)
; inc via_orb ;(6)
; rts
;rcvr_mmc: ; shift register in using phase 2 - ACR=0x08
; lda via_sr
; nop ; min 14 cycles between for 1 byte
; nop
; nop
; nop
; nop
; nop
; nop
; lda via_sr
; rts
rcvr_mmc:
ldy #$01 ; set clk hi
lda #$00
sta via_orb ; clk lo, cs lo
sty via_orb ; clk hi, data will be in bit 7 shortly (4)
asl via_orb ; data in bit 7, clk lo after shift left (6)
rol a ; carry into A (2)
sty via_orb ; clk hi, data will be in bit 7 shortly
asl via_orb ; data in bit 7, clk lo after shift left
rol a ; carry into A
sty via_orb ; clk hi, data will be in bit 7 shortly
asl via_orb ; data in bit 7, clk lo after shift left
rol a ; carry into A
sty via_orb ; clk hi, data will be in bit 7 shortly
asl via_orb ; data in bit 7, clk lo after shift left
rol a ; carry into A
sty via_orb ; clk hi, data will be in bit 7 shortly
asl via_orb ; data in bit 7, clk lo after shift left
rol a ; carry into A
sty via_orb ; clk hi, data will be in bit 7 shortly
asl via_orb ; data in bit 7, clk lo after shift left
rol a ; carry into A
sty via_orb ; clk hi, data will be in bit 7 shortly
asl via_orb ; data in bit 7, clk lo after shift left
rol a ; carry into A
sty via_orb ; clk hi, last bit comes in
cpy via_orb ; (4) no need to clear clk
rol a
eor #$01 ; fix first last bit0
rts
end