PIC18F4550 - Interfacing MicroSD adapter

Discussion in 'Embedded Systems and Microcontrollers' started by Ozette, Jan 5, 2012.

  1. Ozette

    Thread Starter New Member

    Dec 19, 2011
    16
    0
    Dear community,

    I'm new and still learning, please bear.
    (I've read the other thread about the MicroSD, but this one was not relevant to mine).

    Recently I started a project on my own. My idea was to make some image compression unit. I've experimented with several exsisting compression algorithms on formats such as .jpg (lossy), .png (lossless).

    To start off I want to keep things simple and compress a simple .txt file which resides on a microSD.
    This is what I will be using: http://www.gravitech.us/micaad.html

    Also, I will be using an 8gb (c4) microSD.
    I've read some articles about file formats, sending data, how microSDs can be acessed and how information is stored, but I'm still learning.
    I found this page to be very helpful: www.pjrc.com/tech/8051/ide/fat32.html

    Also I downloaded a FAT32 file system library which I want to be using once I interfaced the adapter to my PIC.
    source: ultra-embedded.com/?fat_filelib

    It might sound stupid, but I'm kind of noob interfacing peripherals to PICs.
    I hope to get some enlightment here on how I can set up my PIC to send some data (either raw or in FAT32) to the microSD.

    I especially would like to know which pins I should/could use to connect the adapter. Because the adapter's pinouts state for example a SCK, so can I for example make any pin act as a clock or only those which got SCK or CLK asigned to them.
    And for example the TX and RX pins on this PIC's Cport, must I use these to create some MISO MOSI communication?

    I've got some other smaller questions as well, but I don't want to make the opening post too long.

    I'm using a predefined pcb so some pins are already being used. But I can change a few things here and there.
    The schematic of this pcb can be found in a thread I opened earlier:
    http://forum.allaboutcircuits.com/showthread.php?t=63667
    (3rd post)

    Please let me know if anything is unclear.

    Some help or advice would be greatly appreciated.
    Thanks for your time/help.
     
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,756
    Let me correct that for you:

    Welcome. :)

    I've not used SD cards, but they use SPI interface, yes?

    Then you need to use the pins marked SDI, SDO, and SCK.

    I'm sure others will have more valuable input!
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    I am working on the same thing myself. I was getting mixed results reading the sectors on the SD chip. I figured maybe it was the way I had my SD socket wired up so I ordered one of these:

    http://www.futurlec.com/Mini_SC.shtml

    I am getting a little upset that it has been 4 days and it has not shipped yet.


    If I get anywhere with reading the SD I will let you know. Please do the same.
     
  4. Ozette

    Thread Starter New Member

    Dec 19, 2011
    16
    0
    @joeyd999
    Thank you, hahaha I'd like me some yes!
    Thanks for your input, it's helpful :)

    @spinnaker
    Interesting, that's really wonderful.
    Thank you, and I will let you know what I have managed.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Yes they do use SPI.

    Other useful signals are

    Chip Select (essential)

    Card detect (may be ignored) (I use it)

    Write Protect (may be ignored) (I use it)

    Do note that SD cards run at 3.3V so either use that voltage for the PIC or make a level converter. The converter is sometimes done with just resistors.
     
  6. Ozette

    Thread Starter New Member

    Dec 19, 2011
    16
    0
    @ErnieM
    Thanks for your words of advice. And I think I'll use a resistor to make the SD card run at 3.3v.

    At the moment I'm reading some articles, I'll let you (all) know if I manage something.
     
  7. Ozette

    Thread Starter New Member

    Dec 19, 2011
    16
    0
    Small question:

    http://www.gravitech.us/micaad.html
    Should the adapter's 'DI' be connected to the uC's 'SDO', or should the DI be connected to the SDI and the DO to the SDO.

    And here (press 'page down' 3x): http://www.frank-zhao.com/cache/fat_sd.php
    I read that cs basically can be connected to any pin, but what is a pull-up resistor?
    the chip select pin is used for communication If I'm correct, with state as high if it's idle.
    Please correct me if I'm wrong.
     
  8. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    MCU SDO > SD DI
    MCU SDI < SD DO

    Chip select can be connected to any MCU pin as long as it is configured for digital output.

    Non selected is high for chip select. Idle is high for clock.
     
  9. Ozette

    Thread Starter New Member

    Dec 19, 2011
    16
    0
    Oh I see, thanks a lot spinnaker.

    By the way, I forgot this adapter has a 3.3v regulator, so my pic would be able to operate on 5v without any problems I guess.
     
    Last edited: Jan 7, 2012
  10. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    You should have a pullup on the SD DO. Much of the software out there that reads SD chips uses oxFF to determine that no data is being read. A pullup will make sure the SO is in a know state when the DO is not really active.
     
  11. Ozette

    Thread Starter New Member

    Dec 19, 2011
    16
    0
    Thank you, explains it.

    Edit:
    I've been wondering; Is it possible to adjust a file residing on the microSD with the microcontroller without transfering the data over to the microcontroller? So using the microSD's capacity to work on.
    Or would I still need to read data in (send it to the microcontroller) to adjust it on the microSD.
     
    Last edited: Jan 8, 2012
  12. Ozette

    Thread Starter New Member

    Dec 19, 2011
    16
    0
    Edit:
    Never mind, I took a glance at the schematic again and disconected the 3v3 to ground.
    This didn't make any sense, and the LED is on now when a card is in the adapter.

    But then, what is the 3v3 used for on this adapter?
    Also, does anybody know an answer to my previous question?

    Can anyone tell me what I did wrong?

    My card detect LED won't light when I put a microSD in the adapter.

    http://www.gravitech.us/micaad.html


    http://site.gravitech.us/MicroResearch/Others/MICROSD-ADP/MicroSD-ADP_Schematic.pdf


    Pinouts connected like this to PIC18F4550:

    PIC | Adapter

    VDD to VIN

    GROUND to GND
    GROUND to 3v3 <- OK?
    RB7(40) to CS
    SDO(26) to DI
    SCK(34) to SCK
    SDI(33) to DO
    GROUND to CD <- OK?

    I'm not really sure about where I need to connect the 3v3, I've read articles which explain connection of the microSD to a mcu, but those adapters didn't have a 3.3v regulator so less pins were used.

    I'm a little confused there, because this adapter can be connected directly to a mcu running on 5v if i am correct.


    Also, does anybody know an answer to my previous question?
     
    Last edited: Jan 10, 2012
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    I would do it like so:

    Pinouts connected like this to PIC18F4550:
    Code ( (Unknown Language)):
    1.  
    2. PIC            Adapter
    3. VDD            VIN
    4. GROUND         GND
    5. No Connect  3v3     < CHANGE
    6. RB7(40)       CS
    7. SDO(26)           DI
    8. SCK(34)       SCK
    9. SDI(33)       DO
    10. No Connect  CD       < CHANGE
    11.  
    This card makes 3.3 from 5V, so the 3.3V pin is an output. It makes it to run the SD card and the 3.3V<->5V interface chip. You can use the 3.3V in your circuit if you so choose.

    If yuo are not using the card detect CD signal I would just leave it. I would expect this pin to connect to ground when a card is inserted, so a simple pull-up resistor would give you a proper indication. (I also suggest you use this feature.)
     
  14. Ozette

    Thread Starter New Member

    Dec 19, 2011
    16
    0
    Thank you kindly for your reply ernieM.

    It's exactly as you say, I will now try to read and write to the card.
     
    Last edited: Jan 11, 2012
Loading...