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 support@ccsinfo.com

Saving data in SD card using PIC18f4520

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



Joined: 10 Jan 2010
Posts: 5

View user's profile Send private message

Saving data in SD card using PIC18f4520
PostPosted: Thu Jan 14, 2010 7:38 pm     Reply with quote

I am designing a system where some data are shown in the lcd display now I want to save these data in a SD card. Data are displayed in the LCD by the following
Code:

#include<lcd.c>
lcd_init();
lcd_putc('\f');
printf(lcd_putc,"vi=%4.2F",vi);
printf(lcd_putc,"ii=%4.2F\n",ii);
printf(lcd_putc,"vo=%4.2F",vo);
printf(lcd_putc,"io=%4.2F\n",io);

Actually I put here the main part concerning the LCD display. I do use PIC 18f4520. I want to save these in SD card. Now for saving these in the SD card what should I do? The driver with the compiler "mmc_spi" , is it fine or need some modification? and after that what command I have to do in the main coding. Plzzz give me suggestions.
Hope I am going to get some solutions of my problem immediately.
Regards
Sumon
asmallri



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

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

PostPosted: Thu Jan 14, 2010 8:53 pm     Reply with quote

It depends on what you are trying to do. If you are storing and retrieving data only via the PIC then you can perform low level operations without a full fie system. If however you want to be able to share files with another device, such as a PC, and do not want to develop a driver for PC but instead want to use a standard fie system then the PIC needs to support the file system.
_________________
Regards, Andrew

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



Joined: 10 Jan 2010
Posts: 5

View user's profile Send private message

PostPosted: Fri Jan 15, 2010 5:00 pm     Reply with quote

Thank you very much Andrew for the reply....at least I am getting some hope now.......... Smile
I want to save this data in the SD card (I think SPI bus is required for this). Then I want to retrieve these data from the card and just want to keep this saved in the card, and insert this card in the pc through a card reader and retrieve these data. And you talked about the file system. I don't understand it cause I am a new user. Is it fine or do you suggest to retrieve data directly by the pc connected ? Plz suggest me which one will be better and give me the way to make it possible. Again thank you and plz reply cause I am in a bad state regarding this issue.
regards
Sumon
asmallri



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

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

PostPosted: Fri Jan 15, 2010 6:30 pm     Reply with quote

The easiest way to talk to an SD card is via the SPI bus.

Think of an SD card as a sequence of filed sized sectors. You tell the card the sector number you want to write to and then perform a low level operation. Your software determines what sector number you read or write from. In this regard it is like reading and writing to an EEPROM.

However if you want to perform file based operations, such as opening a file, writing to a file, removing the card from the PIC and inserting it in a PC, and having the PC read the file just like any other disk on a PC them you need a file system.

FYI - The PIC18F4620 or other PIC with more RAM and Program memory are a better choice than the PIC18F4520 - this is because a file system is memory intensive for both RAM and program memory
_________________
Regards, Andrew

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



Joined: 10 Jan 2010
Posts: 5

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 8:29 pm     Reply with quote

Thanks Andrew once again for your reply.
Ok then I just want to write in the SD card and read from it. I don't want to create file and save them in the file.
I want to do it in the easiest way just to write it and retrieve it. That's it...so what is the step to do it...

Waiting for your reply eagerly
Thanks
msumonh



Joined: 10 Jan 2010
Posts: 5

View user's profile Send private message

PostPosted: Wed Jan 20, 2010 10:30 am     Reply with quote

hi
can you plz let me understand that how can i know the memory map of the SD card. because i am saving data at the card at when i want to read it then how can i call the data.
Thanks
asmallri



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

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

PostPosted: Wed Jan 20, 2010 11:46 am     Reply with quote

msumonh wrote:
hi
can you plz let me understand that how can i know the memory map of the SD card. because i am saving data at the card at when i want to read it then how can i call the data.
Thanks


An SD/MMC card, when accessed via a low level driver has no MAP. The first sector is sector 0 and increments upwards.

On the other hand if you have a file system then it depends on the file system. Typically it is the FAT file system in which case you can google it.
_________________
Regards, Andrew

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



Joined: 10 Jan 2010
Posts: 5

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 7:05 am     Reply with quote

Andrew
Thanks again. Is it possible to use the "mmc_spi" that in the driver folder use as the driver here and in the first reply you told me that I can write my data and read it by the eeprom command. Is it ok? I think if this becomes clear to me then I could be able to do the job. Plz make this thing that i asked today clear to me. It would be a great help.
Thanks
Sumon
asmallri



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

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

PostPosted: Fri Jan 22, 2010 1:31 am     Reply with quote

msumonh wrote:
Andrew
Thanks again. Is it possible to use the "mmc_spi" that in the driver folder use as the driver here and in the first reply you told me that I can write my data and read it by the eeprom command. Is it ok? I think if this becomes clear to me then I could be able to do the job. Plz make this thing that i asked today clear to me. It would be a great help.
Thanks
Sumon


Here I cannot help you. I have never used the driver, I use my own drivers.

I did not say you read it like an EEPROM. I meant is is unstructured "like" an EEPROM. With an EEPROM you setup the desired address and then read or write to the EEPROM. This is the same mechanism you will use with a low level driver. After you have initialized the SD card to put it into SPI mode, you will sent setup the address and read or write to the card.
_________________
Regards, Andrew

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



Joined: 19 Mar 2009
Posts: 25

View user's profile Send private message

MMC/SD use
PostPosted: Fri Jan 22, 2010 8:44 am     Reply with quote

You can get the abbreviated SD specification at www.sdcard.org

This will tell you how to use the card for low level storage and recovery. It is quite simple. The card has its own embedded controller so it isn't like an eeprom and you have to know the secret code to get things done. BTW you should look at writing to the PIC flash depending on how much data you have.

Andrew has a comprehensive SD driver kit that a real bargain. Due to the low price you have to decipher his example code to understand how to use it, but it is still a bargain. His drivers maintain a file system so anything you do can potentially be ported to a PC, and that is an extremely useful tool. If you are like me, and have little experience with the nuances of PC file systems, it takes some time to understand that part. The main issues I encountered were the need to sync the FAT tables on a regular basis (so the PC knows where the data is) and to include a NULL terminator in my file names.

I am using Andrew's drivers in a current project and it knocked a huge chunk of time out of the project. I went from scratching my head to a full blown PC compatible file system fully integrated into my application in less than a month. The main issue is that the SD Organization wants a couple of $K for a complete copy of the specification and then you still have to write and debug the code. Time is money. Money is money.

In my case I am saving the data in ascii format so when I read the file into a PC I can easily import it into a large number of applications such as Excel. This is a very powerful product design feature.
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