I've started to think about this project since it's finally the time to build a light 65xx SBC too, not "only" interfacing with existing computers, but still I'd like to keep the "common I/O bus" idea, so I can use the same devices created by me on various range of hardwares without the need to rebuild them for each platform.
SD Card interfacing
Re: SD Card interfacing
enso wrote:
Bit-banging SPI is very simple, and SD cards have very lax timing requirements. I've driven SD card clocks by hand on one occasion! This is the code I've been using on my 45MHz 6502 CHOCHI board. I am sure it could be improved:
I've started to think about this project since it's finally the time to build a light 65xx SBC too, not "only" interfacing with existing computers, but still I'd like to keep the "common I/O bus" idea, so I can use the same devices created by me on various range of hardwares without the need to rebuild them for each platform.
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: SD Card interfacing
Quote:
I'm also thinking on SD-card interfacing (and other SPI devices btw) but not with bit-banging which seems to be too slow for my taste.
Here's part of the SPI-bitbanging code I have posted on my website:
Code: Select all
CLK_UP: MACRO ; NOTE! Accum is not preserved!
LDA #1
TSB VIA3PB
ENDM
;------------------
CLK_DN: MACRO ; NOTE! Accum is not preserved!
LDA #1
TRB VIA3PB
ENDM
;------------------
CLK_LO_PULSE: MACRO ; NOTE! Clock must already be known to be high!
DEC VIA3PB
INC VIA3PB
ENDM
;------------------
CLK_HI_PULSE: MACRO ; NOTE! Clock must already be known to be low!
INC VIA3PB
DEC VIA3PB
ENDM
;------------------
MOSI_UP: MACRO ; NOTE! Accum is not preserved!
LDA #2
TSB VIA3PB
ENDM
;------------------
MOSI_DN: MACRO ; NOTE! Accum is not preserved!
LDA #2
TRB VIA3PB
ENDM
;------------------
; For SEND_BYT and RCV_BYT below, I use program structures discussed in my web page
; http://wilsonminesco.com/StructureMacros/index.html . The source code for implementing them on the C32 assembler is at
; http://wilsonminesco.com/StructureMacros/STRUCMAC.ASM , but you can undoubtedly see what they will assemble if you want to do it
; without the macros. I used them here to make it more clear what is happening.
SEND_BYT: ; Start with byte in A. Slave must already be selected.
PHA ; Put the input number on the stack because we need A for the TRB/TSB mask below.
CLK_DN ; Prepare for mode-0 transmit, and for high clock pulse with INC DEC.
TSX ; Put the stack pointer in X for shifting below without bringing it back into the accum.
LDA #2 ; 2 is the value of the MOSI bit for TSB & TRB.
FOR_Y 8, DOWN_TO, 0 ; 8 is the number of bits we will shift out and test in the loop.
ASL 101,X ; Shift the input number left, since transmission is msb-first.
IF_C_CLR ; The bit gets put in the carry flag.
TRB VIA3PB ; If the bit was a 0, clear the MOSI bit in VIA3PB,
ELSE_ ; otherwise
TSB VIA3PB ; (ie, the bit was a 1), set the MOSI bit in VIA3PB.
END_IF
CLK_HI_PULSE ; Pulse the clock line. The INC/DEC does not affect A.
NEXT_Y ; Decr the counter and see if we need to repeat the loop.
PLA ; Remove the number from the stack. (We don't need it anymore, but we need the stack cleaned up.)
RTS
;------------------
RCV_BYT: ; Slave must already be selected, and first bit must already be waiting on MISO. Output is in A.
CLK_DN ; Prepare for mode-0 receive, and for high clk pulse with INC DEC.
LDA #0 ; We will build up the byte in A, so init it to 0.
FOR_Y 8, DOWN_TO, 0 ; 8 is the number of bits we will shift in in the loop.
BIT VIA3PB ; MISO is on VIA3PB6, which BIT reflects in the V flag.
CLC
IF_V_SET
SEC ; Transfer V flag into C flag,
END_IF
ROL A ; then rotate it into the accum.
CLK_HI_PULSE ; Pulse the clock to get the next bit ready, even if it won't get read
NEXT_Y ; until the next RCV_BYT . Decr the counter and see if we need to repeat.
RTS ; Output is in accum.
;------------------
< now build the routines specific to the SPI ICs you want to use >
I know SPI allows sending and receiving at the same time, but none of the SPI ICs I've used so far do that. They only do one at a time.
Quote:
Option2: Let's use a dedicated SPI interface IC. Unfortunately there is not so many ... Unlike UARTs, they're quite rate [rare?]. To be precise I only know about 65SPI, but it would be harder/more expensive to get one from Hungary, also maybe it's too 65xx specific, I'd like something I can use in my Z80 projects as well. I don't know if 65SPI can be used with outer [other?] CPUs easily or not.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: SD Card interfacing
It seems possible to achieve close to 100KHz clocking bitbanging even at 1MHz. Even at 50KHz you can read data at the rate of 6K per second! You will fill your 64K of RAM in 11 seconds, or more realistically, load a respectable 32K app in under 6 seconds. Is it really worth adding extra hardware to bring that time down to 1 second?
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
Re: SD Card interfacing
enso wrote:
It seems possible to achieve close to 100KHz clocking bitbanging even at 1MHz. Even at 50KHz you can read data at the rate of 6K per second! You will fill your 64K of RAM in 11 seconds, or more realistically, load a respectable 32K app in under 6 seconds. Is it really worth adding extra hardware to bring that time down to 1 second?
6502 sources on GitHub: https://github.com/Klaus2m5
Re: SD Card interfacing
For comparison, I just read a file from an old floppy disk, and I got 33K per second (including a few seeks back and forth). Of course, this is with relatively modern equipment from the end of the floppy era. The original drives that you could buy for home computers were much slower.
I guess it all depends on your application and expectations. For recreating retro experience, 100 Kbit/sec is good enough to load some old games.
I guess it all depends on your application and expectations. For recreating retro experience, 100 Kbit/sec is good enough to load some old games.
Re: SD Card interfacing
enso wrote:
It seems possible to achieve close to 100KHz clocking bitbanging even at 1MHz. Even at 50KHz you can read data at the rate of 6K per second! You will fill your 64K of RAM in 11 seconds, or more realistically, load a respectable 32K app in under 6 seconds. Is it really worth adding extra hardware to bring that time down to 1 second?
Re: SD Card interfacing
I will try to be the voice of reason here. If speed is in fact an issue, why not get a 45MHz 6502 computer for $25? And since it's on an FPGA, you can pop in a shift register with no problems if you feel like doing some interesting work. The FPGA is 1/2 full, so there is plenty of room for innovation and interesting projects.
If speed is not the issue (that is you want to run at less than 14MHz), then can you really worry about being locked out for a few seconds while the computer is bitbanging?
If speed is not the issue (that is you want to run at less than 14MHz), then can you really worry about being locked out for a few seconds while the computer is bitbanging?
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
Re: SD Card interfacing
enso wrote:
I will try to be the voice of reason here. If speed is in fact an issue, why not get a 45MHz 6502 computer for $25? And since it's on an FPGA, you can pop in a shift register with no problems if you feel like doing some interesting work. The FPGA is 1/2 full, so there is plenty of room for innovation and interesting projects.
If speed is not the issue (that is you want to run at less than 14MHz), then can you really worry about being locked out for a few seconds while the computer is bitbanging?
If speed is not the issue (that is you want to run at less than 14MHz), then can you really worry about being locked out for a few seconds while the computer is bitbanging?
Re: SD Card interfacing
@LGB: The whole point of wanting to use a 6502 in any form is a bit odd, considering that there are so much more powerful alternatives. It's not surprising that everybody has their own specific motivations and self-imposed restrictions. So, maybe you are odd, but not worse than anybody else here. 
Re: SD Card interfacing
Arlet wrote:
@LGB: The whole point of wanting to use a 6502 in any form is a bit odd, considering that there are so much more powerful alternatives. It's not surprising that everybody has their own specific motivations and self-imposed restrictions. So, maybe you are odd, but not worse than anybody else here. 
Re: SD Card interfacing
OK, I totally get it. I suppose the proper solution for you is a shift register or two.
However, having used the stock C64 disk drive, I am convinced that bitbanging SPI would be an incredible increase in performance, even at 50khz.
However, having used the stock C64 disk drive, I am convinced that bitbanging SPI would be an incredible increase in performance, even at 50khz.
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
Re: SD Card interfacing
enso wrote:
OK, I totally get it. I suppose the proper solution for you is a shift register or two.
However, having used the stock C64 disk drive, I am convinced that bitbanging SPI would be an incredible increase in performance, even at 50khz.
However, having used the stock C64 disk drive, I am convinced that bitbanging SPI would be an incredible increase in performance, even at 50khz.
And btw, SD card is the first stage only to try (that's not for the C64 too much btw but I also tried with an SBC project, where bit banging would be enough!) SPI and play a bit, the SPI based ethernet controller would be a more important goal for me, with some kind of extra flexibility to use a some custom bus signals to connect the same "card" to various types of my machines, let it be a C64, a Z80 based computer or a little SBC project based on 6502. That was the "common I/O bus" idea I wrote about. Also there are interesting other ISP devices like the um-FPU, and maybe others too. As you can see the "speed of loading apps on this machines is OK even with bit banging" is really true, but much wider spectrum of devices would be considered by me than just SD cards ... Well. Later
Re: SD Card interfacing
If you're interested in ethernet, perhaps the Silabs CP220x would be an option (further ethernet discussion should get its own thread).
Re: SD Card interfacing
Arlet wrote:
@LGB: The whole point of wanting to use a 6502 in any form is a bit odd, considering that there are so much more powerful alternatives....
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: SD Card interfacing
LGB wrote:
And btw, SD card is the first stage only to try (that's not for the C64 too much btw but I also tried with an SBC project, where bit banging would be enough!) SPI and play a bit, the SPI based ethernet controller would be a more important goal for me, with some kind of extra flexibility to use a some custom bus signals to connect the same "card" to various types of my machines, let it be a C64, a Z80 based computer or a little SBC project based on 6502. That was the "common I/O bus" idea I wrote about. Also there are interesting other ISP devices like the um-FPU, and maybe others too. As you can see the "speed of loading apps on this machines is OK even with bit banging" is really true, but much wider spectrum of devices would be considered by me than just SD cards ... Well. Later 
Also see our I2C-6 method for facilitating the use of multiple pluggable I²C devices. The brief spec is at viewtopic.php?f=4&t=2155.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?