Microchip MDD File System

Discussion in 'Programmer's Corner' started by chrisw1990, Mar 31, 2012.

  1. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    Ok, Microchips MDD File System doesnt support more than one device.. so my query is this:
    how do i simultaneously implement an SD card interface and a USB interface?
    obviously the FSIO commands are easy to implement.. and i have seen (i think) some USB specific write commands, but don't know where i have seen these nor what they are..
    any ideas?
    Cheers
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,867
    994
    Microchips MDD File system is HORRIBLE!!!! I can't believe how complicated and confusing the code is. I would be embarrassed to publish the code.


    I used FatFS instead.

    http://elm-chan.org/fsw/ff/00index_e.html

    I have attached some code I have been working with. It is not fancy as I have not had a chance to develop proper sample code. It is for the PIC18F27J53 but you should be able to easily modify it. I still need to make the reading of sectors more efficient. I'm thinking of caching at least the last sector read.

    In theroy you could modify it to read as many devices as you please. It seems it would be pretty easy to do. The issue is going to be available memory. You would need to define 512 bytes per device.
     
    chrisw1990 likes this.
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I can't believe how simple it is to use the Microchip MDD file system. It comes up clean without any real tricks.

    A good starting point may be to look at the Microchip "MDD File System-SD Card" sample application. While the USB-SD app does talk to both devices I found to make my code talk to the SD I had to add explicitly the SD stuff.

    Sorry it has been too long for me to discuss all the specifics, but basically just add FSIO.C and SD-SPI.c into your project. Their respective include files should be within the compiler's view. Your HardwareProfile.h file also needs to point to your physical connections.

    I used this in a PIC32 project (after having similar stuff work in PIC18's) that used this USB-SD card reader sample app as a starting point. I added in the MDD library to load in the next hex file to use. It happens to be on a color LCD board so it uses the GOL stuff too. The hard part (and my last open items) were creating a drop down combo box to select a file name.
     
    chrisw1990 likes this.
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,867
    994
    Take a good look at the code sometime. It is horrible, sorry.
     
  5. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    i have to admit, the MDD file system functions i have used are so easy to use, but i havent delved into what they actually do so much, i find the microchip libraries ever so complicated to understand its easier to read a book on what the concept is and write your own functions.
    i have to admit, i was a little annoyed when i found out i couldnt just use the same FSIO stuff for both, though not sure how to set up the hardwareprofile.h to specify the physical connections.
    i must admit, this is all for my project, which sadly is due for exhibition on the 25th april, and im "bricking it". there have been so many complications, i thought the code would be fairly simple as there are so many available demos, i know i sound a little defeatist, but UGH ='[

    ----------------------------------------------
    EDIT
    ----------------------------------------------
    ok i found the USB-SD data Logger in the microchip application libraries, gonna take a look at it in a bit got a stupid poster to make ¬¬ bloody university.

    ----------------------------------------------
    EDIT
    ----------------------------------------------
    ok so had a read of the hardware profile for the data logger demo anddd.. ill sound stupid here no doubt, but it says something about CS, CD and WE:

    Code ( (Unknown Language)):
    1.  
    2.     #define SD_CS               PORTBbits.RB1
    3.     #define SD_CS_TRIS          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
    What the bloomin hec are they? im assuming CS is Chip Select for the SPI.. though CD and WE? looking at SD Card PINOUT it looks like CD is the Chip Select, but that still leaves two.. confused much?
     
    Last edited: Apr 1, 2012
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    WE is Write Enable. The larger SD cards have a mechanical protection tab, the smaller ones don't. WE is the line sensing that tab.

    You usually can define the pin as "1" and the TRIS as null if the input function pin is not there and you just want a default "yes" answer.
     
  7. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    ah yeh of course, makes sense, the image i was looking at didnt have such a pin.. probably cos its a mechanical feature of the socket rather than the card.. not sure what the cs and cd are though, will have to have a look through the code and report back when i get a chance.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Sorry, thought you knew tho*se. CS is the SPI Chip Select, and CD is the hardware Card Detect.
     
  9. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    i knew one was the chip select, but i think i had confused myself with the sd card pinout, 'cos one of the pins is CS and one CD (the same pin) so it confused me a little) thanks for the help, no doubt ill have more enquiries :p
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    One thing to note is SD cards work off 3.3V, so either run your PIC at that voltage or add some resistor dividers between PIC and SD.

    Here's someone's schematic showing those resistors:
    [​IMG]

    (I don't recommend using the red LED to drop 5V to 3.3V as he does.)

    Note the LED on the CS line. That makes a nice "In Use" indicator.

    Sparkfun has a breakout board for an SD card (large sized) (small also available). The page explains the pin names & numbers some more.
     
  11. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    yeh, my whole circuit runs at 3.3V, using 3V3 gps and accelerometer so made sense:)
     
  12. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    ok soo i tried defining the WE bit as null, NULL, \0 etc.. iv had to define the state as 1, and define its tris as a spare IO pin i had.. iv also discovered iv majorly screwed up the SPI bus.
    all my SDIs are connected to SDI on processor.. and SDO is the same problem.. and the spi for the screen.. oh i connected that data in to the processor data in.. what a T**T :D
     
  13. chrisw1990

    Thread Starter Active Member

    Oct 22, 2011
    543
    41
    ok.. so
    Code ( (Unknown Language)):
    1.     FilePoint = FSfopen ("FILE1.txt", "a");
    2.     if (FilePoint == NULL)
    3.     {while(1);}
    4.     length=strlen(SystemData);
    5.     Nop();
    6.     FSfwrite(SystemData, length, 1, FilePoint);
    is returning a null pointer.. ideas?
    need any more coding, let me know
     
Loading...