Write variables with FSRW or SD_MMC_FATEngine to an SD card
lfreeze
Posts: 174
Please help !
I am using the FSRW object, and the SD Cards write tutorial provided by
Gadget Gangster. Everything worked fine with the tutorial. I am able to write strings to the SD card. I then tried to modify the Write program (original below) to include a variable. I did many, many trial and error attempts, mostly including the Numbers object, I was not successful. Can anyone provide a simple example of writing a variable to the SD card?
I have not tried the FAT/16/FAT32 full file system driver. Does a simple example
Of writing a variable to an SD card exist for this routine?
Many thanks for any help .
Larry
WRITE STRINGS TO SD CARD
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
do = 27 '0
clk = 26 '1
di = 25 '2
cs = 24' 3
obj
sdfat : "fsrw"
pst : "Parallax Serial Terminal"
num : "numbers"
Pub demo | mount ,able
able:=1
pst.start(115_200)
waitcnt(clkfreq*4 + cnt)
mount := \sdfat.mount_explicit(do, clk, di, cs)
if mount < 0
pst.str( string( 13, "Failed to Mount", 13 ))
abort
pst.str(string(13, "SD card was found and mounted okay" ,13))
sdfat.popen(string("test.txt"),"w")
repeat 10
sdfat.pputs(string("Sending Strings is Easy",13,10 ))
sdfat.pclose
sdfat.unmount
I am using the FSRW object, and the SD Cards write tutorial provided by
Gadget Gangster. Everything worked fine with the tutorial. I am able to write strings to the SD card. I then tried to modify the Write program (original below) to include a variable. I did many, many trial and error attempts, mostly including the Numbers object, I was not successful. Can anyone provide a simple example of writing a variable to the SD card?
I have not tried the FAT/16/FAT32 full file system driver. Does a simple example
Of writing a variable to an SD card exist for this routine?
Many thanks for any help .
Larry
WRITE STRINGS TO SD CARD
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
do = 27 '0
clk = 26 '1
di = 25 '2
cs = 24' 3
obj
sdfat : "fsrw"
pst : "Parallax Serial Terminal"
num : "numbers"
Pub demo | mount ,able
able:=1
pst.start(115_200)
waitcnt(clkfreq*4 + cnt)
mount := \sdfat.mount_explicit(do, clk, di, cs)
if mount < 0
pst.str( string( 13, "Failed to Mount", 13 ))
abort
pst.str(string(13, "SD card was found and mounted okay" ,13))
sdfat.popen(string("test.txt"),"w")
repeat 10
sdfat.pputs(string("Sending Strings is Easy",13,10 ))
sdfat.pclose
sdfat.unmount
Comments
PUB dec(value) | i
'' Print a decimal number
if value < 0
-value
sdfat.pputc("-")
i := 1_000_000_000
repeat 10
if value => i
sdfat.pputc(value / i + "0")
value //= i
result~~
elseif result or i == 1
sdfat.pputc("0")
i /= 10
I changed the write program to include and use the full duplex serial object.
I created a variable, able and assigned it a value of 1. I loaded, and ran the write program. I replaced this line:
sdfat.pputs(string("Sending Strings is Easy",13,10 ))
With this line:
ser.dec(able)
I got all blanks when I read the card
Can you point me in the right direction? I probably misunderstood your suggestion
Thanks
Larry
You spend alot less time debugging.
into a modified sdfat.
Chances are you have included the sdfat program multiple times, so they each get their
own set of variables (which means their own file).
Thus, the modified ser() routine is not writing to the file you think it is (it is writing to a
non-existent file).
A question for KYE: I downloaded the AN006 application note and read it
Thoroughly. I must admit that I am confused on how to modify the engine program to match the connections on my SD card.
The current connection on the card I am using are:
SD Propeller
DO 27
CLK 26
DI 25
CS 24
These connections work okay using the FSRW object (writing strings)
I notice on page 15 of the PDF , there are some examples
Of how to create, open, and append a file. I did not find a simple example of how to write a byte or long variable to the card. If you have an example, please provide it.
Thanks again……
Larry
Thank you for pointing out AN006. This subject is something I need to read up on and use.
Also, the file system works kinda like a serial port... All the information you need is there in the demo code included with the driver. Please read the demo code. It shows how to do everything you want.
Larry
Update the GG tutorial with some demonstrations on how to write numbers... Thanks for pointing out this need.
(The AN006 document is most excellent, but different folks learn in different ways, so alternatives are always a good idea...)
OBC
They are not fully commented, but give them a try. I am not very skilled at writing spin code but, persisted with a lot of trial and error
and cutting and pasting.
Larry