Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Sdcreatefileordir problems..

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> KokkeKat FAT-free SD card lib
View previous topic :: View next topic  
Author Message
svberg

Bascom Member



Joined: 07 Nov 2011
Posts: 48

blank.gif
PostPosted: Fri Jan 02, 2015 6:10 pm    Post subject: Sdcreatefileordir problems.. Reply with quote

Hi.
My settings in lib are;
Const Sdinitdetail = 0
Const Sdfsactive = 1
Const Sdusefind = 0
Const Sdusefindstoreentry = 0
Const Sdusedirlist = 1 ' Use or don't use
Const Sddirlistarraysize = 12 ' If used, set the size of the array that holds the cluster numbers
Const Sdrmode = 1
Const Sdwmode = 2
Const Sduseappend =1
Const Sdcleartail = 0
Const Sdusefsinfo = 0
Const Sduselfn = 0
Const Sduselfncompare = 0
Const Sdusewipe = 0
Const Sdusedirlistdelete = 0
Const Sdusesizeinfo = 0
Const Sdusecrc7 = 0 ' This has no practical use in the library - use it if you want to add

Program;
gosub sdinit
print sdstatus;" ";sdcardtype

Sdentrynames = "log1501.txt"
Sdcreatemode = 0 ' file
Sdstartdirclusterd = 0 for root directory.
Sdyear = 2015 'the year
Sdmonth = 01 'the month
Sdday = 02 'the day
Sdhours = 17 'the hours
Sdminutes = 33 'the minutes
Sdseconds = 59 'the seconds
Sdmseconds =234 'the milliseconds
print "Creating file"
Sdcreatemode = 0 ' Create file
Sdstartdirclusterd = 0
gosub Sdcreatefileordir

print sdstatus;" ";sdcardtype

After SDinit I get SdStatus=0 and cardtype=3. So far so good.
But calling the Sdcreatefileordir, programs never return, and I have to reset.

Using Arduino Mega 16MHz, and Bascom 2.0.7.8.002

SD card is HC 4Gb, which have been formatted FAT and tested in PC..
Any ideas, any help??
Best regards svein
Back to top
View user's profile
KokkeKat

Bascom Member



Joined: 08 May 2011
Posts: 59
Location: Stockholm

sweden.gif
PostPosted: Fri Jan 02, 2015 10:40 pm    Post subject: Reply with quote

Hi Svein,

I have moved your posting to a separate thread.

Could you please try the "Example_WRITE_FILE.bas" template code in the zip file that you find in thread "Latest release"?

If I remember correctly, you must specify the filename in exactly that way (11 CAPITAL letters without the dot).

Please also see "6.9.1 Initialization sequence" in the pdf document. You are missing the gosub Sdreadfsinfo call after calling Sdinit.

I hope this will help.

Cheers

Niclas
Back to top
View user's profile
svberg

Bascom Member



Joined: 07 Nov 2011
Posts: 48

blank.gif
PostPosted: Sat Jan 03, 2015 8:54 pm    Post subject: HI Niclas Reply with quote

Thanks for super quick response!!
Sdreadfsinfo did the trick..
But, still have problems.

Heres the program;
.
.
gosub SDCardInit
gosub writelog
.
.
**************************************
SDcardInit:

Gosub Sdinit
if sdstatus=0 then
'SD OK.
'Check If Log file Exists.
gosub Sdinitfs
tmpstr=str(maned)
tmpstr=format(tmpstr,"00")
Sdentrynames = "LOG" + str(ar) + "02" + " TXT"
Gosub Checkforfile
if sdstatus<>37 then 'No file, Make it
Sdcreatemode = 0 ' file, 1 = subdirectory
Sdstartdirclusterd = 0 ' = the directory cluster number (in which the file or subdirectory should be created). Set to 0 for root directory.
Sdyear = ar+2000 'the year
Sdmonth = maned 'the month
Sdday = dag 'the day
Sdhours = timen 'the hours
Sdminutes = minutt 'the minutes
Sdseconds = sekund 'the seconds
Sdcreatemode = 0 ' Create file
Sdstartdirclusterd = 0
Gosub Sdreadfsinfo

Gosub Sdcreatefileordir
if SDstatus<>0 then
Errors(2)=1
ErrorNames(2)="Createfile failed: " + str(sdstatus)
Else
Print "File Created ";Sdentrynames
End if

Else 'File Exists
Print "File Exists ";Sdentrynames
ENd if
Else 'SDInit failed.
Errors(1)=1
ErrorNames(1)="SDInit failed: " + str(sdstatus)
End if
Return


WriteLog:
' INNstr="Hello World"
GoSub Sdpreparetoappend
While Sdclosefile = 0 And x<2000 ' Just a test
Incr x
tmpstr="A"
Sdbyterw =asc(tmpstr)
GoSub Sdwritebyte ' Save a byte to the card
Wend
print "Written ";x; " Bytes"
'Write Nl,Cr
Sdbyterw =13
GoSub Sdwritebyte
Sdbyterw =10
GoSub Sdwritebyte

GoSub Sdfinalizeafterwriting ' After writing the last byte, close the file
GoSub Sdwritefsinfo
if sdstatus<>0 then
errors(3)=1
errornames(3)="Failed to write "+str(sdstatus)
End if


Return

I don't get any errors, but when trying the SD in PC, it will not read the file.

After doing a disk repair, I get:
Windows report. Wrong timeformat on file ... AND The file have not the correct size..
Now I can read the file, and everything looks OK.

I have tried 10 times to reformat (Fat32) with same result.
Running Win7

So still some bugs.. biting me.

Any pesticide left??

Best regards svein

ps. Tried with both buffered and unbuffered writing..
Ah.. And one more thing;
In Your write example is this line;
While Sdclosefile = 0 And Sdtempw2 < 1024 ' 512 times (always make sure that Sdclosefile = 0 before writing)
Sdtempw2 < 1024 and '512 times???
Back to top
View user's profile
KokkeKat

Bascom Member



Joined: 08 May 2011
Posts: 59
Location: Stockholm

sweden.gif
PostPosted: Sun Jan 04, 2015 6:32 pm    Post subject: Reply with quote

Hi Svein,

My first guess is that it's Window's file system caching that's causing problems for you. After you have formatted the card, shut down the PC, take out the card, boot the PC, run your AVR program, and then insert it into the PC.

Verify that Sdentrynames is exactly 11 characters.

If this doesn't solve the problem, I'm afraid I will have to ask you to read the pdf document in the download zip file and the sticky threads in this forum.
Also, compare the example code files to your own code.

Thanks for pointing out the 1024 and 512 discrepancy. This looks like a typo.

Best regards

Niclas
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> KokkeKat FAT-free SD card lib All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum