Problem with sd card read and write.
·· I am writing to a sd file the value of a counter. I am update the file about every 20 secs. As long a the value is less than 6 digits, ie:999999 there seems to be no problem. A 6 digit number is written as 8 characters with the cr,lf at the end. Since the problem seems to be 8bytes, I am wondering if it is a memory problem of some sort.
· I am using fsrw. I have included the code dirty as it is. I don't expect anyone to fix the code just throw out some ideas.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
· I am using fsrw. I have included the code dirty as it is. I don't expect anyone to fix the code just throw out some ideas.
pri hobbswrite|r,y,digits
digits:=x:=1
repeat while digits=<hobbsvalue
digits:=digits*10
x++
digits:=digits/10
r:=sdfat.mount(0)
r := sdfat.popen(string("value.txt"), "w")
repeat y from 0 to x-2
r:=hobbsvalue/digits
if r => ("0") and r =< ("9")
sdfat.pputc(r+48)
'term.dec(r)
byte[noparse][[/noparse]@infoin+y]:=r
hobbsvalue:=hobbsvalue//digits
digits:=digits/10
byte[noparse][[/noparse]@infoin[noparse][[/noparse]y+1]]:=$0D
'term.str(string("Infoin "))
'term.out($0D)
'term.str(@infoin)
'term.out($0D)
repeat y from 0 to strsize(@infoin)
r:=byte[noparse][[/noparse]@infoin][noparse][[/noparse]y]
'term.hex(r,2)
if r => ("0") and r =< ("9")
sdfat.pputc(r+48)
sdfat.pputc($0D)
sdfat.pclose
hobbsread
'term.str(@infoin)
waitcnt(clkfreq*4+cnt)
pri hobbsread |r ,mult,y ,val
'out(0)
r:= sdfat.mount(0)
'term.hex(r,2)
x:=0
r := sdfat.popen(string("value.txt"), "r")
row:=2
col:=1
printstr(string("File is "))
hex(r,2)
mult:=1
repeat while r=>0
r:= sdfat.pgetc
if r => ("0") and r =< ("9")
byte[noparse][[/noparse]@infoin[noparse][[/noparse]x++]]:=r
mult:=mult*10
mult:=mult/100
hobbsvalue:=0
repeat y from 0 to x-2
r:=byte[noparse][[/noparse]@infoin[noparse][[/noparse]y]]
val:=(r-48)*mult
hobbsvalue:=hobbsvalue+val
mult:=mult/10
if hobbsvalue<hobbsold
hobbsvalue:=hobbsold
else
hobbsold:=hobbsvalue
'term.out(0)
'term.str(string("Read "))
'term.dec(hobbsvalue)
sdfat.pclose
waitcnt(clkfreq*4+cnt)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········

Comments
hobbsvalue:=1000
hobbswrite
The screen prints 1. Is there something special about zeros?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
hobbsvalue:=hobbsvalue//digits
Should be:
hobbsvalue:=hobbsvalue-r*digits
Otherwise,
you might just use this funciton from vga_text:
PUB dec(value) | i '' Print a decimal number if value < 0 -value out("-") i := 1_000_000_000 repeat 10 if value => i out(value / i + "0") value //= i result~~ elseif result or i == 1 out("0") i /= 10just replace "out" with "sdfat.pputc"
·out(value / i + "0") ?what is the "0" for?
····· value //= i······ ?//= in english?
Can anyone explain these 2 lines?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······
······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
//= is the modulus operator... This is just the remainder after division (so 15//10=5)