PIC18F4550 - Interfacing MicroSD adapter

Thread Starter

Ozette

Joined Dec 19, 2011
16
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.
 

spinnaker

Joined Oct 29, 2009
7,830
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.
 

Thread Starter

Ozette

Joined Dec 19, 2011
16
@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.
 

ErnieM

Joined Apr 24, 2011
8,377
I've not used SD cards, but they use SPI interface, yes?

Then you need to use the pins marked SDI, SDO, and SCK.
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.
 

Thread Starter

Ozette

Joined Dec 19, 2011
16
@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.
 

Thread Starter

Ozette

Joined Dec 19, 2011
16
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.
 

spinnaker

Joined Oct 29, 2009
7,830
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.
 

Thread Starter

Ozette

Joined Dec 19, 2011
16
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:

spinnaker

Joined Oct 29, 2009
7,830
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.
 

Thread Starter

Ozette

Joined Dec 19, 2011
16
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:

Thread Starter

Ozette

Joined Dec 19, 2011
16
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:

ErnieM

Joined Apr 24, 2011
8,377
I would do it like so:

Pinouts connected like this to PIC18F4550:
Rich (BB code):
PIC            Adapter
VDD            VIN 
GROUND         GND 
No Connect  3v3     < CHANGE
RB7(40)       CS
SDO(26)           DI
SCK(34)       SCK
SDI(33)       DO
No Connect  CD       < CHANGE
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.)
 

Thread Starter

Ozette

Joined Dec 19, 2011
16
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:
Top