Shop OBEX P1 Docs P2 Docs Learn Events
SD Tutorial Part #2 Posted — Parallax Forums

SD Tutorial Part #2 Posted

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2011-06-08 23:40 in Propeller 1
Part #2 of the SD tutorial series is now online at GadgetGangster.com.

If reading or writing data to the SD has been a mystery to you, hopefully these will help.

Thanks Nick!

OBC

Comments

  • Nick McClickNick McClick Posts: 1,003
    edited 2011-06-07 11:12
    Beat me to it! This will also get rolled into the book after another round of editing / review.
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-06-07 18:29
    Great work OBC. While it is quite simple to use the drivers, it is often daunting for some people who have never done such a thing before. This will make it easy to get running for the inexperienced and provide a quick outline for experienced users.
  • TtailspinTtailspin Posts: 1,326
    edited 2011-06-07 21:38
    Thank You.

    I promise to use this knowledge for good only...
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-06-08 05:51
    This thread is most timely - thanks++

    I was wondering if I could first describe something, and then ask some questions?

    By way of background, I have just sent off for manufacture two boards that take the Dracblade board and split it into a Gadget Gangster standard motherboard, and an add-on external memory board. I'm using these for developing large programs in C, in particular a GUI for the propeller.

    But as the program grows in size (about 200k at present) the download speed is getting slower. The compilation speed remains almost instantaneous so the bottleneck is the download, so I'm now looking at ways of downloading big programs, eg megabytes in size, in a way that keeps the simplicity of "press F10 and see your program run in a few seconds".

    So I'm thinking of hacking into existing USB to SD card readers which are available on ebay for $1 each including shipping. Take one of these, open up the case, solder wires to the SD card socket onto a board, and then build a switch that connects a new SD card socket to either this SD card reader, or to the propeller.

    In simple terms, and SD card has Gnd, 3V, DO, DI, CLK and CS. So in very simple terms, the "switch" could be a 6PDT physical switch. Or relay.

    But I think it can be done more easily than that. Gnd is common. 3V3 can be switched with NPN transistors (the current draw of an sd card might be a bit high for a BC557 or equivalent, so maybe move up to a BC337 or equivalent).

    And then there are 4 data lines. So - here is the question. Is the data direction of those 4 lines always the same?

    In other words, do CS, DI and CLK always go "in" to the SD card, and does DO always come "out" of the SD card?

    ie, none of these lines are bidirectional?

    If they are bidirectional, I'd be thinking of reed relay(s) as the simple answer. But if they are only ever one direction, then there are multiple 74xx solutions, like 2-1 demultiplexers, or logic gates, or hc125 etc.

    The point of this would be to get USB 2.0 download speeds to an sd card which I think would be only a few seconds for megabytes, then switch to running the large program from the sd card.

    Advice here would be very much appreciated - thanks!
  • prof_brainoprof_braino Posts: 4,313
    edited 2011-06-08 06:41
    As I understand it,

    DI = MOSI -> Master Out / Slave In
    DO - MISO -> Master In / Slave Out
    Clk - Provided by master
    CS - provided by master

    So none would be bidirectional.
  • Nick McClickNick McClick Posts: 1,003
    edited 2011-06-08 08:50
    @Drac - I think you want to share an SPI buss with multiple devices. All devices on the buss share Di, Do, and Clk, but they get their own Chip Select (CS) line. The Chip Select line doesn't really carry any data, it just allows the master (the Propeller here) to control which device is active. And all the master does to select the active slave is pull Cs low.

    If two devices were on the buss, you'd use 5 pins - Di, Do, Clk, Cs for the first device, and a Cs for the second device.
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-06-08 14:33
    Drac: The lines are not bi-directional on SPI. Nice concept. Be aware that the cheap $1 USB readers (the real tiny red & black ones) do not use gold connectors. But to investigate, they are cheap - I should pull mine apart.

    Now for the downside. I am not sure what effect you will have in removing the SPI connection from the USB. Copying files is quick on the PC to USB that way. I do it often.

    To switch the data lines you can use mosfets or gates. Gates are easier - try a quad 2:1 mux. BTW use 74LVCxxx as they are better than 74HCxxx for what we use. See the specs. And they are much faster. To switch power (you may not need to do so???) try one of the mosfet switches that are used to switch power on laptops (low power versions that disable parts of the laptop). Perhaps the ones used in the backpack could work - not sure of any part nos.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-06-08 16:26
    Thanks everyone - that is all very useful information.

    I'm not sure about switching power or not. The concern would be sending data into pins on an unpowered device. Looking at the pins on an actual SD card (and micro sd), the power pins are slightly longer so they connect first, which suggests they are trying to avoid sending data to an unpowered device.

    Yes, would need to think about the speed, eg LV parts. How fast does USB2 go?

    Re switching the device over, I think that would be the same as removing the sd card. Don't do it too soon after downloading a file, maybe wait a few seconds? That might have to be under software control - maybe it is possible to do the 'it is now safe to unplug your device' by software?
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-06-08 22:53
    Drac: You should not remove a USB device until windoze says you can. So you have to click on the taskbar to close the device on XP & Vista. If anything is open (e.g. Explorer and looking at the device folders) you cannot close the device and get the removal window. I am not sure if there is an unmount command in windoze using software.

    Sorry, typo. Should read 74LVCxxx and you should by choice use these for the prop. I was out of touch when I used the 74HC573 latches on the TriBlade.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-06-08 23:40
    Drac: You should not remove a USB device until windoze says you can.

    I found a solution which is pretty good
        Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
            Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll", AppWinStyle.NormalFocus, True)
            MsgBox("got to here")
        End Sub
    

    This pulls up the disconnect window and you just click stop. So it is an extra keypress as part of the F10 download process. The "true" value in the shell call means that the program does not go on to the next line until the user has closed this window.

    There are some comments on various forums about getting inside the API so that might be another avenue to look at.

    This is still going to be much quicker for really big programs than doing a serial download. Probably round the 100k mark this will end up being quicker.
Sign In or Register to comment.