Shop OBEX P1 Docs P2 Docs Learn Events
SPI interface on Propeller ASC and Arduino Wireless SD Shield — Parallax Forums

SPI interface on Propeller ASC and Arduino Wireless SD Shield

doggiedocdoggiedoc Posts: 2,245
edited 2012-10-16 18:33 in General Discussion
I've been trying to get the SD card on the Arduino Wireless SD Shield to work. I'm using Kye's FATEngine object and the code works with Gadget Gangster Quickstart Module and Spinneret SD card readers. I've changed the pin to what is listed for the Shield assuming I am interpreting MOSI as DO, MISO as DI, and of course CLK and CS to Pins 11, 12, 13, and 4 respectively.

I have tried the only size micro SD cards I have 4GB SanDisk and 4GB PNY cards. I've included the code:
{SD Read Test - using Kye's FATEngine
}


CON

  _clkmode = xtal1 + pll16x ' The clkfreq is 80MHz.
  _xinfreq = 5_000_000 ' Demo board compatible.

  _dopin = 11
  _clkpin = 13
  _dipin = 12
  _cspin = 4
  _cdpin = -1 ' -1 if unused.
  _wppin = -1 ' -1 if unused.

  _rtcres1 = -1 ' -1 always.
  _rtcres2 = -1 ' -1 always.  
  _rtcres3 = -1 ' -1 always.  

  _statuspin = 23  ' Status LED pin number.

OBJ
  fate      : "SD-MMC_FATEngine"
  pst        : "Parallax Serial Terminal"
  
PUB main |  data, r, errorNumber, partitionName, fileName

       init                                                                                  
       pst.str(string(13, "[INITIALIZATION COMPLETE]",13))
       mountCard
          
       statusLED(-1)
       partitionName := \fate.partitionVolumeLabel
         
       pst.str(string(13, "[SD Volume Mounted Successfully]",13))
       pst.str(string("Volume = "))
       pst.str(partitionName)
       pst.str(string(13))

       ListDir

       pst.str(string(13, "Enter Name of file to Open: "))
       pst.strin(fileName)
       
       \fate.openFile(fileName,"R")
       errorNumber := \fate.partitionError
       if (errorNumber)
          handleError
       pst.str(string(13, "[File Opened]", 13, 10))

       repeat
          r := \fate.readByte
          if r < 0
            pst.newline
            \fate.unmountPartition
            quit
          if r > 10
            pst.str(@r)     
 
       \fate.closeFile
       pst.str(string(13, "[Closing file ....]", 13))      

       \fate.unmountPartition
       pst.str(string(13, "[... and unmounting SD card.]", 13))      

       waitcnt(clkfreq * 2 + cnt)
       pst.str(string(13, "[You may now safely eject SD card.]", 13)) 

PRI init

     pst.Start(115_200)
     fate.fatEngineStart( _dopin, _clkpin, _dipin, _cspin, _wppin, _cdpin, {
        } _rtcres1, _rtcres2, _rtcres3)

     waitcnt(clkfreq*2 + cnt)
       

PRI statusLED(frequency) | buffer, counter ' Configure the status LED.

  ' Frequency must be between 0 and (clkfreq / 2). Otherwise output is always 1.

  buffer := ((0 < frequency) and (frequency =< (clkfreq >> 1)))

  outa[_statuspin] := (not(buffer))
  ctra := (buffer & constant((%00100 << 26) + _statuspin))
  dira[_statuspin] := true

  counter := 1
  repeat 32 ' Preform (((frequency << 32) / clkfreq) + 1)

    frequency <<= 1
    counter <-= 1
    if(frequency => clkfreq)
      frequency -= clkfreq
      counter += 1

  frqa := (buffer & counter) ' Output is always 0 if frequency is 0.

PRI mountCard


      \fate.mountPartition(0)

      if(!fate.partitionMounted)
        pst.str(string(13, "[ERROR! Failed to mount SD Card]", 13 ))
        handleError

PRI handleError
    
      statusLED(2)
      
      waitcnt(clkfreq * 20 + cnt)
      mountCard
      
PRI ListDir | buffer,counter,match

    fate.listEntries("W")
    pst.str(string("DIR listing: ",13))   
    repeat while(buffer := fate.listEntries("N"))
    
         pst.str(buffer)
         pst.str(string(13))                                           

I've also added it as an attachment.

Anybody had success with SD Shields on the Propeller ASC? BTW I have a rev-e of the Propeller ASC board

Thanks,
Paul

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-10-16 13:03
    The Propeller ASC uses 1K resistors in series with the various Arduino I/O pins. Depending on what's on the SD Shield, these serial resistors may prevent the Propeller from pulling down the signal lines to an adequately low voltage. You could use the SD card with the ASC's expansion port which doesn't have the 1K resistors.
  • doggiedocdoggiedoc Posts: 2,245
    edited 2012-10-16 13:31
    I presume that means jumper wires to the correct pins on the shield? I'll go find the pin diagrams for the ASC and figure it out!

    Thanks Mike!
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2012-10-16 13:34
    MOSI will be DI, MISO will be DO. You definitely need A solder bridge on those four pins. I don't have the shield, so I assume pin 4 is the CS output. 11, 12 and 13 are the standard Arduino pins for SPI.

    Ack! No jumper wires. Use the super convenient solder jumpers on the back!
  • doggiedocdoggiedoc Posts: 2,245
    edited 2012-10-16 13:43
    Martin - you are a genius! So all I need is to bridge the pads on the bottom of the ASC for pins 4, 11, 12, and 13 to bypass the resistors? Cool!

    Dang - I don't have an iron at work. Guess it will have to wait until I get home! :D

    @paw
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2012-10-16 13:47
    Yep, that's all you gotta do. Just realized I don't have a photo of the jumpers on the Wiki. I've got some work to do.

    Also. Measure the voltages on those pins, with the shield connected, and make sure they're all 3.3v before bypassing the resistors.

    Is this the shield you're working on? https://www.sparkfun.com/products/11287?
  • doggiedocdoggiedoc Posts: 2,245
    edited 2012-10-16 14:31
    I'll be sure to check those voltages -

    Not that board... this one: http://store.arduino.cc/ww/index.php?main_page=product_info&cPath=11_5&products_id=146
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2012-10-16 15:14
    Ah that shield looks like it's all 3.3v anyway, so you should be good to go.
  • doggiedocdoggiedoc Posts: 2,245
    edited 2012-10-16 15:16
    It works!!!!
    You dudes know your stuff man!
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2012-10-16 17:40
    If you're interested, doc. You're welcome to some wiki space to put up some compatibility notes for that shield.
  • doggiedocdoggiedoc Posts: 2,245
    edited 2012-10-16 18:33
    Care to elaborate?
    If you're interested, doc. You're welcome to some wiki space to put up some compatibility notes for that shield.
Sign In or Register to comment.