Shop OBEX P1 Docs P2 Docs Learn Events
sd card troubles — Parallax Forums

sd card troubles

PashaPasha Posts: 56
edited 2008-11-19 15:22 in Propeller 1
I am using the PropRPM it is working well for me. I am trying to attatch an sd card reader, but have been so far unsuccessful. I have worked a total of about 4 hours on this problem, and just need some good advice. I am using a floppy edge connector as my reader. I know that all the pins on my card are touching the pins on the reader. I have connected sd card pin 1 to prop pin 3, pin 2 to prop pin 2, pin 3 to gnd, pin 4 to +3.3V, pin 5 to prop pin 1, pin 6 to gnd, pin 7 to prop pin 0. other than this I have pulled up all pins (except power and ground pins) via 10K resistors to +3.3v. I keep getting the error message -41 even when there is no card in the reader. Please any suggestions would be welcome. when I tried it without any pullup resistors, I always got -20 even though I know my card was correctly formated, connected, and all wires were conducting correctly.
«1

Comments

  • RaymanRayman Posts: 14,595
    edited 2008-11-09 19:18
    One thing to make sure is that you have the sd card formatted with the right sector size...

    This info is at the bottom of this page:

    http://www.rayslogic.com/propeller/Programming/SD_Card/SD_Card.htm

    Also, make sure it's not·the newer type "SDHC" card.
  • giannissamgiannissam Posts: 22
    edited 2008-11-09 19:23
    Same prob here..i've formated my card 10283 times (lol). i used format from right click windows menu, the dos format using /fs:fat /a:16k or /a:32k and the panasonic sd format utility...... any other tools?
  • PashaPasha Posts: 56
    edited 2008-11-09 19:39
    just found one of the many problems some of the wires were touching. I am debugging it now. I know that my card is correctly formatted. I formated it with command prompt the way i was supposed to, and it said that there were 16bits in each fat entry.
  • PashaPasha Posts: 56
    edited 2008-11-09 19:49
    I just got it to work!!!!!!!!!!!!!!!!!!
    I disconnected the pullup resistors, because that was when i started to get the -41 error. I only got one of my cards to work. [noparse]:([/noparse] will try formatting again tell me any luck you have.
  • giannissamgiannissam Posts: 22
    edited 2008-11-09 20:31
    i'll try without the resistors. (what is their use really? i use 10k ones but i read somewhere that u can use others too? what's the difference?)
  • AribaAriba Posts: 2,690
    edited 2008-11-09 22:45
    The PullUps are only for a defined state on the SD card Pins when the FSRW object is not used (and the Pins are floating).
    10k or 20k or 100k does not matter. (I normally connect only one at the CS pin).

    I've used something like a "floppy edge connecter" at the beginning and had always contact problems, because the contacts of my SD cards are a little bit sunked in the plastic enclosure.
    Since I use a real SD card socket it works well.

    Andy
  • PashaPasha Posts: 56
    edited 2008-11-10 16:44
    I did get it to work with sdpi but not with sdpiasm or anything faster. Any help?
  • PashaPasha Posts: 56
    edited 2008-11-10 18:49
    could the difference in length of my leads make the difference (about half a centimeter)
  • rokickirokicki Posts: 1,000
    edited 2008-11-10 19:18
    If you are using anything faster than sdspi, you should not use the series resistors.

    The series resistors "slow the signal down" (really, there's an RC time constant coming into play here).

    If you don't have the series resistors, and it still only works with sdspi and not with the faster ones,
    it's time to look at your signal path and see what might be causing problems. These are not terribly
    fast signals (around 20MHz) but it still doesn't take a whole lot of capacitance or inductance to slow
    them down.

    In general, I would always try to use a real SD socket, and not some kludge. Spend a few bucks
    and wait for it to come in the mail and save yourself a ton of aggravation. To me this fits squarely
    in the "use the right tools" category, similar to the way you never want to use a pair of cheap
    slip-joint pliers on nuts, or common rubber mallets on the side of your new plasma HDTV because
    the picture isn't coming in well.
  • rokickirokicki Posts: 1,000
    edited 2008-11-10 19:20
    A difference in the length of the leads shouldn't make a difference unless the difference
    is many yards. I think it's about a nanosecond a foot. The data is latched on a clock
    edge, but the signal changes on the other clock edge, so there's quite a lot of setup and
    hold time.
  • PashaPasha Posts: 56
    edited 2008-11-10 20:18
    Thanks for the feedback. I haven't been using any resistors at all. my wires from the reader to the propeller are only about 3cm long. I live in Ukraine and don't have access to the kind of stores you are talking about. I would have to wait until some one is coming over from the states before i could get it. I don't have that kind of patience.

    Ps. I tried adding one pullup resistor between 3.3v and cs, and nothing changed. still -20 error. I know my sd card is correctly formated, because it always works with sdspi
  • PashaPasha Posts: 56
    edited 2008-11-10 20:19
    How can I measure the capacitance on the line? my multimeter does measure capacitance.
  • rokickirokicki Posts: 1,000
    edited 2008-11-10 21:30
    Doesn't sparkfun deliver to the Ukraine?

    It should work with no resistors at all. Try cranking the prop clock down from 80MHz to say 10MHz and see if that works
    (of course your TV won't work there, so you'll have to use perhaps a serial connection or something to verify it).

    There is no easy way that I know of to measure capacitances so low, but frankly, I'm not sure that's your problem.
    It *might* be power issues; do you have a capacitor close to the card between +3.3V and ground? Maybe the
    power lines are too long.

    It may be time to slap a scope on the pins. Do you have a scope, or a friend who has one?

    Frankly, though, this stuff works under such adverse conditions that I'm still tempted to blame some sort of
    programming error or the like.
  • PashaPasha Posts: 56
    edited 2008-11-11 05:42
    I don't have a scope or easy access to one. I haven't checked if sparkfun delivers to Ukraine, but there would be lots of extra charges, and there is a crazy law that each house can only receive 2 packages per 6 months. If it would be delivered in an envolope it would be no problem, but the moment its a box........
    I will try the speed thing. Maybe just have it run an led if there are no problems. Thanks Rockocki. The real reason I am using an sd card is because I am building a robot, and i am pretty sure I will need to reprogram it a lot of times. I am not building it on the board I have to program the Eeprom, so I would like to put the program on the sd card and transfer it from there at run time. I should be able to do this albeit slowly even with sdspi.

    will post results
  • PashaPasha Posts: 56
    edited 2008-11-11 05:56
    THe lines i am using go directly to the propeller chip. nothing else is on them.
  • AribaAriba Posts: 2,690
    edited 2008-11-11 13:06
    Pasha

    this is a european source which also ships to Ukraine (they have an ukraine translation of the site too).
    www.tme.eu/ua/

    Andy
  • PashaPasha Posts: 56
    edited 2008-11-14 17:02
    I tried that idea, but it didn't work, even with spdiasm. i just told it to turn on an led if it mounted. I also checked to see if it had written the newfilex.txt file. No Go. ps. can anyone help me with the procedure necessary to boot a prop from a file on an sd card using the slow spdi driver?
    ·
  • PashaPasha Posts: 56
    edited 2008-11-14 17:44
    I looked at the power lines, and there is a 100microF capacitor between vss and ground not to mention two smaller ones marked k5m I don't know what that means, but they could be causing the problems. They are not physically close to the sd card reader I would say almost 3 inches away. Does this help?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-14 17:45
    FemtoBasic and DongleBasic (from the Object Exchange) have the capability of loading a Spin program from an SD card and transferring control to it. They also have an "autostart" capability where they will load and run a Basic program with the name "AUTOEXEC.BAS" which in turn can load and run a Spin program. Parallax used FemtoBasic to make a kiosk that would execute any of a set of demo programs using a keyboard and display to select the program to run.

    The loader object from FemtoBasic is designed to be used on its own (separate from the rest of FemtoBasic) to do EEPROM or low level SD card I/O.
  • PashaPasha Posts: 56
    edited 2008-11-14 19:47
    I noticed that it doesn't use the normal fsrw. I need to use the slow sdspi spin driver. Do you know how i could implement this, or build one from scratch. I know it would be slow, and could take up to eleven seconds just to boot, but that doesn't matter, It is only for my robot, and it can take time to load at startup.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-14 20:26
    In order to "boot" a Spin program directly, you must use an assembly language read/write routine. You can't use a Spin routine. Try using DongleBasic on your system. It uses your PC for the console (like HyperTerminal or PropTerminal or equivalent). Read the brief documentation that comes with it.

    Note that your SD card should be formatted with 32K clusters. If the file to be loaded spans more than one cluster and they're not sequential, the file won't load properly. Formatting with 32K clusters eliminates this issue.
  • PashaPasha Posts: 56
    edited 2008-11-15 15:02
    The problem is that I am using an old 16 megabite card which can only be formated with up to 2k to still be fat16
  • PashaPasha Posts: 56
    edited 2008-11-15 16:05
    Hey Mike, I have been looking at your OS for the prop. It seems to have sd support using fsrw, but I can't figure out how to access the sd card. any help.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-15 19:17
    The Propeller OS that I wrote only has support for EEPROMs, not for SD cards. I started adding SD card support, but ran out of room and had some other problems. As a result, I decided to take Rokicki's simple FemtoBasic and develop it further adding a lot of the work I had done to expand the Propeller OS.

    With small clusters (like 2K) you have to be careful about how you create your files so that they're at least 32K in length and contiguous. If you never delete files and never expand them in size, you'll be ok since new files will always be allocated at the end of the existing files.

    You should still be able to format a 16MB card using 32K clusters using Linux or an old version of Windows (like Windows 98). As I recall, both allowed you to specify the cluster size explicitly.
  • PashaPasha Posts: 56
    edited 2008-11-16 11:45
    I can format my card with 32k clusters, but then it will fomat as fat12, isn't that a problem?

    Is there a way I can mod the fsrwfemto file to use sdspi instead of some special assembly one. My card interface isn't working at that speed.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-16 16:18
    1) If you can specify 32K clusters, you should be able to specify FAT16 as well. FAT12 won't work.

    2) The low level SPI routines in sdspiFemto are called "spiSendByte" and "spiRecvByte". With an 80MHz system clock, the SD card clock speed is about 3MHz with a 100ns wide transmit clock pulse and a 50ns wide receive clock pulse. These can be slowed down by adding NOP instructions to these low level routines. The easiest way to test this out would be to change the Propeller's system clock speed by changing the _clkmode constant definition and using pll8x instead of pll16x. This will give you a 40MHz system clock and slow down everything including the SD card speed by a factor of two. Other I/O like a keyboard and display or serial I/O will adjust appropriately.
  • PashaPasha Posts: 56
    edited 2008-11-16 18:02
    THanks will try.

    ps. Will the tv work?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-16 18:21
    The TV driver is supposed to work with a system clock frequency down to about 15MHz. Look at the comments at the end of TV.spin for specifics.
  • PashaPasha Posts: 56
    edited 2008-11-16 19:03
    Thanks a lot, I will post results as soon as I can get to it.
  • rokickirokicki Posts: 1,000
    edited 2008-11-17 19:46
    Note that when formatting, you normally (at least on Windows) just specify "Fat" and the cluster size.

    If the total number of clusters is then < 4096, you'll get fat12. If it's less than 65,536, you'll get fat16.
    Otherwise you'll get fat32. (This is rough; the numbers above are not exact.)

    If your card is so small that 32Kbyte clusters give you fat12, that means your card is only about 128MB or
    less; I was not aware such cards even existed anymore.

    In any case, I recommend people use 65Kbyte clusters; there's no good reason not to unless you have
    *very* small cards.
Sign In or Register to comment.