Close

Reading a file now!

A project log for Propeller Weekender: SD-Card Experimentation!

Testing the SD-Card on the Parallax Propeller!

uncle-yonguncle-yong 08/18/2019 at 13:300 Comments

So after messing and futzing around with their novel Spin language (I suspect it's a hybrid of Python, some C and probably Pascal?) I managed to coax that thing to print out an excerpt from the Propeller Manual. (source: https://www.parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2.pdf

I named the text file "textfile.txt" and written the excerpt into it :

The Propeller chip is designed to provide high-speed processing for embedded systems while
maintaining low current consumption and a small physical footprint. In addition to being
fast, the Propeller provides flexibility and power through its eight processors, called cogs,
that can perform simultaneous independent or cooperative tasks, all while maintaining a
relatively simple architecture that is easy to learn and utilize.

And also the code to read the file:

{ FSRW Test }


CON
        _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
        _xinfreq = 5_000_000

        SDO = 15
        SDI = 13
        SCK = 14
        CS  = 16

VAR
  long symbol
  byte isMounted
  byte textBuf[512]
  byte bufCount
   
OBJ
  fsrw: "fsrw.spin"
  pst: "Parallax Serial Terminal.spin"
  spisd: "safe_spi.spin"
  
PUB main

  DIRA[3] := 1   
  pst.Start(115200)
  pst.Str(String("Hello World Propeller!",13))

  bytefill(@textBuf, 0, 128)
  isMounted := fsrw.mount_explicit(SDO, SCK, SDI, CS)

  if(isMounted == 0)
    pst.Str(String("SD-Card Detected!",13))
  else
    pst.Str(String("SD-Card error or not found!",13))
    repeat
      'wait here and blink LED for 500ms if error or not found!
      OUTA[3] := 0
      waitcnt(cnt + (clkfreq/2))
      OUTA[3] := 1
      waitcnt(cnt + (clkfreq/2))

  fsrw.Seek(0)    
  pst.Str(String("Reading SD Card!",13))
  if( fsrw.popen(String("textfile.txt"), "r") == 0 )
     pst.Str(String("File is found, reading it now!",13))
     if( fsrw.pread(@textBuf, 512) < 0 )
        pst.Str(String("Reached end of the file!",13))
     pst.Str(@textBuf)   
  else
    pst.Str(String("File not found!",13))

  pst.Str(String(13))    
  fsrw.pclose    
  waitcnt(cnt + (clkfreq))
  pst.Str(String("Done, unmount!",13))
  fsrw.unmount


  repeat


PRI private_method_name


DAT
name    byte  "string_data",0        
        

And the output:

Success! That'll be the reference for me (and the readers) to write more code for the Propeller.

Discussions