6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Apr 26, 2024 9:08 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Wed Oct 27, 2010 1:55 pm 
Offline

Joined: Wed Oct 27, 2010 1:28 pm
Posts: 25
Location: Valladolid (Spain)
While designing a SD card interface to my own 6502 SBC i read this on André Fachat's 8-bit pages:
SD cards require SPI mode 0, while the VIA's shift register is SPI mode 3. "You could reverse clock, but you cannot make the VIA shift out earlier. So there is no way to use the VIA SR".
Well, you can't make the SR shift out earlier, but you can delay the clock. I did this using a 1us delay line made of 4 RC networks and HC04 inverters and I got a 500 kbit/sec SD interface directly from CB1,CB2 pins. For input I used a 74HC164 shift register clocked by the same delayed and inverted clock. This register is connected to the full port B of the VIA.
And for level conversion I'm using simple resistive voltage dividers for SCK, MOSI and /SS, while MISO is connected directly to the HC164.
All the timings are for 1MHz phi2 clock.
I just finished a working prototype. It can fill the whole 56kB of RAM from a SD card in less than 2 seconds (about 24 cycles/byte) I don't think the same speed is possible using bitbanging.
The same interface can be also used with an ENC28J60 Ethernet module, but it is not yet tested.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Oct 27, 2010 2:52 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
VERY sweet. Hope you can post schemartics and code eventually, make more of a canonical base for interfacing projects...

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 28, 2010 7:22 am 
Offline

Joined: Wed Oct 27, 2010 1:28 pm
Posts: 25
Location: Valladolid (Spain)
The schematic is availabe from the following URL:

http://www.ele.uva.es/~jesus/6502/perif_schem.pdf


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 28, 2010 2:27 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
A most clever and working design. For giggles, I will redraw as specific to port, on general principles. I had seen SD interface for the AVR as is for everything else, but super glad to see a working 65XX series interface :D

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 28, 2010 11:05 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
That is really slick. I like it!

Though, why do you have resistors on only three of the PB pins? It seems as though you set those pins to output under certain conditions. Are they used for other purposes besides reading the peripheral feedback?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 29, 2010 2:07 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
jesari, how long have you been working on your SD card interface?

Seems like you are you using the 6522 just for 8 bit output port?

I also would like to use "solid state" memory... Your SD card interface seems much easier, than a USB interface IC I've been thinking about.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 29, 2010 7:35 am 
Offline

Joined: Wed Oct 27, 2010 1:28 pm
Posts: 25
Location: Valladolid (Spain)
kc5tja wrote:
That is really slick. I like it!

Though, why do you have resistors on only three of the PB pins? It seems as though you set those pins to output under certain conditions. Are they used for other purposes besides reading the peripheral feedback?


After reset the current ROM code sets those bits as outputs. This has to be changed on new revisions, but, meanwhile, the resistors help to relax data contention.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 29, 2010 8:10 am 
Offline

Joined: Wed Oct 27, 2010 1:28 pm
Posts: 25
Location: Valladolid (Spain)
ElEctric_EyE wrote:
jesari, how long have you been working on your SD card interface?

Seems like you are you using the 6522 just for 8 bit output port?

I also would like to use "solid state" memory... Your SD card interface seems much easier, than a USB interface IC I've been thinking about.


The building took around une week of my spare time, but I was thinking about it long before, since I built the CPU board (Feb. 2010)

The PORTB of the VIA is used only for input, while PORTA is used also for other interfaces: bitbanging UART, I2C and speaker. PA0 is the ROM enable signal in the CPU board, so it can't be used for I/O. I'm keeping ORA always as $00 and changing DDRA instead.

The SD interfacing is much simpler than USB, as you can see. The software can be also much simpler than that for USB. I'm right now dealing with the FAT16 filesystem...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 29, 2010 11:29 am 
Offline

Joined: Wed Oct 27, 2010 1:28 pm
Posts: 25
Location: Valladolid (Spain)
Here are some details related to the code involved. First a timming diagram:
Image

It is clear that a minimum 14 cycles are needed between SR write and IRB read.

And the code involved:
Code:
; Single transfer
; 14 cycles between WR and RD
spibyte:
           sta   SR      ; 4 cycles
           jsr   delrts  ; 12 cycles
           nop           ; 2 cycles
           lda   IRB     ; 4 cycles   
delrts:    rts

In order to achieve a higher speed with the SD card, I'm using the following routines for block transfers:
Code:
; Block transfer (up to 256 bytes), write
; ptr1 ->  data source
; Y: # of bytes (minimum:1, 0=256)
; 19 us/byte (421 Kbit/s)
;------ Not yet tested ------
spiwr:
   sty   tmp1
   ldy   #0
spiwr1:
   lda   (ptr1),y   ; 5 cycles
   sta   SR      ; 4 cycles
   nop         ; 2 cycles
   iny         ; 2 cycles
   cpy   tmp1      ; 3 cycles
   bne   spiwr1      ; 3 cycles
   rts

; Block transfer (up to 256 bytes), read
; ptr1 <- data destination
; Y: # of bytes (minimum: 2 bytes, 0=256)
; 22 us/byte (363 Kbit/s)

spird:
   ldx   #$ff
   stx   SR      ; 4 cycles (dummy write)

   dey         ; 2 cycles
   sty   tmp1      ; 3 cycles
   ldy   #0      ; 2 cycles
   nop         ; 2 cycles
   nop         ; 2 cycles
   beq   spird1      ; 3 cycles
   
spird1:
   lda   IRB      ; 4 cycles
   stx   SR      ; 4 cycles (dummy write)
   sta   (ptr1),y   ; 6 cycles
   iny         ; 2 cycles
   cpy   tmp1      ; 3 cycles
   bne   spird1      ; 3 cycles / 2 cycles if no taken
   
spird2:
   nop         ; 2 cycles
   lda   IRB      ; 4 cycles
   sta   (ptr1),y
   iny
   rts

The SD sector is 512 bytes long, and, therefore, I'am calling spird twice


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 31, 2010 9:50 pm 
Offline

Joined: Sun Nov 01, 2009 2:22 pm
Posts: 21
Location: United Kingdom
Quote:
The same interface can be also used with an ENC28J60 Ethernet module, but it is not yet tested.


What a sweet little interface. Presumably brings the potential to use devices like the 'Connect Wi Fi' wifi cards to the table.

http://uk.eye.fi/

PS. I only own one which my camera couldn't cope with, so it's just sitting there.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 13, 2013 3:19 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 990
Location: near Heidelberg, Germany
Hi there,

I have updated my SPI page, where I now have extended my SPI interface to use SPI mode 0 as well.
I'm not using a delay, but an inverter (xor) in the data line to manually set the first data bit before shifting out the
rest of the data.

Runs at any speed up to phi2/2 (shifting out at phi2).

http://www.6502.org/users/andre/csa/spi/index.html

Andre

_________________
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content: http://6502.org/users/andre/


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 02, 2015 8:11 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
[As jesari's schematic is on a web server not presently responding, here's an archive link:
http://web.archive.org/web/201206281353 ... _schem.pdf
It's a subpage of "Bender's brain. A 6502 prototype" at http://web.archive.org/web/201306201645 ... proto.html
]


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 27 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: