SDFileSystem.bas ???

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Thu Oct 09, 2008 4:16 pm

Liak,

http://www.ohararp.com/files/SD_GPS_DAT ... T_V314.pdf

Page page has a schematic that works very well.
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Post by liak » Fri Oct 10, 2008 2:39 am

Dear ohararp,
Thanks for the help. Will read your schematics carefully and see if I can adopt it to my settings. Thanks a lot. :)

Regards,
Liak

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Fri Oct 10, 2008 12:47 pm

Liak, FYI this is for a pic running at 3.3V. I suggest using the 18LF2620.
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Post by liak » Sun Oct 12, 2008 3:29 am

Dear ohararp and Steven,
I am having difficulty in adapting it to my PIC18F2525. I need to put voltage dividers in between the pins from PIC to SD. So the arrangement became a bit complicated and confusing for me. How do you think I may add the pull ups into the wavplayer schematic? Can you put any suggestions to make it possible, maybe a rough schematic? (I dont have any 3.3V PIC).
Any help will do. :oops:

Thanks
Regards,
Liak

Bryan
Registered User
Registered User
Posts: 18
Joined: Tue Feb 19, 2008 6:50 am
Location: Nelson, B.C. Canada

SD card schematic

Post by Bryan » Sun Oct 12, 2008 10:07 pm

Hi Liak, there is a schematic of a SD card daughter board on the Micro Electronika site that shows a switchable arrangement for the inputs to the SD card. (the voltage dividers can be switched in when used with a 5.0 V processor) you can find it at: http://www.mikroe.com/pdf/mmc_proto_schematic_v100.pdf

Does anyone know how critical it is to use the voltage dividers when using a 5.0 V processor? I'm working with a board designed around a 5 volt 18f8722 and the designer does not use dividers on the inputs to the SD card - all lines are pulled high with 10K. So far I'm not having any luck talking to the SD card. Is there a chance that the 3.3v electronics in the card plug could be damaged with such an arrangement?

Bryan

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Post by liak » Tue Oct 14, 2008 7:20 am

Dear all,
Thanks Bryan and ohararp. I am still working on the SD. Dead line running near and it's still not working. The card fails to init. Not sure why. It was running well before then, after it failed, it failed until now. And Steven, may I know why the adaptation for SDHC makes the module prone to failure when the pins are not pulled up? Can I get the version without the SDHC adaptation? All the schematics I see on the net does not include pull ups.

:cry:

Liak

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Post by liak » Thu Oct 16, 2008 3:36 am

Dear all,
Finally, done! Finally I managed to sort out the problem. After nearly 3 weeks of fooling around, managed to get working pull up on the I/O pins and the module now is tested okay. Thanks everyone. Time to move on to other tasks.

:lol: Valuable lessons learned.

Regards,
Liak

Bryan
Registered User
Registered User
Posts: 18
Joined: Tue Feb 19, 2008 6:50 am
Location: Nelson, B.C. Canada

Interfacing 3.3v SD card to 5v PIC

Post by Bryan » Thu Oct 16, 2008 4:34 am

Hi Liak, congratulations on your success! Did you end up using the voltage dividers?
I just came across what looks to me like fairly authoritive article on the interfacing of a SD card to a 5 volt PIC processor. Interesting what they say about the DO line from the SD card needing a TTL buffer. This is the first time I've seen anything indicating that!
article from this Link:
http://brushelectronics.com/index.php?page=software
Bryan

How to implement an SD/MMC Card with a PIC Microcontroller

A number of hardware reference designs incorporating SD/MMC Cards are available on our Projects page.
For a 3.3volt PIC system, the minimum interface between an SD/MMC card and the PIC is four I/O lines which include the three SPI bus lines (SCK, SDO and SDI) the fourth line is the chip select. Optionally two additional lines connect to the SD/MMC socket for Card Detect (CD) and Write Protect (WP).
For 5 volt PICs, level translation is required between the 5 volt I/O of the PIC and the 3.3 volt I/O of the SD/MMC Card. Level translation for the PIC SDO, SCK and CS outputs can be implemented with simple resistor voltage dividers.
***Coming from DO of the SD/MMC Card to the SDI input of the PIC is not so straight forward and requires a TTL buffer. This is because the PIC, in SPI mode, has the SDI input configured as a Schmidt trigger input and the guaranteed logic high out of the SD/MMC card is less than the guaranteed logic high level of the PIC. ***

When selecting a PIC for applications that write to a media card there are two main criteria; there is sufficient RAM to support the access method and the PIC supports an SPI bus. SD/MMC Cards must be written in 512 byte blocks. This is also the sector size of the SD/MMC card. So for example, to append a byte to a file, the sector must be read into a buffer, the location modified, and the sector written back to disk. If using a file system, a sector buffer is required for file system management and one 512 byte buffer plus local file variables are required for each open file. This means a PIC with 1500 bytes of memory, such as the PIC18F452, using a file system can realistically have only a single file open at a time. The PIC18F4620, which is pin compatible with the PIC18F452 has 3900 bytes of ram available and therefore can have multiple files open simultaneously.

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Post by liak » Thu Oct 16, 2008 2:25 pm

Dear Bryan,
Thanks for sharing. I use voltage dividers. Seems to me the article is right. It was a nightmare struggling to init the SD card. I only found out by myself after testing it for 2 weeks!
I suspect the SD card failed to initialize because the SDO line is below TTL. I added pull up on the SDO line like Steven suggested. But the SDI (from PIC to SD) is left without and it works.

Regards,
Liak

RDHeiliger
Registered User
Registered User
Posts: 26
Joined: Sun Oct 12, 2008 11:21 pm
Location: Utah

Post by RDHeiliger » Wed Oct 22, 2008 5:23 am

Just starting to play with SD memory. I am using microSD cards. Trying the basic read write program that is in the sample directory.

The init seems to run in a loop, like the processor is restarting the program over and over.

I tried adding 10K pull ups on the SDO and SDI lines and still am stuck in the init loop.

What size pull ups did you use? I am using an 18f24J10, a 3.3v part.

I noticed on one of the other posts schematic that 2.2K pullups are used on all three SPI lines when 3.3v chips are used and 3.3K with 5v chips.

may try 2.2K on all three line spi lines tomorow.

any thoughts

RD

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

Post by Steven » Wed Oct 22, 2008 6:05 am

Hello and welcome to the forum. Could you let me know if you are using the original version of the SD module that ships with the compiler, or the later version from the wiki (http://www.sfcompiler.co.uk/wiki/pmwiki ... temVersion). Could you also post the code you are using.

Thanks,

Steve

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Wed Oct 22, 2008 1:16 pm

I am using 10K pullups without a problem.
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

RDHeiliger
Registered User
Registered User
Posts: 26
Joined: Sun Oct 12, 2008 11:21 pm
Location: Utah

Post by RDHeiliger » Wed Oct 22, 2008 1:19 pm

I received the compiler a week ago. Have been using the version on the disk. After reading some of your previous posts I clicked the "online update". Still having the same problem. Are the "online update" files the same as on wiki? Have not changed the pullups to 2.2K or added the pullup on the CS line yet.

The only code I changed was to ad the Config settings. I found I had to change the default setting of using the internal 32Khz ocilator to get the chip to run at 20MHZ.

Code:

// device and clock...

Device = 18F24J10

Clock = 20

Config

DEBUG = OFF,

XINST = OFF,

STVREN = ON,

WDTEN = ON,

FCMEN = ON,

IESO = OFF,

FOSC2 = ON,

FOSC = HS,

WDTPS = 128

// import SD file system, usart and conversion modules...

#option SD_SPI = MSSP // use hardware SPI

Include "SDFileSystem.bas"

Include "usart.bas"

Include "Convert.bas"

// variables...

Dim Index As Byte

// program start...

SetBaudrate(br19200)

USART.Write("Initialising card...", 13, 10)

If SD.Init(spiOscDiv64) Then


// format SD card...

USART.Write("Formatting, please wait...", 13, 10)

QuickFormat


// write data to SD card...

USART.Write("Writing data, please wait...", 13, 10)

If SD.NewFile("test.txt") = errOK Then

For Index = 0 To 255

SD.Write("Line ",DecToStr(Index,3), 13, 10)

Next

SD.CloseFile

EndIf


// read data back...

USART.Write("Reading data...", 13, 10)

If SD.OpenFile("test.txt") = errOK Then

Repeat

USART.Write(SD.ReadByte())

Until SD.EOF

SD.CloseFile

USART.Write("Finished.", 13, 10)

EndIf

EndIf



RD

User avatar
ohararp
Posts: 194
Joined: Tue Oct 03, 2006 11:29 pm
Location: Dayton, OH USA
Contact:

Post by ohararp » Wed Oct 22, 2008 1:31 pm

RD, for timing purposes you'll need to run some sort of external crystal or resonator. I didn't see a HC or XT config on your setup.
Thanks Ryan
$25 SMT Stencils!!!
www.ohararp.com/Stencils.html

RDHeiliger
Registered User
Registered User
Posts: 26
Joined: Sun Oct 12, 2008 11:21 pm
Location: Utah

Post by RDHeiliger » Wed Oct 22, 2008 1:37 pm

FOC HS - sets the crystal mode
FOC2 ON - selects HS or EC

This is different than most pics i have used, but needed to do it this way to get the UART to run at the slected baud.

RD

Post Reply