Shop OBEX P1 Docs P2 Docs Learn Events
PropC3 MicroSD card question — Parallax Forums

PropC3 MicroSD card question

tim1986tim1986 Posts: 41
edited 2011-02-05 20:31 in Propeller 1
Hey i just got the propeller C3 board. I can't seem to access a 4GB microSD SDHC card with the "prop_c3_unit_test_010.spin" demo. I can use this exact same card on a propeller protoboard with SD card adapter and socket. I think I was using the FSRW driver.

I was reading on the forum that "the new fsrw object now supports sdhc cards(cards over 2gb are all this type) " by mctrivia http://forums.parallax.com/showthread.php?123796-micro-sd-card&highlight=c3+micro+sd+sdhc

Is there a FSRW driver for the C3??

Thanks in advance!
-Tim

Comments

  • wjsteelewjsteele Posts: 697
    edited 2011-02-01 03:10
    Just looking at the schematic, it looks like you will have to modify FSRW slightly to support it. For one, the SPI bus is on pins 8-11, whereas the default config for FSRW is 0-3. Also, I think, but don't know for certain, that you will need to do something to enable the MUX to switch to the SD card, which is on Channel 5. They appear to need to have SPI_SEL0 - SPI-SEL2 to be set, but I see nothing in the schematic (at first glance) that indicates how to do that... possibly by reading in the documentation it will tell you exactly how to do that. My guess is that it's done in software via the I2C bus. If that is the case, it should be a simple software change to enable it.

    Bill
  • wjsteelewjsteele Posts: 697
    edited 2011-02-01 03:19
    Upon further reading, I see a very clever design. :-) I wasn't exactly right, in that it doesn't use the I2C bus to select the correct MUX, instead Pin 8 and 25 are used to toggle a counter and clear it for SPI_Channel selection. Simply toggle the SPI_SEL_CLR pin to reset the counter and then toggle the SPI_SEL_CLK pin 4 times to get to Channel 5, which will enable pins 9-11 for SPI communication to the SD card.

    Bill
  • tim1986tim1986 Posts: 41
    edited 2011-02-01 13:32
    Thank you Bill! I had already found out about the chip selection SPI_SEL_CLR and SPI_SEL_CLK pins and the toggle sequence. I just didn't know to change the pins. Thanks again! I'll post the modified FSRW here when I get it working.
  • TubularTubular Posts: 4,717
    edited 2011-02-01 14:47
    I liken the SPI select mechanism to those old decadic rotary phones... CLR is analogous to going off-hook, then dial 1 for SRAM, 3 for flash, dial 5 for MicroSD...
  • tim1986tim1986 Posts: 41
    edited 2011-02-01 17:15
    Well, I tried using the correct chip select method and pins. It didn't work.

    I tried modifying FSRW by removing CS(chip select) references and adding the SPI_Select_Channel and SPI_Init. It didn't work.

    I really would like SDHC support for the PropC3.

    -Tim
  • tim1986tim1986 Posts: 41
    edited 2011-02-01 18:47
    Well, what I'm really trying to do with the propC3 is playing wav files off of the microSD card. I had this working with the propeller proto board, but it does NOT work with the propC3.

    I'm beginning to feel like the Propeller C3 is not as useful as it is intended to be.

    Please help,
    -Tim
  • wjsteelewjsteele Posts: 697
    edited 2011-02-01 19:41
    I think you might be trying to debug two problems... have you tried using just a regular MicroSD card instead of the HDSD Card? I just wonder if that might be the problem.

    I know that FSRW works with 2gig and under but I haven't tried it with HD cards yet. (BTW... I just bought a whole gaggle of 2gig MicroSD cards for $5 each off of Amazon (including shipping) so they should be real easy and inexpensive to find.)

    I wish I could help you further, but I don't have a C3 yet.

    Bill
  • David BetzDavid Betz Posts: 14,516
    edited 2011-02-01 19:57
    Hi! I have been using a C3 for a while and have had good luck with 2gb SD cards. I have attached the version of fsrw that I use on my C3. I don't have any SDHC cards so I'm not sure if this driver will work with them but it seem to work okay with my 2gb SD cards.

    David
  • tim1986tim1986 Posts: 41
    edited 2011-02-01 22:31
    Thank you Bill and David. I'll have to try this out tomorrow after work. I'm glad you made a compatible version of FSRW David!
    Thanks,
    -Tim
  • tim1986tim1986 Posts: 41
    edited 2011-02-02 21:10
    Hey David. The "#ifdef" lines are giving me an error. "Expected unique object name." I guess I'll just comment out the un-needed lines.
    -Tim
  • tim1986tim1986 Posts: 41
    edited 2011-02-02 21:53
    Well, it's still not working. :( I'll post my code.

    ' SPIN WAV Player Ver. 1a (Plays only mono WAV at 16ksps)
    ' Copyright 2007 Raymond Allen See end of file for terms of use.
    ' Settings for Demo Board Audio Output: Right Pin# = 10, Left Pin# = 11 , VGA base=Pin16, TV base=Pin12


    CON _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000 '80 MHz

    buffSize = 256

    VAR long parameter
    long buff1[buffSize]
    long buff2[buffSize]
    long stack1[100]
    word MonoData[buffSize]

    OBJ
    'text : "vga_text" 'For NTSC TV Video: Comment out this line...
    'text : "tv_text" 'and un-comment this line (need to change pin parameter for text.start(pin) command below too).
    'SD : "FSRW"
    SD : "fsrwFemto_rr001.spin"
    num : "numbers"

    PUB Main|n,i,j
    'Play a WAV File
    dira[12] := 1
    outa[12] := 0
    'Start up the status display...
    'text.start(16) 'Start the VGA/TV text driver (uses another cog)
    'The parameter (16) is the base pin used by demo and proto boards for VGA output
    'Change (16) to (12) when using "tv_text" driver with demo board as it uses pin#12 for video
    'text.str(STRING("Starting Up",13))

    'open the WAV file (NOTE: Only plays mono, 16000 ksps PCM WAV Files !!!!!!!!!!!!!)
    'access SD card
    i:=sd.mount_explicit(9, 11, 10, 0)
    if (i==0)
    'text.str(STRING("SD Card Mounted",13))
    else
    'text.str(STRING("SD Card Mount Failed",13))
    repeat

    'open file
    i:=sd.popen(string("test1.wav"), "r") ' <
    Change .wav filename here !!!!!!!!!!!!!!
    'i:=sd.popen(string("test2.wav"), "r") ' <
    Change .wav filename here !!!!!!!!!!!!!!
    'i:=sd.popen(string("test3.wav"), "r") ' <
    Change .wav filename here !!!!!!!!!!!!!!
    'i:=sd.popen(string("test4.wav"), "r") ' <
    Change .wav filename here !!!!!!!!!!!!!!
    'i:=sd.popen(string("gauss22.wav"), "r")
    'i:=sd.popen(string("gchargef.wav"), "r")
    'text.str(STRING("Opening: "))
    'text.str(num.toStr(i,num#dec))
    'text.out(13)

    'ignore the file header (so you better have the format right!)
    'See here for header format: http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
    i:=sd.pread(@MonoData, 44) 'read data words to input stereo buffer
    'text.str(STRING("Header Read ",13))


    'Start the player in a new cog
    COGNEW(Player(24, 1),@stack1) 'Play runs in a seperate COG (because SPIN is a bit slow!!)
    'text.str(STRING("Playing...",13))


    'Keep filling buffers until end of file
    ' note: using alternating buffers to keep data always at the ready...
    n:=buffSize-1
    j:=buffsize*2
    repeat while (j==buffsize*2) 'repeat until end of file
    if (buff1[n]==0)
    j:=sd.pread(@MonoData, buffSize*2) 'read data words to input stereo buffer
    'fill table 1
    repeat i from 0 to n
    buff1:=($8000+MonoData)<<16
    if (buff2[n]==0)
    j:=sd.pread(@MonoData, buffSize*2) 'read data words to input stereo buffer
    'fill table 1
    repeat i from 0 to n
    buff2:=($8000+MonoData)<<16


    'must have reached the end of the file, so close it
    'text.str(STRING("Closing: "))
    sd.pclose

    'shut down here

    PUB Player(PinR, PinL)|n,i,nextCnt,rate,dcnt
    'Play the wav data using counter modules
    'although just mono, using both counters to play the same thing on both left and right pins

    'Set pins to output mode
    DIRA[PinR]~~ 'Set Right Pin to output
    DIRA[PinL]~~ 'Set Left Pin to output

    'Set up the counters
    CTRA:= %00110 << 26 + 0<<9 + PinR 'NCO/PWM Single-Ended APIN=Pin (BPIN=0 always 0)
    CTRB:= %00110 << 26 + 0<<9 + PinL 'NCO/PWM Single-Ended APIN=Pin (BPIN=0 always 0)

    'get length
    n:=long[MonoData+40]
    'get rate
    rate:=long[MonoData+24]
    case rate
    8000:
    dcnt:=10000
    16000:
    dcnt:=5000
    other:
    return false
    'jump over header
    MonoData+=44 'ignore rest of header (so you better have the right file format!)


    'Get ready for fast loop
    n--
    i:=0
    NextCnt:=cnt+15000

    'Play loop
    repeat i from 0 to n
    NextCnt+=dcnt ' need this to be 5000 for 16KSPS @ 80 MHz
    waitcnt(NextCnt)
    FRQA:=(byte[MonoData+i])<<24
    FRQB:=FRQA


    'Easy high-impedance output (e.g., to "line in" input of computer or sound system)
    '
    ' R=100
    ' Prop Pin ────┳──────── Audio Out
    ' C=0.1uF
    ' 
    ' Vss




    {{
    TERMS OF USE: MIT License

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
    }}
  • tim1986tim1986 Posts: 41
    edited 2011-02-03 20:30
    So, I tried downloading a new copy of "wav players" object. I tried to get it working on the board I had it working on. I couldn't get it to work. I don't know what I'm doing wrong. :(
  • David BetzDavid Betz Posts: 14,516
    edited 2011-02-04 04:32
    tim1986 wrote: »
    Hey David. The "#ifdef" lines are giving me an error. "Expected unique object name." I guess I'll just comment out the un-needed lines.
    -Tim
    Sorry. I use BSTC to compile my Spin code and it supports #ifdef. As you suggest, you can just comment those out as well as the SPI non-C3 SPI driver.
  • TubularTubular Posts: 4,717
    edited 2011-02-04 06:02
    Tim1986

    I had a go at modifying Kye's SD2.0_FatEngine for C3 style SPI, but ran out of room in the cog. I'll see if I can compact things a bit tomorrow.
  • David BetzDavid Betz Posts: 14,516
    edited 2011-02-04 06:52
    tim1986 wrote: »
    Well, it's still not working. :( I'll post my code.
    You might want to put the mount code in a loop so that you make more than one attempt to mount the SD card. I've noticed that it often doesn't mount successfully the first time.
  • AndreLAndreL Posts: 1,004
    edited 2011-02-04 23:17
    The SD card spec for any operation is MORE than once, so you should make attempts up to 256 times for many operations. In most cases they will succeed in 2-4 tries, but up to 16 are needed by some cards under some drivers. So, all mounting, and init operations should ALL be in a loop or I guarantee you driver will work on your card and break on others. Remember, SD card drivers like video drivers, you need to get a good 5-10 brands and try on all then you know the driver is robust.

    Andre'
  • tim1986tim1986 Posts: 41
    edited 2011-02-05 00:22
    Thanks for this info/tips David and Andre'.
  • tim1986tim1986 Posts: 41
    edited 2011-02-05 20:31
    Well, I tried to add a 'repeat' right before the mount command and it seems to just get stuck on that it won't even go to the very next command that prints a string to the C3 tv text object.
Sign In or Register to comment.