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

read/write on mmc card with PIC18fxx problems!!!help me plz

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



Joined: 26 Apr 2011
Posts: 3
Location: Tunisia

View user's profile Send private message

read/write on mmc card with PIC18fxx problems!!!help me plz
PostPosted: Wed Apr 27, 2011 7:13 am     Reply with quote

Dear all,
I need very urgently to find out how to read and write on a mmc card memory. I'm running out of time and i need this to complete my project to take my engineering diploma, so can anyone please help me to get out from this problem. I'm really stuck.
I use ccs c compiler.
I find out that I should use the spi protocol. I tried to use some function such as "spi_write(value) " and "spi_read(value)", predefined on the ccs c compiler but I failed to make any results:(((

Help will be greatly appreciated.

Thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Wed Apr 27, 2011 9:14 am     Reply with quote

Several things you need to start with:
What voltage is your PIC?. If you are using a 5v PIC device, you _need_ a 3.3v to 5v converter device between the MMC card and the PIC. Resistor divider in the other direction. This needs to be sorted out _before_ you start to talk to the card....
Then, do you want to store the data as if the mmc card is just a memory device, or do you want to use it as a file system?. If the former, you need to look at mmc_spi.c. Understand that the card needs to be talked to in 512byte blocks. This handles this for you. To talk to a file system, you then need to look at fat.c. More complex.

Best Wishes
farhani123



Joined: 26 Apr 2011
Posts: 3
Location: Tunisia

View user's profile Send private message

PostPosted: Wed Apr 27, 2011 12:03 pm     Reply with quote

Thanks a lot T for this clarification:)
But if you don't mind i can't honestly make difference between "file system" and "memory device" but what I'm "dreaming" to do is that i want to read data from the rs232 port and save it in the mmc card. The first part i did it but I'm stuck in the mmc part. From other side i wish that i can find data that i stuck in the mmc card in a .txt file but i think it is too difficult to reach, isn't it??
farhani123



Joined: 26 Apr 2011
Posts: 3
Location: Tunisia

View user's profile Send private message

PostPosted: Wed Apr 27, 2011 4:28 pm     Reply with quote

I found the "mmc_spi" and the "mmcsd" drivers and I had tried to use functions such as "mmc_write_block(address, size, *ptr)" and "mmc_read_block(address, size, *ptr)".
I made: address=0x00,size=512 and ptr="hello", in order to write "hello" in the block of 512byte wich start from the address 0x00.
The problem is when I simulate this in Proteus isis and i use the spi debugger, I see strange code that the PIC18f4520 send to the mmc card("ff ff ff ff ff ff ff ff") which have nothing to do with the word I wish to send to the mmc. In addition, I found nothing on the mmc card when I read it with the function previously declared!!!!!
Have you, please, T any idea what is wrong with this??
Thanks in advance:)
Sergeant82d



Joined: 01 Nov 2009
Posts: 55
Location: Central Oklahoma

View user's profile Send private message

PostPosted: Wed Apr 27, 2011 7:46 pm     Reply with quote

Why not just use the example code and drivers which are included with the compiler?

in the /examples folder, ex_fat.c
and it includes two files from the /driver folder, fat.c & mmcsd.c

I am in the process of implementing an SD card into my project, and using these files it has been pretty easy to get it up and running.
Rod_O



Joined: 23 Sep 2011
Posts: 4

View user's profile Send private message

SD reading
PostPosted: Mon Sep 26, 2011 10:13 am     Reply with quote

Ttelmah wrote:
Several things you need to start with:
What voltage is your PIC?. If you are using a 5v PIC device, you _need_ a 3.3v to 5v converter device between the MMC card and the PIC. Resistor divider in the other direction. This needs to be sorted out _before_ you start to talk to the card....
Then, do you want to store the data as if the mmc card is just a memory device, or do you want to use it as a file system?. If the former, you need to look at mmc_spi.c. Understand that the card needs to be talked to in 512byte blocks. This handles this for you. To talk to a file system, you then need to look at fat.c. More complex.

Best Wishes


Hi Ttelmah,
Do you have an example code for the mmc_spi.c driver, I can't get a valid reading with it. It just shows 00 anywhere I read. I'm not using fat, I just want to use the SD to read and write raw data. (I'm using Proteus to simulate it).
Thanks for anything... in advance XD
Rodrigo
_________________
>Rod_O
temtronic



Joined: 01 Jul 2010
Posts: 9168
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 1:17 pm     Reply with quote

Also be aware that Proteus is FULL of bugs,errors, faulty logic, bad DRCs, etc. You're better off working with real hardware and using the examples CCS supplies!

AND

be sure to use the LF version of the PIC(low voltage) OR logic level translator chips btweeen the PIC and the MMC card !
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Sep 26, 2011 1:44 pm     Reply with quote

Are you locked in to this idea and not other for your project????

Confession - i have had a need for exactly or almost what you want to program yourself -- but buy it off the shelf for $25 all ready to go -
ie: capture text on a MICRO SD card up to 16GB in size.
see:

http://www.sparkfun.com/products/9530

NOTE: current delivery firmware in the product is HUGELY improved and SO EZ to use now that it is just about idiot proof too.

I use it to protect high value instrument capture data from other PIC controllers - in an automated instrument environment -as a backstop against a HOST PC crash while expensive, impossible to reproduce data is being delivered.


i think perhaps the "openlog" module is exactly what you are trying to design.
Rod_O



Joined: 23 Sep 2011
Posts: 4

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 3:50 pm     Reply with quote

I did it :D
I use Suky's library (SDCard_Hard.c)... Now I can read and write directly to SD cards in Proteus (I save the SD card image in a .mmc file, from where i can see - with winhex or notepad - the changes in the sd image file. Now i have to see if it works with big (>2GB) SD Cards.
And then maybe FAT system... but i dont need it right now.
Thanks everyone XD
...
Rod_O
_________________
>Rod_O
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