-
Reading a file now!
08/18/2019 at 13:30 • 0 commentsSo 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.
-
SD-Card detected!
08/18/2019 at 09:59 • 0 commentsI got myself a bunch of these Propeller chips and the Prop tool back in late 2010 when I have already graduated. The tough part was getting these libraries to work. I was very young at that time and inexperienced, and tried to get Propeller to work with SD-Card, but failed miserably.
Many years later, I chanced upon these stuff when I'm cleaning the room. Maybe I can give it a try again? What problems would I see again?
Here are the bare minimum to connect the SD-Card to the Propeller:
Looks fine eh? Oh well, back then I did not bother to put the pull-ups. Prolly why it kept failing. In the schematic, it's not labelled, but it's usually 10K.
I got these pieces of code from http://obex.parallax.com/object/33. That was the simplest, and doesn't look like the drivers are scattered all over the place.
Then the fun part begins - I try to get it to be detected. That was that itch I wanna scratch since 2010:
{ 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 OBJ fsrw: "fsrw.spin" pst: "Parallax Serial Terminal.spin" spisd: "safe_spi.spin" PUB main pst.Start(115200) pst.Str(String("Hello World Propeller!")) isMounted := fsrw.mount_explicit(SDO, SCK, SDI, CS) if(isMounted == 0) pst.Str(String("SD-Card Detected!")) else pst.Str(String("SD-Card error or not found!")) DIRA[3] := 1 repeat OUTA[3] := 0 waitcnt(cnt + (clkfreq/2)) OUTA[3] := 1 waitcnt(cnt + (clkfreq/2)) PRI private_method_name DAT name byte "string_data",0
Did it work? At the start, no. It hung after the "mount_explicit".
I searched around for an hour or so. Then went to nap. After the nap I looked at the breadboard and I found the SD-Card didn't get powered up (the little red and black wires below the pull-up resistors):
Damn, I looked really stupid on that one! Connecting to it, it's all working!
What am I gonna do next? It's simple: I'm trying to see if I can read or write something on it!
Firstly, if it doesn't get detected or hang up:
- Flip the SDI and SDO pin numbers on the "CON" area.
- Make sure the SD-Card is powered.
- Make sure the SD-Card is fully inserted into the slot!