Help with writing to SD file please!
Hugh
Posts: 362
Hi folks,
I'm scratching my head and going round in circles - I'll soon be dizzy and bald, so any assistance you could suggest would be gratefully received by me!
I have some data in a variable of up to 40 bytes in length. I can display the contents of the last fifteen bytes (the portion of interest) to an LCD display easily, but I don't seem to be able to write it to a file on an SD card using FSRW v2.4.
The code looks like:
What actually gets written is ".|.|.|.|.|.|.|.|.|.|.|,"
I have tried without the 'num.dec' (Num = simpleNumbers.spin), using bytemove and pwrite, and many others combinations...
It is probably staring me in the face but what am I doing wrong, or not doing?
Thanks
Bald dizzy Hugh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
I'm scratching my head and going round in circles - I'll soon be dizzy and bald, so any assistance you could suggest would be gratefully received by me!
I have some data in a variable of up to 40 bytes in length. I can display the contents of the last fifteen bytes (the portion of interest) to an LCD display easily, but I don't seem to be able to write it to a file on an SD card using FSRW v2.4.
The code looks like:
r:= sdfat.mount(0) sdfat.popen(string("Data5.txt"), "a") repeat 11 lcd.dec(dataIn[noparse][[/noparse]ct - charCtr]) ' ct = length, so say = 30 lcd.putc(32) ' charCtr starts at 15 sdfat.pputs(num.dec(dataIn[noparse][[/noparse]ct - charCtr--])) sdfat.pputs(44)
What actually gets written is ".|.|.|.|.|.|.|.|.|.|.|,"
I have tried without the 'num.dec' (Num = simpleNumbers.spin), using bytemove and pwrite, and many others combinations...
It is probably staring me in the face but what am I doing wrong, or not doing?
Thanks
Bald dizzy Hugh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
- use the same output from num.dec in the LCD and SD code
- make sure to close the file when you are done writing...if you power off or unplug the SD card, the FAT table may not be updated.
- using "pputs(44)" writes a string where the starting pointer address is 44....probably not what you want!
- verify your pins connecting to the sd card, and check the return value of the mount call.
check out the following code (I made some guesses about variables and OBJ types):
Please let me know if that changes anything.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Post Edited (lonesock) : 10/28/2009 9:10:44 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
What shows up on the LCD?
Don't forget that you have to close the file after you finish writing or the last 512 byte block won't be written to the SD card.
Lonesock's code as above results in a series of what I would call 'high ASCII' characters being displayed on the LCD - if I display them using...
...they display correctly. Sometimes "data6.txt" is an empty file.
A different procedure in the same code writes various data to a file on the SD card without a problem.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.