Shop OBEX P1 Docs P2 Docs Learn Events
Using an SD card with propeller assembly? — Parallax Forums

Using an SD card with propeller assembly?

tholbertontholberton Posts: 41
edited 2012-05-20 20:08 in General Discussion
I want to use a micro sd card for a project i'm preparing for. Since it requires a lot of data transfer in a short amount of time, most of the code is going to be in assembly (I also prefer assembly since it involves understanding the hardware more). I'm having trouble figuring out where to start, though.

Here's the vague approach I've been thinking of, (just to get the basic SPI interface working):
pin 0 - CS selected on low
pin 1 - CLK
pin 2 - DO
pin 3 - DI

to write 1011 to DO

mov outa, 0110b
mov outa, 0000b
mov outa, 0100b
mov outa, 0000b
mov outa, 0110b
mov outa, 0000b
mov outa, 0110b
mov outa, 0000b

I know using jmp, xor, and a shift function i could make a loop... i just wanna know, is this the right approach to take? I'm kind of skeptical because of what needs to be on the falling or rising edge of a bit on some devices. any info or tips are appreciated.

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-05-19 22:19
    Have you checked the OBEX, Object Exchange?

    How fast do you need to go?

    http://obex.parallax.com/objects/92/

    http://obex.parallax.com/objects/619/
  • tholbertontholberton Posts: 41
    edited 2012-05-19 22:38
    well those are great, but I want to write my own code for it so that I can at least understand what I'm doing. i'm hoping for the clk to be in the order of mhz
  • tholbertontholberton Posts: 41
    edited 2012-05-19 23:00
    i figure with 20 mips, using four instructions, like mov, shift, if_z, and jmp; you could make a 5 mhz clk for the spi? i'm not an expert, so any advice on this or the protocol would help a lot
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-20 07:27
    For output transfers, you have to place the data on the DI line prior to the leading edge of the clock. You'd use a sequence like:
       shl    data, #24   ' position byte for output
       mov    count, #8   ' number of bits to output
       andn   outa, csMask   ' make /CS low
    :loop
       shl    data, #1   wc   ' shift msb into carry
       muxc   outa, diMask   ' put data on DI line
       or     outa, clkMask   ' clock it
       andn   outa, clkMask
       djnz   count, #:loop
       or     outa, csMask   ' end of transfer
    
    There are faster ways to do this using a cog counter as the clock source, but this is pretty fast (4MHz) and is straightforward.
  • Mike GMike G Posts: 2,702
    edited 2012-05-20 10:02
    Mike Green or anyone, can you point me to documentation on using counters for clocking an SPI bus.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-20 10:28
    There's no documentation on this. You'll just have to trudge through one of the existing I/O drivers that use this technique. It's mostly a matter of counting instruction cycles, initializing the counter so it has a synchronous relationship with your code's execution so the output of the counter produces pulses that remain in a fixed relationship with the data produced by your code with the clock pulse occurring at the correct time in relationship with the data.
  • tholbertontholberton Posts: 41
    edited 2012-05-20 20:08
    Thank you so much! So if the data bit is valid on the rising edge of the clk, I just make sure the data bit is on/off before clk rises? that's pretty much exactly what I needed to know. thanks a bunch!
Sign In or Register to comment.