Message Boards
Threads [ Previous | Next ]
SD card interface
SD card interface Vijay 8/6/08 11:54 AM
RE: SD card interface ganzziani 8/6/08 1:22 PM
RE: SD card interface bmorse 8/6/08 1:42 PM
RE: SD card interface boseji 8/6/08 8:14 PM
RE: SD card interface bmorse 8/7/08 12:23 AM
RE: SD card interface Vijay 8/7/08 9:27 AM
RE: SD card interface boseji 8/7/08 11:17 AM
RE: SD card interface bmorse 8/7/08 2:06 PM
RE: SD card interface boseji 8/15/08 2:54 AM
RE: SD card interface jamodio 8/15/08 2:02 PM
RE: SD card interface boseji 8/15/08 4:06 PM
RE: SD card interface mimemike 8/15/08 11:22 PM
RE: SD card interface boseji 8/16/08 12:34 AM
RE: SD card interface g921002 8/16/08 3:08 PM
RE: SD card interface boseji 8/16/08 3:49 PM
RE: SD card interface bmorse 8/17/08 2:28 PM
RE: SD card interface boseji 8/17/08 2:42 PM
RE: SD card interface Vijay 8/31/08 5:26 AM
RE: SD card interface saipan59 8/31/08 7:30 PM
RE: SD card interface mimemike 9/1/08 5:55 AM
RE: SD card interface boseji 9/1/08 1:37 PM
RE: SD card interface Vijay 9/2/08 3:08 AM
RE: SD card interface mimemike 9/2/08 6:22 AM
RE: SD card interface boseji 9/2/08 2:28 PM
RE: SD card interface bitcoder 10/11/08 7:38 PM
RE: SD card interface bwike 12/9/08 2:51 AM
RE: SD card interface mimemike 12/9/08 3:03 AM
RE: SD card interface saipan59 12/9/08 4:28 AM
RE: SD card interface saipan59 12/9/08 4:36 AM
RE: SD card interface bmorse 12/9/08 4:40 PM
RE: SD card interface bmorse 12/9/08 5:08 PM
RE: SD card interface bwike 12/9/08 6:40 PM
RE: SD card interface saipan59 12/9/08 6:43 PM
RE: SD card interface bmorse 12/10/08 1:52 PM
RE: SD card interface ericm 2/4/10 2:44 AM
RE: SD card interface boseji 4/8/10 8:42 AM
RE: SD card interface matheuz 7/22/10 8:56 PM
RE: SD card interface boseji 8/25/10 12:48 PM
RE: SD card interface Graham Martin 10/9/08 9:55 AM
RE: SD card interface mimemike 10/9/08 3:28 PM
SD card interface
8/6/08 11:54 AM
does anybody have info for SD card interface with PIC32 starter kit
RE: SD card interface
8/6/08 1:22 PM as a reply to Vijay .
An internet search will provide lots of examples. Here is one in particular for a dsPIC:

http://www.k9spud.com/sdcard/
RE: SD card interface
8/6/08 1:42 PM as a reply to Vijay .
What mode do you want to connect to SD card with?? SPI or standard SD Interface??
RE: SD card interface
8/6/08 8:14 PM as a reply to bmorse .
Hi,

I too require some help regarding the MicroSD interfacing.

Please let me know.

Thanks,
RE: SD card interface
8/7/08 12:23 AM as a reply to Vijay .
here is a circuit i used to interface to a different pic, I'm sure you can figure out which pins you are connecting them to on the Pic Starter kit...



Hopefully this helps you guys out, Lucios book covers this too....
RE: SD card interface
8/7/08 9:27 AM as a reply to bmorse .
The schematic looks easy, is it a special SD card or do all SD card support SPI, i need to interface it to SPI only,

Another doubt, there are many versions of SD card like the standard, mini and micro, i want to use the microSD card 128MB,that are used in mobile phones, does it connect in the same fashion
RE: SD card interface
8/7/08 11:17 AM as a reply to Vijay .
Hi,

I have made a breakout of the MicroSD card.
But I was never able to interface it. Since its comm algo is different from the normal SD or so.
Well I would post my PCB and schematics today.

Best of Luck,
RE: SD card interface
8/7/08 2:06 PM as a reply to Vijay .
Vijay:
The schematic looks easy, is it a special SD card or do all SD card support SPI, i need to interface it to SPI only,

Another doubt, there are many versions of SD card like the standard, mini and micro, i want to use the microSD card 128MB,that are used in mobile phones, does it connect in the same fashion
]

Here are the different card pinouts and pad assignments:







hope this resolves any confusion with the different card formats.... you will have to consult the card manufacturers datasheets for the commands and other communication protocols.
RE: SD card interface
8/15/08 2:54 AM as a reply to bmorse .
Hello,

I am having trouble Interfacing the microSD Card using the PIC-MMD library.
Here are my Connection:
 1
 2microSD                     PIC32MX
 3  Card                      Connection
 4    CD           ==>          Not Connected
 5    CS           ==>          RD14
 6    DI            ==>          SDO1/RF8
 7  VDD           ==>         +3.3V
 8  SCLK          ==>         SCK1/INT0/RF6
 9  GND           ==>          GND
10  DO             ==>         SDI1/RF7
11  WP             ==>         Not Available


For the same I modified the Init code:
HardwareProfile.h
 1    #elif defined (USE_PIC32) //*******  32-bit  *******
 2        #define SD_CS                PORTDbits.RD14//PORTBbits.RB1
 3        #define SD_CS_TRIS            TRISDbits.TRISD14//TRISBbits.TRISB1
 4       
 5        #define SD_CD                PORTFbits.RF0
 6        #define SD_CD_TRIS            TRISFbits.TRISF0
 7       
 8        #define SD_WE                PORTFbits.RF1
 9        #define SD_WE_TRIS            TRISFbits.TRISF1


Also for the Main File since I didn't have the WP,CD etc.
Demostration.c
 1#elif defined (__PIC32MX__)
 2   // Turn on the interrupts
 3   INTEnableSystemMultiVectoredInt();
 4   SYSTEMConfigPerformance(GetSystemClock());
 5   mOSCSetPBDIV(OSC_PB_DIV_1);
 6   
 7   //Initialize the RTCC
 8  // RtccInit();
 9  // while(RtccGetClkStat()!=RTCC_CLK_ON);// wait for the SOSC to be actually running and RTCC to have its clock source
10                                        // could wait here at most 32ms
11  // RtccOpen(0x10073000, 0x07011602, 0);
12#endif
13
14  // while (!MDD_MediaDetect());
15
16   // Initialize the library
17   while (!FSInit());
18 


Please help me out with this.

Thanks,

Boseji
RE: SD card interface
8/15/08 2:02 PM as a reply to bmorse .
Being the PIC32 a 3.3V part you don't need the resistors for voltage division, if
you have Lucio's book check page 406, for the SPI mode besides pull-ups (10K)
on the Card Detect and Write Detect switches and CS, you only need a pull-up
on the card SDO pin.

My .02
RE: SD card interface
8/15/08 4:06 PM as a reply to jamodio .
Hello,

I have pulled up all the lines except and SCK pin. As per the SD card data sheet it is required.
I am using microSD so there is no sperate CD pin. I am not sure how to render this requirement.

Please let me know on this,

Boseji
RE: SD card interface
8/15/08 11:22 PM as a reply to boseji .
With MicroSD cards it is assumed that the card is alway inserted since they were primarily designed for devices such as cell phones.

When I initially ran the BSD stack on the PIC32 using the KPIC-P32S1 break out board which has a MicroSD card slot, I just #defined the pin name to be the inserted state (Believe it was #define CD 0 ). I am not 100% sure as the code is at home and I am currently on the road.


EDIT:

Replace the following.....

1#define SD_CD                PORTFbits.RF0 6       
2#define SD_CD_TRIS            TRISFbits.TRISF0


With......

1#define SD_CD           0 

And remove the SD_CD_TRIS=1 from the setup routine.


(Might have polariy wrong - but by memory a logic 0 indicates inserted.)


Mike
RE: SD card interface
8/16/08 12:34 AM as a reply to mimemike .
Hello,

Thanks a lot for your help.
I did as you asked and what it Worked!!

Here is what I modified in the HardwareProfile.h
 1
 2    #elif defined (USE_PIC32) //*******  32-bit  *******
 3        #define SD_CS                PORTDbits.RD14//PORTBbits.RB1
 4        #define SD_CS_TRIS            TRISDbits.TRISD14//TRISBbits.TRISB1
 5       
 6        #define SD_CD                0//PORTFbits.RF0
 7        #define SD_CD_TRIS            TRISFbits.TRISF0
 8       
 9        #define SD_WE                0//PORTFbits.RF1
10        #define SD_WE_TRIS            TRISFbits.TRISF1


Also I disabled the RTCC since I dont have a crystal on my board but hope to put one.

I will put up the stripped version of this driver so that its beneficial for all the other folks who want to use MicroSD without the hassles.

Thanks again for your generous help,

Boseji
RE: SD card interface
8/16/08 3:08 PM as a reply to bmorse .
bmorse:
here is a circuit i used to interface to a different pic, I'm sure you can figure out which pins you are connecting them to on the Pic Starter kit...

Hopefully this helps you guys out, Lucios book covers this too....
]


I have tried this circuit before, it just fit MMC card. There were some unknown problems for SD device.
At latest I bought the SD card board (AC164122).
RE: SD card interface
8/16/08 3:49 PM as a reply to g921002 .
Hello,

I have streamlined the code from MCHP and made it possible to be configured for SD card only.
You can have a look at my Project's Code Section.

Best of Luck,

Boseji
RE: SD card interface
8/17/08 2:28 PM as a reply to g921002 .
g921002:


I have tried this circuit before, it just fit MMC card. There were some unknown problems for SD device.
At latest I bought the SD card board (AC164122).
]

That circuit only works with the MMC type card, thats why it is labeled as such. I provided the other pinouts so that way you could configure your circuit depending on what type of card you are using.
RE: SD card interface
8/17/08 2:42 PM as a reply to bmorse .
Hello,

I have made the connection to a MicroSD breakout that I had built.
Here is the Circuit
 1
 2microSD                     PIC32MX
 3 Card                       Connection
 4 CD           ==>          Not Connected
 5 CS           ==>          RD14
 6 DI           ==>          SDO1/RF8
 7 VDD          ==>          +3.3V
 8 SCLK         ==>          SCK1/INT0/RF6
 9 GND          ==>          GND
10 DO           ==>          SDI1/RF7
11 WP           ==>          Not Available

Here is the Breakout Picture:



Also there is a modification required in the HardwareProfile.h file.
 1
 2     #elif defined (USE_PIC32) //*******  32-bit  *******
 3         #define SD_CS                PORTDbits.RD14//PORTBbits.RB1
 4         #define SD_CS_TRIS            TRISDbits.TRISD14//TRISBbits.TRISB1
 5       
 6         #define SD_CD                0//PORTFbits.RF0
 7         #define SD_CD_TRIS            TRISFbits.TRISF0
 8       
 9         #define SD_WE                0//PORTFbits.RF1
10         #define SD_WE_TRIS            TRISFbits.TRISF1


And it should work fine with the demo app included by Microchip.
Let me know in case any one requires the Gerber/PCB.

Best of Luck,

Boseji
RE: SD card interface
8/31/08 5:26 AM as a reply to boseji .
To create an array in C code inside the SD Card are functions and data structures readily available for pic32??
RE: SD card interface
8/31/08 7:30 PM as a reply to Vijay .
I'm not sure what you're really asking, but if I'm guessing right, the answer is:

There are functions for doing file I/O to the SD card, such as creating files and directories, writing files, appending files, reading files, etc. So you can store any data you want, and you decide what format to write the data (list, array, text, etc.).
You can also store data in raw blocks, instead of using a file structure.

Pete
RE: SD card interface
9/1/08 5:55 AM as a reply to saipan59 .
A good example of this is the FAT32 file system that MCP provides (Using it in my project)

Uses the equivalent to fopen(....) fclose(...) fread(...) fwrite(...) I even thing there might be a fprintf(....)

The only difference is that the names a prefixed with FS e.g. FSfopen() FSfwrite().

If you can read and write files in 'C' on a PC it is exactly the same on the PIC32 with Microchips FAT16/32 Libraries and a SD card (or even USB memory stick).


Feel free to download my source code and look in gui.c for example code in function called "show_file"

Note: the Graphics and FAT/SD Card libraries need to be installed in the default places for it to compile.

Mike
RE: SD card interface
9/1/08 1:37 PM as a reply to mimemike .
Hi,

I have used the MCHP SD lib for my purpose. Its quite friendly and now I am able to stream ADC data directly to a file and also append it. Using the same lib.
Hope that it may help you too.

Best of Luck,

Boseji
RE: SD card interface
9/2/08 3:08 AM as a reply to boseji .
I think i need to rephrase my question

For ex: i create an array

data int image[640][480];

in C32 or in general any microcontroller compiler the default place of storing the array will be the internal ram for which address space is internally available. This array cannot be obviously created in pic32 internal ram. I dont want the higher level file system type of access. Is there an option available with any header file as follows

xyz int image[640][480];

where the xyz(data location specifier) will along with data read/write function set be available in any header file

for example

a= image[k][j];
image[k][j+1]= (image[k][j+1]+a)/2;

the xxyyzz.h file should have read and write functions

If it is not available, i need to start understanding the file systems
RE: SD card interface
9/2/08 6:22 AM as a reply to Vijay .
You are correct in that you would not be able to use internal memory for that type of manipulation

640 x 480 x 2bytes (Presuming 16 bit INT - on PIC32 it may be 32 bit int - have not checked yet)
= 614400 /1024 = 600KBytes


options I see at this stage...

1. Add static RAM using the parallel master port and write functions to read/write data as the arrays you need.
Not really an option if you need >128Kbyte as it only has 16Bit address + 16Bit Data interface.... but can be expanded by using external Logic.

2. Use file manupulation techniques (i.e. fopen/fwrite etc) - slower but can easily acheive what you want, and can be experimented with on a normal PC first.
Warning: I dont think the Microchip FAT stacks have error detection and the ability to lock out faulty blocks (correct me if I am wrong) as this is essential if using FLASH type cards (SD/Compact flash etc). This is slower than option 1

3. Attach NAND FLASH type memory - looks like an IDE hard drive.... same issues as #2, but can use the Parallel master port and should be faster than SPI interface.... come in many sizes... got given an 8GB one as part of a buisness card from a supplier.... BGA package though!


Mike
RE: SD card interface
9/2/08 2:28 PM as a reply to mimemike .
Hello,

You are right about that. It would be quite difficult to use the SD for that purpose. Moreover it would be too slow for data fetch and write. Only a parallel NAND flash can suffice for it.

Best of Luck,

Boseji
RE: SD card interface
10/9/08 9:55 AM as a reply to Vijay .
I am very intererested in using an SD card in some of my own projects.

Does one have to keep a record of where the last data was stored as one has to do with using a 24LCxx memory chip ?

If the answer to this is yes surely it is an enormous job to keep track of where the data is ....
RE: SD card interface
10/9/08 3:28 PM as a reply to Graham Martin .
Microchip has written a FAT16/32 file system for the SD card and USB Stick.

You treat it like a normal filesystem on a PC... i.e. use functions like

FSfopen("filename.dat","R"); // same as fopen but just add FS in front

also fseek, fread, fwrite and more are avaliable.

Mike
RE: SD card interface
10/11/08 7:38 PM as a reply to mimemike .
SD, CF memory cards, and USB drives have error detection and correction built into their memory controller. They also handle block management and wear leveling themselves.
RE: SD card interface
12/9/08 2:51 AM as a reply to bitcoder .
Guys...

This thread makes it look easy. BUT I can not get it to work... I have spent a week on this and bought the SD card interface from digikey and can not get it to work either. I have tried multiple sample/demo codes as well as bmorse's source of SDCOMM demo and nothing works. I have tried SPI1 and SPI2. I bought the SD card interface from digikey that plugs into the starter kit expansion board to get working first before I built custom hardware.

I have traced the error into the SD library into the MediaInitialize routine in the FS_init call. It powers down the card after no response. I have tried four different SD cards thinking card or card format my have been the problem (at least one was on the recomended list). I am thinking it is a hw issue at this point (even though I am using Microchip HW). This should be easy to do and I am sure that the problem is somewhere between my keyboard and chair. But I am running out of ideas and places to look....

I reformatted an SD card with one file but I am never able to get past FSinit().

thanks for help in advance...

yl5295
RE: SD card interface
12/9/08 3:03 AM as a reply to bwike .
Can you tell us the EXACT configuration that you have.

1. Development boards you are using
2. If your own custom board - post a schematic etc
3. Compiler and stack versions


I have used microSD cards with the PIC32 in several designs over the past year without any issue... just changing the stack to think a card is actually inserted because there is no Card Detect on the uSD card sockets I used.

Mike
RE: SD card interface
12/9/08 4:28 AM as a reply to bwike .
I'm using the PIC32 starter bd, the expansion bd, and the SD/MMC PICtail. I run the PICtail in the 'upper' half of the slot (I forget which SPI port that is).

When I was getting it to work, my main problem was with the SPI data rate.
As I recall, the default setup in SD-SPI.c was too fast. So then I slowed it WAY down, and found that the card won't talk if it's super-slow, either.

I currently have this. I *think* this is changed from the default (but I don't have an unmodified copy handy):

//Media powers up in the open-drain mode and cannot handle a clock faster
//than 400kHz. Initialize SPI port to slower than 400kHz
#if defined __C30__ || defined __C32__
#ifdef __PIC32MX__
SPIBRG = SPICalutateBRG(GetPeripheralClock(), 200000);
//SPIBRG = 0x007F;
SPICON1bits.MSTEN = 1;
OpenSPIM (MASTER_ENABLE_ON);

I don't use either Write Protect or Card Detect - I assume that a card is always there and writeable.

Do you have an o-scope to verify the basic signals and the data rate? That's how I discovered that the SPI rate was much different than I expected (and I verified that the CLK and MOSI signals were wiggling as they should).

Pete
RE: SD card interface
12/9/08 4:36 AM as a reply to saipan59 .
Other speed-related settings I'm using:

#define GetSystemClock() (72000000ul) // 8 MHz/2 x 18 PLL = 72 Mhz
#define GetPeripheralClock() (GetSystemClock()/(1<<OSCCONbits.PBDIV))
#define GetInstructionClock() (GetSystemClock())

Pete
RE: SD card interface
12/9/08 4:40 PM as a reply to bwike .
bwike:
Guys...

This thread makes it look easy. BUT I can not get it to work... I have spent a week on this and bought the SD card interface from digikey and can not get it to work either. I have tried multiple sample/demo codes as well as bmorse's source of SDCOMM demo and nothing works. I have tried SPI1 and SPI2. I bought the SD card interface from digikey that plugs into the starter kit expansion board to get working first before I built custom hardware.

I have traced the error into the SD library into the MediaInitialize routine in the FS_init call. It powers down the card after no response. I have tried four different SD cards thinking card or card format my have been the problem (at least one was on the recomended list). I am thinking it is a hw issue at this point (even though I am using Microchip HW). This should be easy to do and I am sure that the problem is somewhere between my keyboard and chair. But I am running out of ideas and places to look....

I reformatted an SD card with one file but I am never able to get past FSinit().

thanks for help in advance...

yl5295
]

There was an actual coding problem with the SD_SPI files there was four lines hard coded to SPI 1 I had changed those 4 lines and got my SD card to work since I am using SPI2, but my socket has the write protect and the card detect input so I am using all the I/O's required, I dont know if that would make any difference in what you have coded or hooked up... I believe I have updated my code on here to reflect my changes, if not I will update it tonight when I get home from work....... I also found out by reading Lucio's book that you have to start off at a low speed when initializing the card for sd mode, afterwards you can increase the speed....
RE: SD card interface
12/9/08 5:08 PM as a reply to bmorse .
I had just checked the code I have on here and it is the updated one where I fixed it to work on SPI2.

Make sure you double check your actual pin connections to the ones in the HardwareProfile.h to make sure they match......
I attached the files needed to test your sd card interface with....
Attachments: Tempcode.zip (93.0k)
RE: SD card interface
12/9/08 6:40 PM as a reply to bmorse .
Thanks for the help guys.... I got it working. Changing the pin defs to match the hardware then bmorse's demo code worked. Then changing the SPI clock (brg reg) to yield a 400khz rather than the default 9Mhz then the microchip code worked.
RE: SD card interface
12/9/08 6:43 PM as a reply to bmorse .
Another hint related to pin hookups:
As I recall, the names of the SI and SO signals on the SD card are *with respect to the Master, not the SD card*. So "SO" is the data *input* to the card. On my first SD card implementation, I had them backwards...

Pete
RE: SD card interface
12/10/08 1:52 PM as a reply to saipan59 .
I thought that would be common knowledge that the "Masters" pin out in respect to TX and RX are always opposite on the "slave", kind of like in RS232 where you connect TX from PC to RX of the connecting device, etc.....

--Just a Thought---
RE: SD card interface
2/4/10 2:44 AM as a reply to bmorse .
I'm trying to get a UBW32 (Pic PIC32MX460) working with a SD card --

I've downloaded Microchip's SD Demo, and am stuck at the FSInit() function. I'm not able to get a response from the SD card.

I've followed all of the above suggestions; have voltage divider resistors on the SDO1, SCK1, and SS1 pins, as well as 10k pull-up resistors. I've modified Hardware.h to reflect the pin assignments for this chip:

sdi1 (rc4)
sdo1 (rd0)
sck1 (rd10)
ss1 (rd9)

And slowed down the SPI communications.

I've hooked up a scope and am seeing some odd behavior - the chip select (SS) seems to behaving correctly, but the clock (SCK) looks like it's transmitting data, not a clock signal, and it's sligtly skewed & sending data slightly before the SS triggers. SDO is always high (as well as SDI, but that's expected since it's not communicating).

This is the first time I've played with SPI communications, I'm stuck, any suggestions?

Thanks!
Attachments: MDD File System-SD Card.zip (30.1k)
RE: SD card interface
4/8/10 8:42 AM as a reply to ericm .
Hello,
The Possible problem is with the Pullups.
You need 47k Pull ups(3.3V) on all your SPI lines connecting to the SD card.

Hope that this should solve your problem.

Best of Luck,

Boseji
RE: SD card interface
7/22/10 8:56 PM as a reply to boseji .
Hi Boseji,

I am new to the PIC32 and I was going through your code. I took the SDMMC.c and the SDMMC.h and put them in a new project. As I have no clue on how the RTOS works I changed the delay function for a while(--time). I wrote a Main where I put the functions initSD(); writeSECTOR( 0x55, 0); deinitSD(); The thing is that I start debugging and it stays stuck at initSD();. I wanted to ask if you could know what Im doing wrong.

Thank you.

Manuel
RE: SD card interface
8/25/10 12:48 PM as a reply to matheuz .
Hello,

The reason that its stuck at the initSD is that your pin configurations are different than LATHI design. Correct these changes in the HardwareProfile.h then it should work fine. You can email me. My ID is available in my Blog http://m8051.blogspot.com

Warm Regards,
Boseji