View previous topic :: View next topic |
Author |
Message |
yoonees
Joined: 29 Jun 2009 Posts: 12
|
Problem ex_fat.c unable to create file/directory on MMC card |
Posted: Wed Jul 01, 2009 4:18 am |
|
|
Hi all,
I'm having some problems getting ex_fat.c from the PICC Examples folder to work. Here are the details:
Compiler version: PCWHD 4.057
PIC processor: PIC18F4550
Clock frequency: 20MHz external oscillator
PIC running at 5V
PIC driver: mmcsd.c from the CCS library
Connection of MMC card to PIC is similar to this site:
http://www.captain.at/electronics/pic-mmc/mmc.png
However, my circuit has a 10K pull-up resistor from the DataOut of the MMC card.
The CS, DataIn, DataOut and CLK are connected as follows:
CS ---> RB3
DataIn ---> RC7
CLK ---> RB1
DataOut ---> RB0
I modified the codes in ex_fat.c and mmcsd.c to this:
Code: | #define MMCSD_PIN_SCL PIN_B1 //o
#define MMCSD_PIN_SDI PIN_B0 //i
#define MMCSD_PIN_SDO PIN_C7 //o
#define MMCSD_PIN_SELECT PIN_B3 //o |
As I'm using a 128MB MMC card from Kingston, therefore, I'm using FAT16. From fat.c:
Code: | /// Define your FAT type here ///
#define FAT16
//#define FAT32 |
The output at HyperTerminal is as follows:
Code: | /> mkdir Test
Making directory '/Test/': |
It is supposed to print 'OK' if the creation of the directory is successful or 'Error creating file' if the creation of the directory failed. However, in my case, it just stops at 'Making directory '/Test/': '
Any ideas what went wrong? Thank you so much! |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jul 01, 2009 3:01 pm |
|
|
MMC and SD cards are much easier to interface when your PIC is running at the same 3.3V as the memory cards. The circuit as posted has been discussed several times before on this forum and many people had troubles to get it working. Main problem is often that the logic high voltage of the Data Out from the memory card is not high enough to be seen as 'high' by the PIC. My electronics knowledge is not good enough to say if a 10k pull up will solve this problem.
You already have a 3.3V regulator, so save some money and parts by using this voltage for the PIC. The voltage dividers can then be ridden of too. You'll have to use the PIC18LF variant of the processor to support this low voltage.
If you do insist on using the 5V supply, then you might get it to work by ensuring the Data Out pin is connected to a normal digital TTL input of the PIC. Pin B0 used as hardware SPI input pin is Schmitt Trigger type and has a too high 'high' voltage level of 0.8 * Vdd = 4V.
Standard TTL has a Vih of 0.25Vdd + 0.8V = 2.25V
Another improvement is reducing the PIC power supply voltage to 4.2V, this is the lowest voltage guaranteed for the standard PIC18. For example insert a diode in series with the power supply line for a 0.6V voltage drop.
Many other things can be wrong, but without code example this is hard to tell. |
|
|
yoonees
Joined: 29 Jun 2009 Posts: 12
|
|
Posted: Wed Jul 01, 2009 9:45 pm |
|
|
Hi ckielstra,
Thank you so much for replying!
I'm sorry I forgot to mention in the previous post that the codes are from the PICC/Examples folder (ex_fat.c or fat_ex_shell.c). I just modified the codes to work with PIC18F4550. As this is a public forum, I did not post up the codes due to copyright issues. However, if you still like to have a look at the codes, do let me know and I will send it to you.
As for the hardware, I managed to get it working with ex_mmcsd.c code from the Examples folder. I'm just not sure why it could not create a directory/file using ex_fat.c.
Having said that, I will give the PIC18LF variant a try and will post up the results soon.
Thank you once again
***UPDATE***
I've tried using PIC18LF4550. Unfortunately, the results are still the same
Code: | />mkdir Test
Making directory '/Test/': |
Could it possible be due to memory or RAM issues? |
|
|
yoonees
Joined: 29 Jun 2009 Posts: 12
|
|
Posted: Mon Jul 13, 2009 1:31 am |
|
|
Hi guys,
I'm still struggling to get this to work. Any help/ideas/suggestions would be greatly appreciated!
My main objective is to be able to use the microcontroller as a datalogger and the MMC as a storage device. I would like the data to be in FAT16 format so that I can access the data from a PC.
Thanks!
***UPDATE***
IT WORKS!
I just realized that I need to format the MMC card using the format function provided in the source code. I am now able to read/write on the MMC card. HOWEVER, when I try accessing the MMC card using a PC, it shows an empty directory (although I have created some text files and directories on the MMC card using the microcontroller). But when I checked the properties of the MMC card, it shows that there are some used space. Any ideas how to display the contents of the MMC card on the PC? |
|
|
Guest
|
|
Posted: Mon Jul 13, 2009 5:58 pm |
|
|
Get the info coming!
I am soldering my SD card adapter and going to test it soon.
So you are simply using ex_fat.c connected to hyperterminal?
Code: | FormatMedia(524288); |
to format a 512MB
in you case you have 128MB and you wrote
Code: | FormatMedia(131072); |
I will try to get the code running using a SD card.
Thanks for sharing. |
|
|
yoonees
Joined: 29 Jun 2009 Posts: 12
|
|
Posted: Tue Jul 14, 2009 2:32 am |
|
|
Anonymous wrote: | So you are simply using ex_fat.c connected to hyperterminal? |
Yes. Don't forget to change the CS, DataIn, DataOut and CLK pins on ex_fat.c and mmcsd.c to suit your microcontroller type.
Anonymous wrote: | Code: | FormatMedia(524288); |
to format a 512MB
in you case you have 128MB and you wrote
Code: | FormatMedia(131072); |
|
When you run ex_fat.c, this is what you will see in HyperTerminal when you type "help" (without quotes):
Code: | del filename --- Deletes the file
make filename --- Creates an empty file
append filename string --- Appends string to the end of the file
cd dir --- Change the working directory
dir --- Shows the contents of the directory
cat filename --- Displays content of file
tail filename --- Displays the last 80 characters of file
mkdir dir --- Create a directory
rmdir dir --- Deletes the directory
format size --- Format card. (Example: 'format 5524288' formats a 512MB card)
help You are here
Put a parameter in quotes if it has spaces |
From there, I just type
Anonymous wrote: | I will try to get the code running using a SD card.
Thanks for sharing. |
I'm happy to share
Please do share your results once you have completed your tests. Thanks! |
|
|
Guest
|
|
Posted: Thu Jul 16, 2009 5:57 pm |
|
|
I just tested ex_fat.c formated my card, wrote data into multiple files. I was able to see them using dir and opening them to check.
When I plug the card into the computer, I can not see anything on the card. It does take some space 38kb and when I plug it back it, I can still see all the stuff I wrote earlier.
so it is in the MBR?
Master Boot Record
I will check that out... |
|
|
robomaniac
Joined: 16 Jul 2009 Posts: 19 Location: Sherbrooke, Québec, Canada
|
|
Posted: Thu Jul 16, 2009 6:26 pm |
|
|
When I try to format my 8MB SD card, it does not work:
Code: | /> format 8192
Formatting media (size=8192): Error formatting media |
1024 * 8 = 8192
I can still write stuff on it.
I can format my 2Go card with no problem.
Making directory is also not possible, it takes a lot of time then it said NO. _________________ Jérôme Demers
www.jeromedemers.com |
|
|
yoonees
Joined: 29 Jun 2009 Posts: 12
|
|
Posted: Thu Jul 16, 2009 8:51 pm |
|
|
robomaniac wrote: | When I try to format my 8MB SD card, it does not work:
Code: | /> format 8192
Formatting media (size=8192): Error formatting media |
1024 * 8 = 8192
I can still write stuff on it.
I can format my 2Go card with no problem.
Making directory is also not possible, it takes a lot of time then it said NO. |
Hi Jérôme,
Thanks for replying!
Are you using FAT16 or FAT32?
I think the reason why you could not format your 8MB SD card is because FAT16 can only be used for media with capacities from 16MB to 2GB. FAT32 is for larger media that can't use FAT16. For 8MB SD card, you have to use FAT12. However, this option is not provided in fat.c. |
|
|
robomaniac
Joined: 16 Jul 2009 Posts: 19 Location: Sherbrooke, Québec, Canada
|
|
Posted: Fri Jul 17, 2009 6:39 am |
|
|
hello,
After reading the fat.c file I realise that 8Mb was not there!
And I did not define FAT32 in my code. I will try that.
I will play with my 2Go instead.
Thanks! _________________ Jérôme Demers
www.jeromedemers.com |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Fri Jul 17, 2009 8:19 pm |
|
|
robomaniac wrote: | hello,
After reading the fat.c file I realise that 8Mb was not there!
And I did not define FAT32 in my code. I will try that.
I will play with my 2Go instead.
Thanks! |
If you are going to use a 2GB card and can live with the limitation of a maximum of 512 files in the root directory, then FAT16 is more efficient to implement on a PIC _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
evsource
Joined: 21 Nov 2006 Posts: 129
|
|
Posted: Mon Feb 28, 2011 12:19 pm |
|
|
Anonymous wrote: | I just tested ex_fat.c formated my card, wrote data into multiple files. I was able to see them using dir and opening them to check.
When I plug the card into the computer, I can not see anything on the card. It does take some space 38kb and when I plug it back it, I can still see all the stuff I wrote earlier.
so it is in the MBR?
Master Boot Record
I will check that out... |
I see this problem all over the forum, but surprisingly, no resolutions. Did you ever figure this out? |
|
|
|