Hi,
the following example code works well with the SW version but not with the MSSP. I am using microSD card, 3.3V for the all circuit and 10k pull-up resistors on DO, DI, SCLK.
could you please suggest any reason?
many thanks
Luciano
----------
Device = 18F4525
Clock = 20
#option SD_SPI_SPEED = spiOscDiv64
#option SD_SPI = MSSP 'uncomment for hardware SPI/MSSP version
' #option SD_SPI = SW 'uncomment for software SPI/SW version
Include "SDFileSystem.bas"
Include "Convert.bas"
// variables...
Dim Index As Byte
Dim testbolean As Boolean
'----------------------------
DelayMS (500)
// init SD card...
testbolean = SD.Init (spiOscDiv64) 'uncomment for MSSP version
'testbolean = SD.Init 'uncomment for SW version
// format SD card...
testbolean = SD.QuickFormat()
// write data to SD card...
If SD.NewFile("test3.txt") = errOK Then
For Index = 0 To 255
SD.Write("Line ",DecToStr(Index,3), 13, 10)
Next
SD.CloseFile
EndIf
End
SD file system: hardware vs software SPI problem
Moderators: David Barker, Jerry Messina
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: SD file system: hardware vs software SPI problem
From your code it looks like you're using the original SD library. You might have better luck with the updated version from the wiki found here: SDFileSystem V4.1.4
I've run that one using the hardware MSSP up to 16MHz
I've run that one using the hardware MSSP up to 16MHz
Re: SD file system: hardware vs software SPI problem
thank you for the suggestion.
I did what you suggested and now works both with SW and MSSP.
...rather oddly, now I must init with a byte and not with a boolean, as suggested. maybe(?) there was somehow a mismatch in my previous setting of swordfish and somehow now is fixed.
many thans for the help!
Luciano
I did what you suggested and now works both with SW and MSSP.
...rather oddly, now I must init with a byte and not with a boolean, as suggested. maybe(?) there was somehow a mismatch in my previous setting of swordfish and somehow now is fixed.
many thans for the help!
Luciano
Re: SD file system: hardware vs software SPI problem
Luciano,
as Steven Wright wrote:
"Note that the Init command for initialising the card has been changed slightly since Version 3.1.1 and this will necesitate a change to existing user code. The command now returns a byte, not a boolean. The return variable gives more information in case of a failure (see err codes in comments above command in module for details). Note also that when using the hardware MSSP SPI option using #option SD_SPI = MSSP, the SPI bus speed is no longer passed to the Init command as a parameter, but is set using an option, e.g. #option SD_SPI_SPEED = spiOscDiv4. As for all options, this must be placed before the Include "SDFileSystem.bas" statement in the user code."
.. so test if returned value is $00 that would mean errOK for all done and OK
If returned value is <>$00 then test error code between :
as Steven Wright wrote:
"Note that the Init command for initialising the card has been changed slightly since Version 3.1.1 and this will necesitate a change to existing user code. The command now returns a byte, not a boolean. The return variable gives more information in case of a failure (see err codes in comments above command in module for details). Note also that when using the hardware MSSP SPI option using #option SD_SPI = MSSP, the SPI bus speed is no longer passed to the Init command as a parameter, but is set using an option, e.g. #option SD_SPI_SPEED = spiOscDiv4. As for all options, this must be placed before the Include "SDFileSystem.bas" statement in the user code."
.. so test if returned value is $00 that would mean errOK for all done and OK
If returned value is <>$00 then test error code between :
Code: Select all
errDiskFull = $01,
errNotFound = $02,
errRootDirFull = $03,
errDirNotEmpty = $04,
errExists = $05,
errInUse = $06,
errRWError = $07,
errFileNotOpen = $08,
errBeyondEOF = $09,
errNoResponse = $0A,
errInvalidFormat = $0B,
errInvalidPath = $0C,