SD file system: hardware vs software SPI problem

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Luciano
Posts: 13
Joined: Fri Feb 12, 2010 2:00 pm

SD file system: hardware vs software SPI problem

Post by Luciano » Wed Apr 08, 2015 5:12 pm

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

Jerry Messina
Swordfish Developer
Posts: 1246
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: SD file system: hardware vs software SPI problem

Post by Jerry Messina » Sun Apr 12, 2015 2:07 pm

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

Luciano
Posts: 13
Joined: Fri Feb 12, 2010 2:00 pm

Re: SD file system: hardware vs software SPI problem

Post by Luciano » Mon Apr 20, 2015 10:34 am

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

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: SD file system: hardware vs software SPI problem

Post by Coccoliso » Mon Apr 20, 2015 12:09 pm

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 :

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,

Post Reply