|
|
|
|
|
|
| Re: Z80 SPI fast SD [message #8501 is a reply to message #8498] |
Sun, 25 April 2021 14:24   |
cluso99
Messages: 40 Registered: June 2017
|
Member |
|
|
Ouch! I note the PDF uses 5V for the SD card, not the required 3V3. Pleased your schematic shows 3V3.
I have written SD SPI drivers for the Parallax P1 more than 10 years ago, and did the P2 ROM SD boot code. I found the SanDisk cards to be the easiest and most reliable, and not found I needed any more than 96 clocks for initialisation. I've not seen problems with any other legitimate SD cards (ie not the fake ones that misreport larger sizes than in reality), but I do note I have seen lots of articles on various forums where other SD brands have been reported not to work. I did find a card that misimplemented one of the boot responses incorrectly but it was the only brand that did this, but that was many years ago. I've also found when sharing pins, that many cards don't release the DO (data out from the card) correctly and require extra clocks to force the DO drive release but that shouldn't be a proble here. All my P1 designs share the DO pins with others such as the SRAM on my RamBlade designs. On P2, if a Flash chip is included with SD, then all 4 SPI pins are shared, and these extra clocks after a command are required.
As an extra note, a bulk and a bypass cap should be provided right at the card socket pins on the power/GND supply. Older cards were much more demanding.
I now only support SDHC or SDXC cards using sector mode ie addressing is by sector, not the old byte addressing used by all original SD and early SDHC cards. Note also that SDXC cards are usually formatted as exFAT, not FAT32. I think exFAT is still covered by an MS patent and is not backwards compatible with FAT32/FAT16. IIRC FAT32 only covers up to 1TB.
FWIW on P2 ROM boot I implemented an alternative for non-FAT32 formatted cards which can boot from the MBR or VOL sector(s).
My Z80 emulation maps 8x 8MB HDDs onto 8 FAT32 8MB files.
[Updated on: Sun, 25 April 2021 14:27] Report message to a moderator
|
|
|
|
| Re: Z80 SPI fast SD [message #8502 is a reply to message #8497] |
Sun, 25 April 2021 14:30   |
lynchaj
Messages: 1080 Registered: June 2016
|
Senior Member |
|
|
monahan wrote on Sun, 25 April 2021 14:06I looked at this a few times. Has anybody written and tested a software program for a Z80 with SD cards to actully read and write sectors. Different SD cards have a complex protocol interface. I have been using an SPI module in a Cyclone IV FPGA with its own internal Z80. Works fine but like the above proposed simple hardware inherface
Hi John
The article gives this information on how to use the interface which has 4 IO ports. port 0 is for writing, port 1 is for reading, port 2 for lowering CS#, and port 3 for raising CS#. Ports 2 & 3 seem to be used for detecting the presence of an SD card. I think much of the SD code has already been written for PPISD and N8 bit-banging software. I presume it would be a matter of substituting this low level byte transfer code for the low level bit by bit code. I think most of the existing SD code would be unchanged.
Quote:
Assembly Interface
Bytes are transferred through the interface with this simple assembly code:
transfer_byte:
out $00
receive_byte:
out $01
in $00
ret
First the byte to be transmitted is written to port 0, then a write to port 1 causes the
SPI transfer to take place. Finally, a read from port 0 retrieves the received byte.
My notes indicate that no "nop" instructions are required before the "in"
instruction, but I was probably using one of those old 4 MHz Z80 chips at the time.
A 10 MHz chip probably requires two "nop" instructions and a 20 MHz chip
probably requires six, unless you use a faster clock for the SD transfer. The limit on
the SPI clock is probably going to be the counter chip you use in the circuit below.
The SD cards themselves are already designed to transfer data at insane speeds.
and
Quote:
Anyway, this sets up port 0 to read/write the shift registers. A write to port 1 then
starts the SPI transfer. Ports 2 & 3 when written to toggle the /CS on the SD card,
with port 2 lowering /CS and port 3 raising it. Ports 2 & 3 when read from similarly
toggle a pull-up / pull-down resistor attached to the SD card's data output pin,
which can be used to detect if a card is present by changing the polarity and noting
whether the bits read from the interface continue to match the pull-up / pull-down,
so that an empty card slot looks different than an unresposive but present card.
I am still working on the PCB and making minor tweaks but this is just a distraction while I wait for the Z80 serial board PCBs to arrive.
Thanks, Andrew Lynch
PS, BTW I am not making any claims to being original with this, I found the circuit diagram here:
https://www.ecstaticlyrics.com/electronics/SPI/fast_z80_inte rface.html
[Updated on: Sun, 25 April 2021 14:32] Report message to a moderator
|
|
|
|
|
|
|
|
| Re: Z80 SPI fast SD [message #8508 is a reply to message #8503] |
Sun, 25 April 2021 17:54   |
kman
Messages: 45 Registered: February 2019 Location: Germany
|
Member |
|
|
Quote: It's a shame there is no 3D model for the SD Card footprint, at least that I've been able to find. It is the one missing piece of the 3D render
I used this footprint and 3D-shape for a SD-Card holder on my kiCAD Multicomp pcb. You have to change your footprint if you intend to use it. See the zip-file.
cheers
Kurt
[Updated on: Mon, 26 April 2021 05:19] Report message to a moderator
|
|
|
|
| Re: Z80 SPI fast SD [message #8513 is a reply to message #8508] |
Mon, 26 April 2021 03:13   |
lynchaj
Messages: 1080 Registered: June 2016
|
Senior Member |
|
|
Thank you, I will look into using that 3D model and updating my footprint. BTW, I was able to find the actual part number for the SD Card. It is part from Amphenol 101-00313-68-02. Major props to Sergey who had this info in his ParPortProp description web page. I am adding this info to the Z80 SPI schematic. Also there seems to be many surplus/similar parts/clones on eBay for reasonable prices.
[Updated on: Mon, 26 April 2021 03:19] Report message to a moderator
|
|
|
|
| Re: Z80 SPI fast SD [message #8514 is a reply to message #8502] |
Mon, 26 April 2021 03:17   |
lynchaj
Messages: 1080 Registered: June 2016
|
Senior Member |
|
|
Hi
An update on the Z80 SPI. I contacted the original author of the SPI SD interface for Z80 and had a brief email exchange. Seems like a nice person but no longer active in this particular hobby. However did send me some sample code which I'll have to post later today when I get a chance.
Also, based on some wise counsel I am switching from the 3.3v Zener diode for clamping protection to a all-resistor voltage divider circuit. It certainly is simpler and probably cheaper too. Shouldn't be any concern about rise times with a couple of resistors. So I'll post new info with the adjustments along with the sample code.
BTW, this could easily be an ECB board by just replacing the 2x25 pin header with a DIN 41612 connector. I am using a template for the Z80 MBC but there is nothing special about it.
[Updated on: Mon, 26 April 2021 03:25] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|