Using SDfilesystem I can Quickformat and create an SD card file, save data in it and then re-open the file and read the data back no problems - if the save and open is in the same program.
But if I recompile exactly the same prog. above (without Quickformat) the SD card initialises OK but SD.OpenFile returns an error.
I want to be able to save a file on the SD card then be able to read it back at any time in the future.
Does any one have any clues .... thanks heaps
Code: Select all
' Here is code to save and recall which works but after
' commenting out quickformat and running again fails
'
' RLABS is the SDcardfile system with its 4 pins remapped
'
'
Device = 18F87J50
Clock = 48
Config FOSC = INTOSCPLL, PLLDIV = 2, CPUDIV = OSC1
#option SD_SPI = SW
Include "RLABS SDFileSystem.bas"
Include "usart2.bas"
Include "Convert.bas"
Dim n As Integer
OSCCON = %01111100
OSCTUNE.6 = 1
USART2.SetBaudrate(br115200)
DelayMS(500) ' allow PIC to stabilize
'
' Report progress of code to dumb terminal on Com2 at 115200
'
USART2.Write(27,"[2J", 27,"[f" ) ' CLS
USART2.Write("Create an SD card file", 13, 10)
'
' Format SD card
'
If SD.Init() Then
USART2.Write("Formatting MicroSD card, please wait...", 13, 10)
QuickFormat
USART2.Write("Format done OK", 13, 10)
Else
USART2.Write("SD Init Error, no formatting", 13, 10)
End If
DelayMS(500)
'
'
' Create 200 byte file
'
'
If SD.NewFile("sample.txt") = errOK Then
For n = 0 To 200
SD.Write(n)
Next
SD.CloseFile
USART2.Write("Successfully created sample.txt", 13, 10)
Else
USART2.Write("Error creating sample.txt file", 13, 10)
End If
'
' Open, print and close the file to prove its there at this moment
'
'
If SD.OpenFile("sample.txt") = errOK Then
Repeat
n = SD.ReadByte()
USART2.Write("Byte from sample.txt ", DecToStr(n), 13, 10)
Until SD.EOF
SD.CloseFile
Else
USART2.Write("Error opening sample.txt", 13, 10)
DelayMS(5000)
EndIf