SDFileSystem

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
E_VH
Posts: 12
Joined: Fri Dec 09, 2011 3:08 pm
Location: Belgium

SDFileSystem

Post by E_VH » Fri Dec 09, 2011 4:54 pm

Hi,
Just purchased/installed the compiler and tried to compile the easiest program possible to acces an SD card ?

Because this was the primary raison I purchased a license.

But it didn't work on the pic 18F452 ?

Reading all about the module on the forum didn't help me.


Receive Error Code "A" = erroroNoResponce
SD-Card power = 3.3 volt

Included program + schema.


Hoop someone can help me out.

[code]Device = 18F452
Clock = 20

Config OSC = HS, OSCS=ON, PWRT=ON, WDT=OFF, LVP=OFF

'---LCD module options
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3

#option SD_SPI = MSSP
#option SD_SUPPORT_SUB_DIRECTORIES = True
#option SD_SPI_SPEED = spiOscDiv16
#OPTION SD_CS = PORTC.2
#OPTION SD_DI = PORTC.5
#OPTION SD_CLK = PORTC.3
#OPTION SD_DO = PORTC.4

' #option WDT = true 'don't know this needed

Include "LCD.bas"
Include "Convert.bas"
Include "utils.bas"
Include "SDFileSystem.bas"


Dim Err As Byte

// refresh speed...

Const UpdateMS = 50

SetAllDigital

LCD.Cls
LCD.Write("Start Init")
LCD.MoveCursor(2,2)

DelayMS(100)

Repeat
Err = SD.Init()
LCD.Write(HexToStr(Err))
Until Err = errOK

LCD.WriteAt (4,2, "Init OK")


End
[/code]
[img]J:\PICprogrammas\SwordFish\Test\T1\Pic18F452_MMC-SD.jpg[/img]

Don't know how to post images ?

PIC RC2 => SD1 / RC5 => SD2 / RC3 => SD5 via (3K3 - 2K2 divider)

PIC RC4 => SD7 straight


Thanks

Erik

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Fri Dec 09, 2011 7:01 pm

Hi E_VH,

First of all, welcome to the forum.

Can I confirm that you are using the latest version of the SD File System (http://www.sfcompiler.co.uk/wiki/pmwiki ... temVersion).

Also, have you got a pull-up on RC4 - there is a circuit diagram at http://www.sfcompiler.co.uk/wiki/pmwiki ... CWavPlayer that might help.

Steve

E_VH
Posts: 12
Joined: Fri Dec 09, 2011 3:08 pm
Location: Belgium

SDFileSystem

Post by E_VH » Sat Dec 10, 2011 9:15 am

Hi Steve

Thanks for your quick reply.

Yes I think i am using the latest version off the module 4.1.4

No there is no pull-up on RC4 ? I go try this.

But why the pull-up must go to +5V and not to the +3V3 ?

The SD-Card works with 3V3 ?

And RC4 => SD7 = Data out ?

Supplementary I have read that normaly there must be RAM memory reserved (512K / open file), is the module taking care of that ?

Kind regards for helping me out.

Erik

E_VH
Posts: 12
Joined: Fri Dec 09, 2011 3:08 pm
Location: Belgium

SDFileSystem

Post by E_VH » Sat Dec 10, 2011 10:35 am

Hi Steve

Tested with 10K pull-up to 3V3 => RC4 and everything works fine even without the #options.

I have seen schemas with a diode between de 5V and the SD7?
Searching the internet why is RC4 => SD7 is always staight ???

Like everythink in PIC's its the tiny bits and bold that make it so difficult to master.

Is there an easy way to display the different option to use and when to use them ?

For example "#option SD_SPI_SPEED = spiOscDiv16 " is the module selecting the max-speed possible ?

In any case a great big thank you.

Erik

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Sat Dec 10, 2011 10:59 am

The lastest version of SF comes with version 4.1.4 of the SDFileSystem.bas Module, so yes thats the latest version you have. :)

If you dont set the #option or for example "#option SD_SPI_SPEED = spiOscDiv16 " in your main code, then the Module (SDFileSystem.bas) will take care of that for you by setting the default #option values and yes this will set for example "#option SD_SPI_SPEED" to the max speed.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Sat Dec 10, 2011 11:03 am

It's good to hear that it is now working. Without the pull-up, the PIC input is floating, prior to card insertion, causing false returns.

Also, the SD card output is 3.3V, but this is usually sufficient to register as a high on the PIC input, so you can get away without level-shifters to 5V.

E_VH
Posts: 12
Joined: Fri Dec 09, 2011 3:08 pm
Location: Belgium

SDFileSystem

Post by E_VH » Sat Dec 10, 2011 1:50 pm

I think that what I have done is a bit risky.

Putting the pull-up on the 3V3 side.

When RC4 is high = 5v, than this 5v becomes available on the 3v3 side and may damage and corrupt the 3v3.

But putting a reverse diode between the 5v and the pull-up to 3v3 corrects this, when the RC4 go low this diode conducts to pull SD7 => low.

RC4 -> diode (-|>-) -> 10k -> 3v3
"----------------------" |_-> SD7

Or do you think 5v is not a problem for SD7 ?

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

Post by Jerry Messina » Sat Dec 10, 2011 2:49 pm

I'm not sure I follow what you've done here.

SD pin 7 is the DataOut of the SD card. It should have a pullup so that when the card is not selected the line doesn't float. According to the SDcard spec, you should not connect 5V to ANY of the SDcard pins, so the pullup should go to 3V3. A pullup to 5V isn't a good idea.

Unfortunately, RC4 is a ST input, and has a Vih spec of 3.5V (min input high) if you're using 5V. The SDcard has a Voh of 2.47V (min output high) , so technically the SDcard can't drive the RC4 pin high enough to meet spec and be recognized as a logic high by the PIC.

If you pull the pin up to 3V3 will it work? Possibly. I've seen a lot of latitude in the PIC pin specs, but the correct way to do this is to add a 3V3 -> 5V level shifter on the SD DO pin. A 74HCT gate @ 5V will work, as will many others.

As Steven says, you can "probably" just pull the pin up to 3V3 and get away with it (but you didn't hear that from me).

Post Reply