CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Micro SD card interfacing to pic18f67k22

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
manisha



Joined: 03 Feb 2012
Posts: 29

View user's profile Send private message

Micro SD card interfacing to pic18f67k22
PostPosted: Wed Jan 30, 2013 6:34 am     Reply with quote

Haiiiiii

I am using development board of micro sd card which is from embeededmarket.com. I have connected to 5volts line i.e cs,di,do and sck pins. and set sdi pin of microcontroller as input in tris configuration and others as output and used ex_mmcsd.c example and I am able to read and write the data from particular location even if the SD card is inserted or not. THen tried with FAT16 driver and ex_fat.c file and in this, when entered the commands like mkdir,format etc. I am getting errors in response.. Not understanding where the fault is?

Can anyone please tell me how exactly micro sd interfacing code is done???

And one more is does Micro SD card support SPI mode since in some places it is given as optional...

Expecting a quick response.......
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 7:53 am     Reply with quote

5volts?........

SD, and MicroSD, use 3.3v, not 5v.
5v anywhere near them is asking to kill the card.

The CS line, and the SCK line (and preferably the SDI line to the micro), must have pullup resistors to 3.3v. 10K is recommended for CS, and 50K for the other lines. Some sources simply recommend 10K on all four lines.

Card must be MicroSD, not MicroSDHC. The libraries do not support HC cards.

If you are using the examples, you don't need to set TRIS. With CCS, for 99% of code, do not touch the TRIS registers, the compiler handles this for you.

Best Wishes
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: Micro SD card interfacing to pic18f67k22
PostPosted: Wed Jan 30, 2013 4:26 pm     Reply with quote

manisha wrote:
...I am able to read and write the data from particular location even if the SD card is inserted or not.


Writes to SD/MMC cards are done in 256 bytes blocks. In file system implementations this typically means on or more 512 byte blocks of RAM are allocated for write and/or read buffers. Note that strictly speaking there is no requirement to read in 512 byte blocks but it is very common to do so.

Reading and writing operations therefore operate on the RAM buffers with actual media writes (and typically actual reads) done on 512 byte boundaries. Reading and writing without a card actually present means that you are reading and writing only to the RAM buffers and there is something wrong with you code that allows you to get to this point when the media has not successfully passed initialization.

Quote:
And one more is does Micro SD card support SPI mode since in some places it is given as optional


Mandatory support for the SPI interface on microSD cards was dropped a few years ago however you will note that virtually all vendors of microSD cards offer SD adapters allowing their microSD cards to be used in full size and mini size SD card applications. However full size and mini size require SPI support. This means that any vendor dropping SPI support from their microSD cards will result in them missing out on the mini and full size SD market allowing a competitor to fill this niche. I work with lots of microSD cards from multiple vendors and have yet to come across one that lacks SPI support. This does NOT mean that all microSD cards support SPI - it just means I have not come across any that do not support SPI.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
manisha



Joined: 03 Feb 2012
Posts: 29

View user's profile Send private message

Micro SDHC card interfacing with pic18f67k22
PostPosted: Wed Jan 30, 2013 11:00 pm     Reply with quote

Thanks a lot for your replies......

I am sure that the voltage at the card is 3.3 volts logic even if microcontroller has 5 volts logic since 3.3 volts regulator is in between and also all the IOs (CS,DI,DO,SCK) near memory card are now at 3.3 volts logic. So no chance to kill the card.

And I think the problem lies in the capacity of card i.e I am using 4GB kingston i.e SDHC as specified on the memory card. And I think the drivers provided in the library are not supporting that card.

Can anyone please suggest what drivers I should use to program 4GB microSDHC card???
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu Jan 31, 2013 1:59 am     Reply with quote

Even if the card was SD, you would have problems.
How are you adapting between 3v and 5v on the data lines?. Key point to understand, is that the 3.3v output of the SDO line on the card, does _not_ go high enough to be seen by the PIC running at 5v, as a logic 'high', if you are going into an input that uses Schmitt buffers. These _require_ the signal to go up to typically 0.8* the PIC's supply rail (0.7* in some cases). 3.5 to 4v. The SDO line then can never actually be 'seen' by the PIC. Hence you need to have a proper 3.3v to 5v buffer on this line, or it'll never work.
Hardware SPI uses Schmitt inputs.
The other lines _can_ be adapted by just using resistive dividers (but this can be unreliable at higher data rates), but the SDO line can't....
You can feed this line straight into the PIC, _only_ if you use software SPI, and select pins on your PIC that have TTL input buffers (2.4v high).

Interfacing properly between the levels _requires_ proper level shifting IC's in both directions (or much easier, switch to using a 3.3v PIC).

The fat libraries actually work OK with the larger cards. The bit that doesn't is the MMC interface code. The larger cards change to using block addressing, rather than byte addressing, using a fixed 512byte block. There are commercial libraries that'll handle this, or it is fairly easy to modify the existing driver. However you need to get your hardware working first. I'm sure your's isn't.
Look at brushelectronics for a full driver, and look at the circuits they publish for 'how to connect'.

Best Wishes
manisha



Joined: 03 Feb 2012
Posts: 29

View user's profile Send private message

PostPosted: Thu Jan 31, 2013 6:28 am     Reply with quote

ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 05, 2013 4:39 pm     Reply with quote

manisha wrote:
Haiiiiiiiii,

I have used fat.c file available in the ccs drivers and programmed the 2 GB micro SD card and it is working fine. When I make a file it is created and data is appended into the file using the functions available in ex_fat.c file in ccs. But the data appended into the file is limited to few bytes or characters... If I append large data into the file,the data is corrupted and only few words (data) are appended and the same are repeated 3-4 times..

How can I increase the file size to read/write the exact size data from/to the file??.

#define MAX_FILE_NAME_LENGTH 0x20 // the maximum length of a file name for our FAT, including /0 terminator
#define STREAM_BUF_SIZE 0x20 // how big the FILE buffer is. 0x20 is optimal

I have these 2 lines but if I change this number the file is getting corrupted when read from PC.

Please help me in writing huge data to the file.
Always post your CCS compiler version. It may be a known bug in your version.

There are a few known bugs in the CCS FAT driver. See Andrew's fixes:
www.ccsinfo.com/forum/viewtopic.php?t=43402
www.ccsinfo.com/forum/viewtopic.php?t=43417
Or you might consider to use one of the other FAT32 libraries from the Code Library.
manisha



Joined: 03 Feb 2012
Posts: 29

View user's profile Send private message

PostPosted: Tue Feb 05, 2013 9:53 pm     Reply with quote

The compiler version which I am using is Version 4.120
manisha



Joined: 03 Feb 2012
Posts: 29

View user's profile Send private message

PostPosted: Wed Feb 06, 2013 12:14 am     Reply with quote

Quote:
There are a few known bugs in the CCS FAT driver. See Andrew's fixes:
www.ccsinfo.com/forum/viewtopic.php?t=43402
www.ccsinfo.com/forum/viewtopic.php?t=43417
Or you might consider to use one of the other FAT32 libraries from the Code Library.


I have made the changes in my fat and mmcsd driver files as mentioned in the above links and checked but even though the same problem occurs..

How exactly can we increase the size of the file created in the SD card?? since I am able to append only upto 255 bytes/characters of data into the file created.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group