SD Card with PIC18F

Author
juliosilva
Super Member
  • Total Posts : 246
  • Reward points : 0
  • Joined: 2004/04/26 09:47:58
  • Location: Portugal
  • Status: offline
2007/03/15 14:26:29 (permalink)
0

SD Card with PIC18F

Hello,

I need to implement a SD data logger type with PIC18F.
I'll use PIC18F family micro, with C18.

The data should be written in a file (text file will do), and then should be opened in PC.

First, where can I find a cheeper SD Slot?
What is the best option?
Buy that "packages" that has the SD Slot and FAT implemented, and I only need to send the command to Read/Write to SD.
Or create my own FAT library in my PIC?
Is it dificult to create that functions? I only need to open, write (read maybe, or not) and close, the filename should be the date... Maybe check for free space... Dont know.
Has anyone already done that lib in C18, and share it?

Can anyone "guide" me on this subject?

Thanks,

jS


#1

18 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: SD Card with PIC18F 2007/03/15 14:36:49 (permalink)
    0
    Hi Julio, I was going to buy Slots but have not bought then (not urgent)... so, can't help!
    Pacer and probably other people have that code for sale (since it's not exactly trivial); I'm going to work on it, but had no time by now (and not sure I will share it too Smile kidding!)
    My idea of "implementation" for FAT was: GeneralStatus of Card, FindFirstFile, FindNextFile (directory browsing), Open/Read/Write/Close files, Stat on a file...

    Anyway, if you want to avoid this all, you can write data to your FAT in some proprietary format (i.e. sequence of bytes) and then use a USB interface (or serial, or whatever) to download it to a PC.

    GENOVA :D :D ! GODO
    #2
    juliosilva
    Super Member
    • Total Posts : 246
    • Reward points : 0
    • Joined: 2004/04/26 09:47:58
    • Location: Portugal
    • Status: offline
    RE: SD Card with PIC18F 2007/03/15 14:42:27 (permalink)
    0
    Hello DarioG,

    The final product wont be near a PC, so the ideia was to store information on the card, and bring the information to the PC, not the PC to the information :).
    The ideia was to make the sistem independ/away from the PC.
    This is for a school project so I don't have much budget to spend on code... If I wont have it for free, then I have to do it, or go arround :).

    Thanks,

        jS
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: SD Card with PIC18F 2007/03/15 15:28:49 (permalink)
    0
    I see.
    But you can write your own SD , remove it, and instead of placing it directly into a PC, you plug it into another little-little board with RS232 or USB, and PC reads it! Smile

    GENOVA :D :D ! GODO
    #4
    juliosilva
    Super Member
    • Total Posts : 246
    • Reward points : 0
    • Joined: 2004/04/26 09:47:58
    • Location: Portugal
    • Status: offline
    RE: SD Card with PIC18F 2007/03/16 12:33:02 (permalink)
    0
    Hello,

    That's a solution, not very pratical, since you have to build a new hardware, but it's easier solution :).
    Thanks,

    jS
    #5
    asmallri
    Super Member
    • Total Posts : 1864
    • Reward points : 0
    • Joined: 2004/05/26 09:00:05
    • Location: Perth, Australia
    • Status: offline
    RE: SD Card with PIC18F 2007/03/16 17:36:56 (permalink)
    0
    ORIGINAL: juliosilva
    That's a solution, not very pratical, since you have to build a new hardware, but it's easier solution :).


    At some point it must be cheaper to buy a FAT library that to do this.

    Regards, Andrew

    http://www.brushelectronics.com/index.php?page=software
    Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
    #6
    juliosilva
    Super Member
    • Total Posts : 246
    • Reward points : 0
    • Joined: 2004/04/26 09:47:58
    • Location: Portugal
    • Status: offline
    RE: SD Card with PIC18F 2007/03/17 06:04:53 (permalink)
    0
    Hello

    I think its rather buy an SPI module that has a mcu with all the library inside plus the card slot, than buy a card slot, and the libraries, and have a PIC with low resources cause of the lib...
    IMHO...

    jS
    #7
    asmallri
    Super Member
    • Total Posts : 1864
    • Reward points : 0
    • Joined: 2004/05/26 09:00:05
    • Location: Perth, Australia
    • Status: offline
    RE: SD Card with PIC18F 2007/03/17 06:56:29 (permalink)
    0
    I have toyed with this approach as well. If you take a holistic view of what is going on, the SD Card already contains a embedded controller for accessing and managing access to the flash memory system. It abstracts the access to the media taking care of low level tasks such as wear leveling, error detection and media recovery (not data recovery). The developer has to deal with the SPI interface to communicate between the host processor and the media controller. 

    We could add another layer of abstraction to offload the low level SPI interface and the file system overhead. There are products on the market that do just that, but did they significantly decrease the complexity in the process?

    The embedded application still has to deal with interfacing with the file system. There is a finite number of bytes exchanged between these subsystems, buffering and buffer management still needs to take place at both ends, the application still needs to know what type of errors occured when accessing the media and to take action at the application level to reinitialise the files system as appropriate.

    The developer needs to define some interface between the application and the underlying file system. If we look at a typical FAT library, the API is pretty much along the lines of the file system API you would expect to be provided in a PC development environment. We can further abstract the FAT system interface but now we either start diverging from the typical application file system API or we replicate the API interfacing to the interface. It boils down to "what is the return on investment" ak the diminishing returns problem.


    Regards, Andrew

    http://www.brushelectronics.com/index.php?page=software
    Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
    #8
    TCM
    Super Member
    • Total Posts : 502
    • Reward points : 0
    • Joined: 2005/06/26 02:01:25
    • Status: offline
    RE: SD Card with PIC18F 2007/03/18 16:35:30 (permalink)
    0
    Be aware that there is a Microchip FAT16 library available!

    Once i had a spectrum computer , today i am throwing away my pentium PC , tomorow i will write to you from a Microchip internet-enabled device.
    #9
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: SD Card with PIC18F 2007/03/18 16:50:48 (permalink)
    0
    ORIGINAL: TCM
    Be aware that there is a Microchip FAT16 library available!


    Hmmm, you sure? This sounds to me as a long-time legend, but I've never been able to find it!

    GENOVA :D :D ! GODO
    #10
    juliosilva
    Super Member
    • Total Posts : 246
    • Reward points : 0
    • Joined: 2004/04/26 09:47:58
    • Location: Portugal
    • Status: offline
    RE: SD Card with PIC18F 2007/03/19 14:14:07 (permalink)
    0
    It depends on the project, if it's a stand-alone, or if it's only one/few.
    In my case I only need it for one project, if I'm gonna spend some money in a SD Slot, it's better spend a little more, and don't worry about taking care of the dirty job, IF there's not a Free API for it, or you don't want/have time to spend doing it by your self.

    TCM: Where can that be found?

    Thanks all,

        jS
    #11
    tyroflan
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2007/03/20 17:10:50
    • Location: 0
    • Status: offline
    RE: SD Card with PIC18F 2007/03/20 17:15:10 (permalink)
    0
    hi,

    i'm learing pics for a while and i wanted to user SD card with 18F of dsPIC, is there sort or tutorial or schematics about how SD card works ?
    i didn't find anything about how to "interface the sdcard on the pic".

    i see these SD topics are in SPI part of the forum. i suppose the technique uses this protocol ?
    Is any other chip necesary to read/write an SDcard ?

    Thank you for your help dudes.

    #12
    soman
    Starting Member
    • Total Posts : 38
    • Reward points : 0
    • Joined: 2006/11/15 04:54:10
    • Location: 0
    • Status: offline
    RE: SD Card with PIC18F 2007/03/20 22:48:51 (permalink)
    0
    It is easy to write driver for FAT 16. Only thing i to understand FAT....
    First thing is that u must have USB card reader.....
    Then format ur SD card with FAT not with FAT 32....
    then connect that card to PIC ....
    read sector 0...
    this gives u Logical block adress of FAT.....
    Go on that sector, read it u will find all information about FAT.....
    than u have to edit fat table, creat file name in root directory, allocate sector to file, write sectoe with ASCII value manually...
    this are the steps to create file manually...
    It is not so complecated..........
    only thing is to understand FAT file system comletely....
    I will give u link where u will find information about FAT
    u search for
    1.Understanding FAT32 Filesystems on google
    2.Clock Rates for SD Cards using SPI Mode on forum
    after that if u have any doubt ask it

    soman nikhra
    mail--snikhara@gmail.com
    +919982118113
    #13
    Neiwiertz
    Super Member
    • Total Posts : 2094
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    RE: SD Card with PIC18F 2007/03/27 11:04:37 (permalink)
    0
    Hi JulioSilva

    I agree with soman, when needed more info read the Janet's BIBLE

    http://www.lvr.com/mass_storage.htm this book describes FULLY every letter the microchip's FAT16 beta  version and AN1003 sdcard+msd USB stack [8D][8D]

    About to the hardware I will go for the picdem fs usb 18f4550 demoboard + a SD/MMC pictail + ICD2 + mass storage book

    Step 0. make a helloworld blinking project
    Step 1. add sdcard.c from AN1003
    Step 2. format sdcard to FAT16 using PC select (FAT)
    Step 3. read address 0 to msd_buffer
    Step 4. verify content of buffer using ICD2
    Step 5. fill bufer using for loop and counter as data
    Step 6. write buffer to sector 0
    Step 7. verifying card content

    Step 8. see this http://forum.microchip.com/tm.aspx?m=220591

    Regards
    #14
    Neiwiertz
    Super Member
    • Total Posts : 2094
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    RE: SD Card with PIC18F 2007/03/27 12:21:07 (permalink)
    0
    Revealed sdcard whiping:
    After whiping a 512MB i write this custom made sector 0 and
    jumping to sector 1 so the PC format's the card and start writing the bootsector at sector 1. This make that the card corresponds to the spec and all fat implementation normally search first for the jump address, so if the bootsector is specified at sector 0 the PC hasn't no problem and if a FAT16 implementation is smart enough this one can first check if bootsector is located at sector 0 otherwise read out the jump address to locate the bootsector.

    Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

    00000000   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000010   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000020   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000030   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000040   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000050   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000060   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000070   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000080   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000090   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000000A0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000000B0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000000C0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000000D0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000000E0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000000F0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000100   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000110   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000120   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000130   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000140   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000150   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000160   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000170   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000180   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    00000190   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000001A0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000001B0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000001C0   00 00 06 00 00 00 01 00  00 00 FF EB 0E 00 00 00   ..........ÿë....
    000001D0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000001E0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
    000001F0   00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 AA   ..............Uª

    1C2 Partition type indicator (hex)    06
    1C6 Sectors preceding partition 1    01
    1CA Sectors in partition 1              977919

    locations 1C2 and 1CA are very important numbers they are matching to the 512MB card and are different when using other sizes ofcourse

    When inserting card to PC's card reader we get the message format card?
    Ok after formatting we see that bootsector is located at sector 1 just as we have specfied at location 1C6 that's all folks.
    #15
    Beuse
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2008/01/24 13:35:21
    • Location: 0
    • Status: offline
    RE: SD Card with PIC18F 2008/01/24 13:45:55 (permalink)
    0
    Hello.
     
    After a lot of tries, I tried to use this source code in order to access data on a SD card on a dsPIC30F for a project.
    Has anyone been able to compile this source code for FAT16 ?
    I need to use the SPI and read/write functions to make an SD card module work, the goal is to be able to send a .wav file on a buffer, adding some effects (reverb etc.) and finally send it on a codec and amplier homemade...
     
    Has anyone been able to make this work ?
     
    Thanks.
    #16
    RESNIC
    Senior Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2005/10/24 15:39:04
    • Location: ITALY
    • Status: offline
    RE: SD Card with PIC18F 2008/01/28 06:00:24 (permalink)
    0
    Hello,
     
    Also I used the AN1045 and with some modification it works very well !!!
     
    Now I'm thinking to the future, when the SD Card will be greater then 2GB and wi must use the FAT 32.
     
    What do you think about the Driver For SDCard with dimension >2GB?
    And what about the FAT 32?
    Somebody have already change the AN1045 to work with this characteristcs?
     
    Thank you very much for your answare and Have a nice day !
     
    #17
    david_naseef
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2007/03/29 04:16:20
    • Location: 0
    • Status: offline
    RE: SD Card with PIC18F 2008/02/24 10:33:49 (permalink)
    0
    Hi Everybody,
     
    My sdcard is initializing very good but the problem is when I want to write to the sdcard.
     
    First I send a write single block command and the response is 0x00 which is correct.
     
    Then I send 512 bytes and two crc dummy bytes.
     
    Now I should I recieve 0x05 from the card but instead I recieve 0x00. What could cause this problem.
     
    I have tried many cards all with the same result.
     
    thanks
    #18
    brain21
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2003/12/01 09:15:50
    • Status: offline
    RE: SD Card with PIC18F 2008/02/27 21:06:38 (permalink)
    0
    Hi people, I have been trying to write my own FAT lib for a while, but I got tired of doing it so I bought an OEM board from GHI Electronics.  Its called the uALFAT-TF and its pretty small!  I haven't tried it yet, but the documents and forum look promissing.  It uses a micro sd card.  Just thought I'd throw that out there.
     
    Brain21
    #19
    Jump to:
    © 2018 APG vNext Commercial Version 4.5