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

SD Card help required

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



Joined: 08 Apr 2008
Posts: 16

View user's profile Send private message

SD Card help required
PostPosted: Wed Apr 16, 2008 6:39 am     Reply with quote

Hello,

I am after a bit of help. I would like to use an SD card (or equivalent) for data storage. I want a PIC to create a .txt file (or equivalent) for storage and when the data is stored I can unplug the card from the PIC and plug it into a PC. I am looking at storing a normal 8 bit value to start with as I am taking temperature samples from the TC74 located on the PICDEM 2 board.

I recently used the 'flex_lcd.c' file as a #include file and a simple .c test program to get me up and running with the LCD display on the PICDEM 2 board which was great and I wondered if there was similar code samples available for an SD card. I also currently use a 16F877A. I know I will have to change this chip due to memory storage but is there an equivalent 18 series chip with the same pin outs?

Any circuit diagrams, datasheet links etc. . . would also be extremely useful.

In fact, any help would be great!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 16, 2008 12:10 pm     Reply with quote

Quote:

I also currently use a 16F877A. I know I will have to change this chip due
to memory storage but is there an equivalent 18 series chip with the
same pin outs ?

18F452 is the most compatible. 18F4520 is an enhanced version.
You need the PCH compiler for these PICs.
mxkid



Joined: 08 Apr 2008
Posts: 16

View user's profile Send private message

PostPosted: Wed Apr 16, 2008 2:29 pm     Reply with quote

Hi,

Not sure what you mean by a PCH compiler - do you mean that the CCS compiler won't do the job? I have looked at the read me for my IDC2 and both of these IC's are compatible.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 16, 2008 2:50 pm     Reply with quote

The "compiler" is actually at least four separate compilers that are
sold individually or bundled together in various combinations along
with the CCS IDE. Notice the table on this page shows the PCB,
PCM, PCH and PCD compilers:
http://www.ccsinfo.com/content.php?page=Purchasing1

To use the 18F chips, you must have some form of the "compiler"
that contains the PCH compiler.
mxkid



Joined: 08 Apr 2008
Posts: 16

View user's profile Send private message

PostPosted: Wed Apr 16, 2008 3:01 pm     Reply with quote

Ah, makes more sense now, cheers.

Is there anyway I can use my 16 series PIC to perform the task?
asmallri



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

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

PostPosted: Wed Apr 16, 2008 5:32 pm     Reply with quote

PCM programmer wrote:
Quote:

I also currently use a 16F877A. I know I will have to change this chip due
to memory storage but is there an equivalent 18 series chip with the
same pin outs ?

18F452 is the most compatible. 18F4520 is an enhanced version.
You need the PCH compiler for these PICs.


The PIC18F4620 is equally compatible but is better suited for generic SD/MMC card applications on the PIC requiring compatibility with the PC (FAT file system). This is because of the larger amount of RAM and Program memory of this PIC.
_________________
Regards, Andrew

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



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

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

PostPosted: Wed Apr 16, 2008 5:34 pm     Reply with quote

mxkid wrote:
Ah, makes more sense now, cheers.

Is there anyway I can use my 16 series PIC to perform the task?


Not readily. The SD/MMC cards must write blocks in 512 byte chunks. This is difficult to implement on a PIC with very limited RAM.
_________________
Regards, Andrew

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



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

View user's profile Send private message

PostPosted: Wed Apr 16, 2008 7:28 pm     Reply with quote

mxkid wrote:
Is there anyway I can use my 16 series PIC to perform the task?
Yes, there are several options but all have severe limitations. The basic problem is that MMC & SD cards have to be written in chunks of 512 bytes. Reading small amounts of data is no problem, you can even read a single byte if you want to, but the writing has to be done a single 512 byte block at a time. None of the PIC16 chips has enough RAM to hold 512 bytes.

The easiest solution as suggested is to use a PIC18 processor but that might require an update of your compiler. When considering a PIC18 processor make sure it can run at 3.3V, it will make your design a lot easier. Often these chips are indicated as PIC18LFxxx.

If you don't want to spend the money for another compiler than here are a few possible alternative methods using a PIC16:

1) Add an external chip that will handle the communication with the MMC or SD card. Examples are the DOSonCHIP for approx. $13, the Vinculum chip based VDRIVE2 module for about $27 and the uALFAT ($20 for chip chip, $56 for module). These are quick and reliable solutions but not cheap, so only suitable for low quantities or upgrade of existing designs.

1a) A fun option. Go crazy and use the USBwiz This module isn't cheap at $85 but gives you besides FAT32 on a SD card also a USB-host implementation! This is better than the common USB-slave implementations as you can now connect memory-sticks, USB-hard disks, keyboard, mouse and printers to your tiny PIC processor!

2) Write the data in small files with a maximum of let's say 100 bytes and fill the rest of the 512 byte blocks with a constant value (e.g. zero). A lot of memory is wasted but who cares with current low prices for the memory cards.
Disadvantage: Some kind of fixed directory/file structure has to be used. Because of the PIC16 memory limitation you can't read and modify the contents of the FAT32 structure, so this will be a write-once-and-never-change directory structure.


Or, consider using another processor type that has more RAM and can be programmed with the free GNU compiler (Atmel, ARM, MIPS, ...).
asmallri



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

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

PostPosted: Thu Apr 17, 2008 7:40 am     Reply with quote

ckielstra wrote:
mxkid wrote:
Is there anyway I can use my 16 series PIC to perform the task?
Yes, there are several options but all have severe limitations. The basic problem is that MMC & SD cards have to be written in chunks of 512 bytes. Reading small amounts of data is no problem, you can even read a single byte if you want to...


Newer card variants when in high capacity mode must also be read in 512 byte blocks

Quote:
Or, consider using another processor type that has more RAM and can be programmed with the free GNU compiler (Atmel, ARM, MIPS, ...).


You could naturally stay with the Microchip using the PIC18F, PIC24F, and dsPICs families and the free student edition of their respective compilers. IMHO it takes significantly longer to develop in these compilers than with the CCS compiler - I frequently use both Microchip and CCS compilers.
_________________
Regards, Andrew

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



Joined: 01 Jul 2007
Posts: 37

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 1:05 pm     Reply with quote

Or you can use an external memory to handle you 512 bytes chunk and then write them back at once to the SD card.

Dimmu
mxkid



Joined: 08 Apr 2008
Posts: 16

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 3:02 pm     Reply with quote

Thanks for all of your help so far, this is becoming much clearer!

I have checked my CCS compiler and it supports the PIC18F4620 PIC. I also have a good idea of how to design the circuit so building and testing it for the correct voltages etc. . should be no problem. So I think I’m good to go.

Regarding to the software side, I have had a look on the CCS forum for code examples and there are several. For example:

http://www.ccsinfo.com/forum/viewtopic.php?t=23969

Even though it's not for an SD card in the example this is the sort of thing I'm after as it gives #include files and sample code (I have both types of card so I can use an MMC card). However, the sample code does more than I require - all I want to do is create a .txt file and write data. Is it better to take all of the bits I don’t require from this example or look for another? Will this cause me problems as this is new to me? Has anyone got or knows of any examples I could use?

Thanks again!
asmallri



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

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

PostPosted: Thu Apr 17, 2008 4:23 pm     Reply with quote

Here is a link to some hardware designs with SD cards http://www.brushelectronics.com/index.php?page=projects
_________________
Regards, Andrew

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



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

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 4:44 pm     Reply with quote

For another software library have a look at the CCS supplied drivers: mmcsd.c & fat.h
An example of using these drivers is in the example directory: ex_fat.c
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