View previous topic :: View next topic |
Author |
Message |
starfire151
Joined: 01 Apr 2007 Posts: 195
|
correct SD/MMC connections for SPI Mode |
Posted: Sun Jan 13, 2008 10:44 pm |
|
|
Sorry if this appears to be a bit off-subject but it does relate to the software interface for the PIC...
I'm trying to run a PIC18LF2620 at 20MHz and 3.3VDC with a SD/MMC card interface to run a FAT file system. Since the SD interface is 3.3VDC, is it OK to just connect the SPI bus (plus a CS line, a CD line, and a WP line) to the PIC without any level translators?
My connections are:
PIC <---------> SD card socket
16 (SDO) ----> 2
15 (SDI) <----- 7
14 (SCLK) ---> 5
11 (CS) ------> 1
23 (CD) <-----10
6 (WP) <------ 11
The last two are specific to my socket. I know I need pullups on the socket pins 8 and 9 but do I need pullups or pulldowns on any other pins?
Is there any other "gotchas" for this type of interface? |
|
|
crystal_lattice
Joined: 13 Jun 2006 Posts: 164
|
pullups |
Posted: Sun Jan 13, 2008 11:56 pm |
|
|
Hi i'm busy with a similar project, read the data sheets on the sandisk cards they will tell you which pins need pullups. i don't have the datasheet or my PCB on me so i can't check right now but will check later tonight.
Kind Regards |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 14, 2008 12:49 pm |
|
|
Don't forget to connect the power and ground pins: Code: | PIC <---------> SD card socket
gnd --- 3 Vss1 Supply voltage ground
+V --- 4 Vdd Supply voltage
gnd --- 6 Vss2 Supply voltage ground |
The CMD and DATx lines should each have a pull-up resistor of 10k - 100k, i.e. SD connector pins 1,2,7,8 and 9.
When used the Write Protect switch should have a pull up as well.
Quote: | Is there any other "gotchas" for this type of interface? | Of course there are gotchas. Here are some:The full specifications of the SD cards are only available to paying members of the SD Card Association. This has caused many open source projects to generate drivers that have compatibility problems.
The new High Capacity cards (SDHC) of 4GB and more have compatibility issues with some older drivers. Workaround: use cards <= 2GB.
MicroSD cards are not required to support the SPI communications mode, so some of these cards won't work in combination with the PIC. |
|
|
Imanjl
Joined: 15 Nov 2004 Posts: 42
|
|
Posted: Mon Jan 14, 2008 1:46 pm |
|
|
Still there is some cards (MMC) mostly that can work fine without pullup but there is no guarantee for all brands .
I suggest to use pullup resistors for any compatibility problems .
Here is a schematic from one of Texas instrument App note :
|
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Mon Jan 14, 2008 4:49 pm |
|
|
Thanks, all, for the input!
I noticed no one mentioned the need for a pullup on the clock line, though... Is this intentional? Will the clock line respond better (more consistently) without a pullup?
I have seen some schematic layouts which actually have a pulldown on this pin (around 47K).
Are there any problems with running the PIC at 20MHz and 3.3VDC? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Mon Jan 14, 2008 5:21 pm |
|
|
starfire151 wrote: | Are there any problems with running the PIC at 20MHz and 3.3VDC? |
Check the datasheet for that PIC. I don't think that many PICs will run that fast @ 3.3V. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 14, 2008 7:57 pm |
|
|
Check the datasheet figure 26-3 for the maximum clock frequency as a function of voltage. At 3.3V the PIC18LF2620 is specified for a maximum clock frequency of:
Code: | Fmax = 16.36 MHz/V * (3,3V - 2V) + 4MHz = 25.3MHz |
Make sure you are using the 'LF' version, the 'F' version requires a minimum of 4.2V.
Pull-up or pull-down resistors for the clock line are not specified in the SD Card standard. A 47k resistor would minimal effect on the clock signal. Most likely it was added in the schematic you saw to get a defined power-up level, for example because the processor starts up with all pins defined as inputs. As long as you place the required pull-up on the Chip Select pin of the SD card there is no need to waste power by adding a resistor on the clock line. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Tue Jan 15, 2008 8:20 am |
|
|
Excellent answer, ckielstra...
I saw that chart in the data sheet and also came up with about 25MHz as the max freq for 3.3VDC operation. I just wanted a "sanity check". The component is, indeed, the LF flavor so it should run fine at 20MHz.
I also could not find anything related to a pullup or pulldown on the clock line in the Sandisk summary spec but I did find a reference indicating the line should be pulled down (through about a 50K resistor) if the clock is undefined at start up to ensure the clock line is at normal low.
My real problem is that I'm using the Brush Electronics FAT file system library and have been having problems with files not closing (0-length) or being corrupted (not readable on the PC). I've built a small testbed with only the 20MHz oscillator, the PIC18LF2620, and the SD card socket with a program that just writes files every 3 seconds to the card. If I let the program run for about an hour, I get various results depending on the specific SD card I'm using. I have a new 1GB Sandisk card that does not fail. I have a brand new Lexar 1GB card that has about a half-dozen corrupted files. These have all been formatted with FAT16 as FAT32 on the Lexar card fails most of the time.
Any thoughts or pointers to try?
Are there other FAT file systems written for CCS C and the PIC that I could try?
Thanks, much, for your responses. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jan 15, 2008 8:52 am |
|
|
starfire151 wrote: | My real problem is that I'm using the Brush Electronics FAT file system library and have been having problems with files not closing (0-length) or being corrupted (not readable on the PC). | Have you asked the creator of this library if this is a known problem? Maybe there is an update available?
Quote: | I get various results depending on the specific SD card I'm using. I have a new 1GB Sandisk card that does not fail. I have a brand new Lexar 1GB card that has about a half-dozen corrupted files. | Sandisk is one of the inventors of the SD card. Most libraries are tested against this brand. Other manufacturers might have small differences that are within specifications but cause trouble on certain libraries. I'm not saying Lexar is bad but it is just not as well tested by third party vendors.
Quote: | Are there other FAT file systems written for CCS C and the PIC that I could try? | Of course you have checked the CCS driver? See ex_fat.c in the examples directory for an example.
Take note of the remark in fat.c Code: | NOTE: This may be a little buggy. |
The Code Library section of this forum contains one FAT16 and two FAT32 libraries. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Tue Jan 15, 2008 7:44 pm |
|
|
Quote: |
Have you asked the creator of this library if this is a known problem? Maybe there is an update available?
|
I have, indeed, talked to the author of the library. He was very helpful at first. I did get an update to the library but it did not solve this particular problem. I believe I'm getting to the point where he doesn't want to waste nay more time on me though because the last e-mail simply stated "it must be a hardware problem". I never did get a straight answer to the question of how a file could get created successfully (no error code) and yet have 0-length.
Quote: |
Of course you have checked the CCS driver? See ex_fat.c in the examples directory for an example.
Take note of the remark in fat.c Code:
NOTE: This may be a little buggy.
|
Unfortunately my compiler version is 3.249 and I believe the ex_fat.c example is provided in version 4.x. ... at least I could not find it in my examples directory. Does that need version 4.x to run?
Quote: |
The Code Library section of this forum contains one FAT16 and two FAT32 libraries.
|
I would ideally like to get this library working as described but I have downloaded the FAT16 library from the forum. I noticed a couple of bug reports/fixes after the original posting. Is there an up-to-date version with all known bugs fixed somewhere?
Thanks. |
|
|
|