Shop OBEX P1 Docs P2 Docs Learn Events
Using MicroSD card on Demo board with FemtoBASIC? — Parallax Forums

Using MicroSD card on Demo board with FemtoBASIC?

RobotWorkshopRobotWorkshop Posts: 2,307
edited 2008-02-10 17:03 in Propeller 1
Hello,

I've read about support for SD cards on the DEMO board with FemtoBASIC but what about the MicroSD cards? I have one of the small breakout boards for the MicroSD cards which i'm trying to use with the DEMO board. When I send FemtoBASIC to the DEMO board I made sure that Demo = true and the other two board styles are false. I can bring up FemtoBASIC but when I try to use the FILES command it says it can't mount the SD card. I did format the card under Windows XP using: FORMAT F: /fs:fat /a:8192 which completed successfully. The way it is wired up is:

DO - p0 and pulled to 3.3v through 18K resistor
SCK - p1 and pulled to 3.3v through 18K resistor
DI - p2 and pulled to 3.3v through 18K resistor
CS - p3 and pulled to 3.3v through 18K resistor
CD - pulled to 3.3v through 18K resistor
VCC - 3.3v
GND - Ground

Do the connections above look correct? If so are the MicroSD cards different and in that case do I need to switch to the regular SD cards? I have a little free time this weekend and i'm hoping to finish off the demo system so I can try out some of the other programs for this.

Best Regards,

Robert

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-30 23:55
    Robert,
    The connections you've listed appear correct. I haven't tried either FemtoBasic or BoeBotBasic with the MicroSD cards yet, but it should work the same. I do have a MicroSD socket, but haven't hooked it up to anything. Do check that the pins are connected to the signals you think they are. I have wired a standard SD card backwards ... didn't work that way, but it survived the error.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-07-01 02:25
    Hello Mike,

    Thanks for the reply. Maybe I am missing some other steps. A couple of things that come to mind....

    - Do the SD cards need a special volume label when you format them? I labeled mine PROPELLER when I formatted the card.

    - When using the FILES command do I first have to mount the SD card or will it automount the SD card and read it?

    - The CD signal didn't match up to the ones on the regular SD card. I haven't tried tying it low instead.

    I just found this datasheet online that covers some of the MicroSD cards which may help:

    http://www.pqi.com.tw/upload/download/micro SD(2).pdf

    I'm going to review it and double check all the connections again.

    Best Regards,

    Robert
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-07-01 02:38
    There is one thing that seems a bit odd with the SparkFun breakout board for the MicroSD cards. It only brings out 7 of the 8 lines. I'm currently pulling a total of 5 lines high at the moment. I wonder if that extra pin (that isn't brought out to the header) may need a pullup resistor as well?? I guess I can trace out the layout off the PCB to figure out for sure. If that is the case I think I can hack that adapter and add a pull up resistor right on that board. Kind of make me wonder why they just didn't bring out all 8 connections.....

    Best Regards,

    Robert
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-01 02:41
    The FILES command in FemtoBasic does do a mount as part of its processing.

    The CD signal isn't used by the I/O routines. It's an output from the card socket.

    I haven't found that anything special is needed for a volume label other than the
    usual uppercase only, no spaces, etc.

    Thanks for the datasheet.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-07-01 02:56
    I think going over the datasheet has helped.

    Do you know if a regular SD card will work if you leave off the two pull-up resistors on the DAT1 and DAT2 lines?? I'm beginning to think this may be my problem. It appears those two lines aren't brought out to the header and as a result don't have anything connected! I think that the CD isn't doing anything and I could have ignored it. I'm going to try soldering on a couple pull-ups on those other two lines and see if that does it.

    Robert
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-01 03:04
    Rokicki has tried leaving off all the pullups and says that it works file (with an SD card). Try it.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-07-01 16:07
    I added pullups to the other two lines but it is still having trouble mounting a MicroSD card. I've tried two different MicroSD cards a PNY 512mb and a Kingston 1GB card. For the initial tests I had been using FemtoBasic 2.002 and just upgraded to v2.004 with the same results. This morning I even swapped out the propeller chip itself in case something had happened to the one I was using.

    I recall reading somewhere that there was also a slow speed version of the SD card support that would allow it to work with more SD cards. For troubleshooting purposes is there any way to use that with FemtoBasic or add some delays to see if it may be a timing issue?

    Robert
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-01 17:17
    The FemtoBasic SPI routines do use assembly and the read bit routine effectively has a clock pulse width of 50ns, but the bit rate is lower (350ns/bit). The write bit routine is a little slower with a clock pulse width of 100ns and the same bit rate. You could try recompiling FemtoBasic with an extra NOP there. The current routine in sdspiFemto.spin is:
    spiRecvByte      mov     i2cMask,#%10000000
    :recvBit            andn    outa,spiMaskClk         ' Receive data bytes MSB first
                            or      outa,spiMaskClk         ' Copy DO to data bit
                            test    spiMaskDO,ina      wc     
                            muxc    i2cData,i2cMask
                            shr     i2cMask,#1              ' When mask shifted out, we're done
                            tjnz    i2cMask,#:recvBit
                            and     i2cData,#%11111111      ' Eight bits received
    spiRecvByte_ret         ret
    
    


    Try adding a NOP after :recvBit. I'm not sure if there's room in the cog. You'll get an error message if not.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-07-01 17:51
    Hello Mike,

    Thanks for your help. I tried adding the nop and it seems there was room since it compiled and ran the code. It still didn't make any difference. I think I am going to try to pickup a couple more SD cards and format them on another system to make sure that it isn't a formatting problem with the cards. If that doesn't help I think i'm just going to set this off to the side and work on other projects. It is probably something I keep on overlooking so the break may help. I may just pickup one of the Propeller protoboards and try these cards out there. Once I have at least one working setup with the SD card I can figure out what is going on with the other one.

    Best Regards,

    Robert
  • rokickirokicki Posts: 1,000
    edited 2007-07-02 06:51
    Try downloading from http://tomas.rokicki.com/fat16work/ and run the fsrw_speed.spin
    test and let me know what it shows on the screen.

    If you want to try a slower speed, substitute sdspi.spin for sdspiqasm.spin.

    This usually turns out to be something reasonably easy.

    -tom
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-07-03 04:14
    Hello Tom,

    I just ran the fsrw_speed.spin and it returned a code of -13. When I changed it to use sdspi.spin instead it returned a code of -41.

    Does that suggest anything in particular to look for? I didn't get a chance to pickup any more SD cards but am going to see if I can pick up a different brand tomorrow.

    Best Regards,

    Robert
  • rokickirokicki Posts: 1,000
    edited 2007-07-03 04:40
    Yeah, they are both timeouts waiting on a response. So that means something's wrong. smile.gif

    The wiring you describe is correct. At this point, I'd upload a detailed picture of the
    connections if you could just so we can check and see if we note anything wrong.

    Do you have a scope? If you do, scope the pins. Start with DI and make sure it's
    wiggling, and also SCK. If they are both wiggling, then check DO and see if it wiggles at all.

    Also check both power pins, of course; they should be steady at 0 and 3.3V.

    With the SD card out, you should also use an ohmmeter and check for shorts between
    combinations of pins. (With power off, of course.)

    Next, check the connections, P0 -> D0, P1 -> SCLK, P2 -> DI, P3 -> CS. They should have
    a pretty solid connection there. Measure from as close to the Prop to as close to the
    SD card as you can, since any miswiring could be anywhere.

    If all this fails, just for kicks, rewire it to use pins 4..7 instead of 0..3. (This just in case
    there is something wrong with the 0..3 pins, which is unlikely.)

    When you run fsrw_speed, with sdspi.spin, do you get anything on the screen at all? Let's
    see the entire screen contents. If you want, go ahead and add debugging code to
    sdspi.spin and fsrw.spin to see where it blows up.

    This does work for many people, so we just need to work through what the problem is here.

    If you don't have a scope and you are adventurous, you might try the 80MHz scope that
    was put together by Hanno; that is a really cool app.
  • APAP Posts: 24
    edited 2007-07-03 09:36
    robert - quick note of encouragement... I use the sparkfun microSD breakout board with the propeller and it works with the resistor scheme you describe (though I also use 150 Ohm to protect the I/Os). I did originally get some -13 errors as you describe, and I can't recall for sure what that specific problem was, but I believe it was that I didn't have a pull-up on CD at that time, meaning I left CD unconnected and floating. I would suggest check all connections for continuity for the following reason: I recently bough some microSD SMD sockets from Digikey, and did not reflow the parts long enough - some solder paste pads were open. I got -13 error over and over until I went around to a few pads with tip of soldering iron that "didn't quite look right" and problem was immediately solved.

    I'm sure you'll figure it out.

    Dean
  • Rob7Rob7 Posts: 275
    edited 2007-07-03 14:56
    Rokicki,

    Not to change the subject, I also wired up my sparkfun SD breakout board.
    I will follow the direction you posted to look for errors in my wireing set up.
    ·You wrote:
    ·When you run fsrw_speed, with sdspi.spin, do you get anything on the screen at all? Let's
    ·see the entire screen contents. If you want, go ahead and add debugging code to
    ·sdspi.spin and fsrw.spin to see where it blows up.
    My screen reads :
    Mounting.
    Returned from start
    -20
    When I run the fsrw_speed
    Is this also some type of timing error?

    Rob7

    Post Edited (Rob7) : 7/3/2007 3:05:14 PM GMT
  • rokickirokicki Posts: 1,000
    edited 2007-07-03 15:35
    Wow, no, a -20 is progress, that means it actually read data off the card! (But it didn't like the
    data; it couldn't find the FAT16 marker in either block 0 or in the first block referenced by the
    partition table).

    Do you always get a -20 on fsrw?

    (I need to write a debugging version of fsrw that dumps out the process, what it saw, and what
    it expected to see, for situations like this.)

    If you have access to linux, can you do the following:

    1. Insert your SD card into your linux box; figure out where it's mounted. I'm going to assume
    /dev/sdc1

    2. Type

    dd if=/dev/sdc1 of=datadump bs=512 count=2048

    That will dump the first MB into a file called datadump. Now upload this file to

    http://tomas.rokicki.com/cgi-bin/upload.pl

    and let me know it's there and I'll take a look at it to figure out what might be wrong.

    If you don't have linux, get it; you can just download Knoppix and burn it to a CD
    and boot off that to follow my instructions above.

    -tom
  • Rob7Rob7 Posts: 275
    edited 2007-07-03 15:46
    Tom,
    Yes,
    This is the screen I always get .
    I loaded a file to my SD card, however I dont think that I am formatting it correctly ?
    Do you have any sugustions on formatting my card with Win XP home edition SP2.
    I formated the card under Win XP :command prompt C:> FORMAT J: /fs:fat /a:8192
    I also found after checking my file in the SD card, it is listed as an .eeprom extension.
    What extension .xxx should I use for the prop to read it ?
    This is the extension.

    Post Edited (Rob7) : 7/3/2007 3:58:52 PM GMT
  • rokickirokicki Posts: 1,000
    edited 2007-07-03 16:41
    Well, let's see. A 512MB card with 8,192 byte sectors would give you 65K sectors, so that *should* be a FAT16
    format. But a 1GB card with 8,192 byte sectors would give you 131K sectors, so that would be FAT32 and that
    won't work (and will fail as you describe).

    I recommend using format j: /fs:fat /a:32768

    This will always give you a FAT16 for any SD card larger than 128MB (and most cards these days are larger
    than 128MB), and it will give you nice big sectors so things are fast.

    To read an ".eeprom" extension you would give it a filename ending with ".eep".

    If we're lucky the only problem is the format command.
  • Rob7Rob7 Posts: 275
    edited 2007-07-04 00:48
    Thanks, Tom
    My Fios has been giving my trouble now for two days. Verizon has me up and running again !
    Have to run out now for a B-day party.
    I will try it tonight when I get back.

    Rob7
  • hinvhinv Posts: 1,253
    edited 2007-07-04 02:17
    Hi,

    I am using a pqi 1GB micro-sd card and the sparkfun adapter. It worked great as soon as I wired it up.
    I used Femto Basic and didn't even have to change it.
    Here is how I wired it to my DemoBoard.


    Demo Socket resistor Demo
    VDD
    VCC
    P0
    DO
    10K
    VDD
    P1
    SCK
    10K
    VDD
    P2
    DI
    10K
    VDD
    P3
    CS
    10K
    VDD
    CD
    10K
    VDD

    Be careful to not let the long legs of the resisters touch. I made this mistake a couple of times.

    It the whole bible off the card very slowly in femto basic one byte at a times. It ran for several days like that.
    It took more than 24 hours to read the whole file, bible13.txt, and display it on the screen.
    It also worked well for storing programs.

    I hoped that helps.

    Doug
  • hinvhinv Posts: 1,253
    edited 2007-07-04 02:22
    I just looked at what I posted, and yours, and it looks like the only difference is that I am using 10K resisters. I don't know if that is the problem.
    It is possible that your socket is bad. Did you solder a pin header on it so you could plug it into a breadboard?

    Take Care,
    Doug
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-07-06 21:04
    Thanks to all that responded with comments and suggestions! I'd like to report that this particular issue is now resolved......

    The problem was the SD and MicroSD breakout boards from SparkFun. I had purchased one SD breakout and two MicroSD boards. It was just my luck that the SD breakout board and the MicroSD breakout board I was using were both bad. I finally tried out the extra MicroSD breakout board and everything started working perfectly! Upon closer inspection the solder pads on the SD breakout board didn't look so good. I used an exacto to clean off the leads on the socket where it is soldered and then re-soldered each connection. Once that was done the SD card adapter started working fine as well. Still no luck on the original MicroSD adapter but at least I now know that is bad and I can try to clean that up as well. If not i'll see if SparkFun will provide a warranty and replace it.

    So, if anyone else is having issues with the SD and MicroSD cards and use one of these breakout boards then don't assume the adapter is ok. Check the way it is soldered onto the board and if it doesn't look good then send it back....

    Best Regards,

    Robert
  • propelleruser999propelleruser999 Posts: 39
    edited 2008-02-09 13:37
    Hi.,
    i finally stumbled over this thread , which exactly describes my problem (error codes -41 and -13 depending on subroutine used):
    „Using MicroSD card on Demo board with FemtoBASIC? „
    started on 6/30/2007 by RobotWorkshop.

    I,ve tried all 4 submodules to fsrw.spin, from sdspi.spin to sdspiqasm.
    I get exactly the same error codes with the different subroutines, as mentioned in that posts.
    I see signals on DI, CLK, SELECT and DO), which are 3.3V conform. I have added a 0,33uf Capacitor to the SD Card powerpins, since there was a significant voltage drop on Vdd during SD Card access.

    Still errors -41 and -13.

    I used SD-cards: 128MB,256MB( dead,,but this was the only card which got to Directory detected and showed me the contents of my card, and even a file called „newfilex.txt“,which however couldn´t be rcognized by WindowsXP)and 3 1GB cards, which resulted in the same errors.

    The wires on my SD-board are in average appr. 1 inch , the longest is appr. 2 inches.

    CLK looks very good : some 8 or 9 pulse trains
    DI: a somewhat strange signal , too short to analyze with my 20 MHz osciloscope, at least a 10 to 20% positive overshoot detectabel
    SEL: a relative long negative pulse
    DO: some negative pulses

    René
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-09 14:43
    Ren
  • rokickirokicki Posts: 1,000
    edited 2008-02-09 18:02
    Yeah, -13 is timeout and -40 is timeout also (or other could-not-initialize).

    I'm a little surprised about your "significant voltage drop during SD card access"; I don't think that should be happening.
    That sounds like, maybe, you've got an output hooked up to an output somewhere, or there's a short somewhere.

    Did you format your cards in FAT16? But actually, if the cards are FAT32 you should be getting a -20 error.

    How about a photo of your setup? Maybe we can spot something. Failing that, you're just going to have to
    struggle on. Frankly the signals you describe sound all good.
  • propelleruser999propelleruser999 Posts: 39
    edited 2008-02-09 18:38
    Mike,
    if there is a problem inside my SD card socket, i have no possibilty to verify it, since i have no access to the card pins. On the card socket pins i see the signals as mentioned. I have verified connections from the card pins solder connections inside the SD card socket to my external soldering,they were ok.

    Since in Germany i can only get the same type of SD Card Adapter, i need to order one abroad in the USA,
    which will cost me (there was a link for a propeller-ready module in the range of appr. USD$12, but i can not find it anymore). However, with USPS charges of US$ 39 (that will taken into accound for the customs value) and german custom charges of 19% ( they charge on shipping too),i will end up with more than 60 bucks.
    That results in ----> need to find my problem

    regards, Ren
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-09 18:51
    I wish you the best of luck. There's a version of FemtoBasic for the 4D Systems' uOLED-96-Prop that works fine with a uSD card and the only difference in the code is the group of pin numbers used. It's not the wire length. My Hydra SD card adapter has wires several inches long to the SD card socket from the Hydra expansion card and it works fine.
  • propelleruser999propelleruser999 Posts: 39
    edited 2008-02-10 15:13
    Hi, many thanks to all for your help.
    I finally found the problem. Vdd wasn´t connected inside the SD card holder. This card holder is an SMD-type with the SMD contacts in the center of the card slot ( so i think, it can only be soldered with hot air).
    So i had to bend the contacts, in order to get them to a thru-hole mount board solder side(we call this a piece of a euro card board, actually it has 1/10 inch spaced solder pads ).
    2 pins broke during bending , so i had to solder wires from the boards solder side to the SD card holder pins.
    When i added the 0,33 uf between Vdd and Vss (due to noise problems on Vdd) the wire to the Vdd pin inside the card socket got desoldered.
    Without the capacitor i sometimes had success to get up to the point, that „newfilex.txt“ got created , but was not readable by WINXP (probably errors due to +/- 0,5 Volts noise on Vdd, with the cap it was reduced to around 50mV).

    So SD card access is now working (128MB, 256 is dead by applying incorrect voltages , 1 GB SD cards work).

    Still open is
    - german keyboard support
    - mouse doesn´t work (data in has output from propeller)
    - can´t get VGA 512*384 bitmap demo to work (unsupported frame rate)
    but that will be subject to other threads.

    René

    Post Edited (propelleruser999) : 2/10/2008 5:07:18 PM GMT
  • propelleruser999propelleruser999 Posts: 39
    edited 2008-02-10 17:03
    Hi, many thanks to all for your help.
    I finally found the problem. Vdd wasn´t connected inside the SD card holder. This card holder is an SMD-type with the SMD contacts in the center of the card slot ( so i think, it can only be soldered with hot air).
    So i had to bend the contacts, in order to get them to a thru-hole mount board solder side.
    2 pins broke during bending , so i had to solder wires from the boards solder side to the SD card holder pins.
    When i added the 0,33 uf between Vdd and Vss (due to noise problems on Vdd) the wire to the Vdd pin inside the card socket got desoldered.
    Without the capacitor i sometimes had success to get up to the point, that „newfilex.txt“ got created , but was not readable by WINXP (probably errors due to +/- 0,5 Volts noise on Vdd, with the cap it was reduced to around 50mV).

    So SD card access is now working (128MB, 256 is dead by applying incorrect voltages , 1 GB SD cards work).

    Still open is
    - german keyboard support
    - mouse doesn´t work (data in has output from propeller)
    - can´t get VGA 512*384 bitmap demo to work (unsupported frame rate)
    but that will be subject to other threads.

    René
Sign In or Register to comment.