|
|
View previous topic :: View next topic |
Author |
Message |
huthaifa85
Joined: 28 Jun 2008 Posts: 5
|
8GB MMC card .... Nothing on the MMC after running ... |
Posted: Sat Nov 09, 2013 11:43 am |
|
|
Hello
I am trying to copy a string on a MMC card of size 8 GB, First I have formatted it Fat32, allocation unit size:32 KB ...
I am using a MMC module:
http://www.adafruit.com/adablog/wp-content/uploads/2011/07/fetch-14.jpg
connected to my PIC18f452 ...
The code seems running and even the indicators I have added work in the correct order.. But every time I check the MMC card after running the project I find nothing on it ....
Here is my code:
Code: |
#include <18F452.h>
#include <string.h>
#include <MMC_SPI_FAT32.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,NOLVP,NOCPD
#use delay(clock=20M)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include "MMC_SPI_FAT32.c"
void main(){
char f,gfilename[8],c;
char msg[64];
int cart;
output_high(pin_a0);
delay_ms(1000);
output_low(pin_a0);
delay_ms(1000);
output_high(pin_a0);
delay_ms(1000);
output_low(pin_a0);
while(true)
{
if(MMCInit() == MMC_OK) {
output_high(pin_a0);
delay_ms(2000);
InitFAT();
strcpy(gfilename,"test.txt");
f = fopen(gfilename,'a');
delay_ms(1000);
if (f & MMC_ERROR)
{
output_high(pin_a2);
if(f == MMC_NO_CARD_INSERTED)
output_high(pin_a2);
else if(f == MMC_MAX_FILES_REACHED)
output_high(pin_a2);
}
else
{
strcpy(msg,"aaaa");
fputstring(msg,f);
printf(msg);
fclose(f);
delay_ms(100);
while (MMCInit() == MMC_OK)
{
output_high(pin_a1);
}
}
}
}
}
|
Hope someone can help me !
Thanks in advance |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
Posted: Sat Nov 09, 2013 12:26 pm |
|
|
Anything over 2GB (except a few oddities), is SDHC, not SD. The CCS code only supports SD, not SDHC....
Best Wishes |
|
|
huthaifa85
Joined: 28 Jun 2008 Posts: 5
|
|
Posted: Sat Nov 09, 2013 12:38 pm |
|
|
So If I change it to 2 GB, you think that this code will be more than enough to do the job ???? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
Posted: Sat Nov 09, 2013 2:16 pm |
|
|
No...
Without looking very far, how long is the string "test.txt" (hint, strings have a null terminator character).
I'm sure there are other problems. |
|
|
huthaifa85
Joined: 28 Jun 2008 Posts: 5
|
|
Posted: Sat Nov 09, 2013 3:58 pm |
|
|
Like what ?
I have summarized the code to this form:
Code: |
#include <18F452.h>
#include <string.h>
#include <MMC_SPI_FAT32.h>
#include "MMC_SPI_FAT32.c"
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,NOLVP,NOCPD
#use delay(clock=20M)
void main()
{
char f,gfilename[20];
char msg[64];
output_high(pin_a0);
delay_ms(1000);
output_low(pin_a0);
delay_ms(1000);
output_high(pin_a0);
delay_ms(1000);
output_low(pin_a0);
while(true)
{
if(MMCInit() == MMC_OK) {
output_high(pin_a1);
delay_ms(2000);
InitFAT();
strcpy(gfilename,"test.txt");
f = fopen(gfilename,'a');
delay_ms(1000);
strcpy(msg,"aaaa");
fputstring(msg,f);
printf(msg);
fclose(f);
delay_ms(100);
while (MMCInit() == MMC_OK)
{
output_high(pin_a2);
}
}
}
}
} |
Now, the response is the same with and without the MMC .. LED a1 is ON!
Is there something else to consider ?
better library ... ?
Please Help ! |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sat Nov 09, 2013 4:26 pm |
|
|
How do you know you even opened the file successfully?
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
huthaifa85
Joined: 28 Jun 2008 Posts: 5
|
|
Posted: Sat Nov 09, 2013 6:56 pm |
|
|
I have added the indicators to show what is going one while running.. So that:
Code: |
if(MMCInit() == MMC_OK) {
output_high(pin_a1);
|
The LED should not turn one unless the condition is OK ... What I cant understand is that this condition is true with and without a MMC in the socket !
So thats Why I am confused ...
Ideas ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
Posted: Sun Nov 10, 2013 9:09 am |
|
|
Lets go through some things:
First, the code as written, does not test for a card. It expect _you_ to do this. The CD connection on your adapter, shorts to ground, when there is a card in the unit. This needs to have a pull up resistor, and be wired to your processor, and be tested for being 'low', before you start trying to talk to the card.
Then the code requires you to tell it about your hardware setup. There is a section after the initial comments, where you either need to define 'MMC_SPI_SOFTWARE', and tell it what pins you are using, or remove this define, and use the hardware pins. It will not work, till the setup matches your hardware.
General comment, add 'ERRORS' to your RS232 definition. This should (must...) always be present when using the hardware RS232, unless _you_ write code to handle the error states yourself. Without this the RS232 can become hung. Since you are not using the RS232, won't matter, but it is waiting to catch you later.
Then you need to ensure that the pins used for your SPI setup, are available for you to use. So things like analog ports turned off (for 90% of compiler versions this is done for you, but things like CCP ports, timer oscillators etc., are _not_ turned off on many chips...).
You need to be very careful how the card is formatted. Most of the standard CCS code, won't handle cards with an MBR. It requires cards with the 'superfloppy' format that doesn't have this. Not sure whether the fats32 driver you are using fixes this or not.
There is a fix for the standard CCS drivers at:
<http://www.ccsinfo.com/forum/viewtopic.php?t=43402>
This also has a link to the other bugfix needed for the standard drivers.
At least you have a 5v adapter board that has a chance of working...
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Nov 10, 2013 9:12 am |
|
|
MMCInit() will only return MMC_OK when it reads a return code with all zeroes. When you have no card inserted but the error is not detected then this means you have a hardware error.
On the website where you bought your interface board from there is a schematic:
https://github.com/adafruit/MicroSD-breakout-board/blob/master/usdbreakout.png
From this I see one major problem, there are no pull-up resistors on the data lines. This is especially important for the Data_Out from the board to your PIC as this line starts in 'open collector' mode, that is, it does not provide current by itself for the first few commands. Without the pull-up resistor your used FAT driver will read all zeroes and says the init is OK.
A 100k pull-up will do.
Even better to add 100k pull-up to CS, CLK and DI as well. This will give the lines a defined value on startup when the PIC pins are still configured as inputs.
Another problem with your interface board is that it doesn't convert the 3.3V DO line to 5V. This means you can not use the hardware SPI. The hardware SPI inputs are of the Schmitt Trigger type and require a minimum High voltage of: 0.8 * Vdd = 0.8 * 5V = 4.0V
The work around is to use software SPI, then the PIC input becomes a normal TTL input with a High for everything above 2V. Only downside is that software SPI is slower. Software SPI is the default setting in the FAT library you are using.
Last edited by ckielstra on Sun Nov 10, 2013 10:00 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19569
|
|
Posted: Sun Nov 10, 2013 9:40 am |
|
|
but (of course) you need to make sure the PIC line you are using for the input, does have TTL buffers not Schmitt buffers. Data sheet.
I must admit I assumed anyone selling a 5v breakout board, would have properly buffered the lines.
The DO line not being buffered, can float low, so can give '00000000' if read without a card, which would then be seen as OK.... |
|
|
huthaifa85
Joined: 28 Jun 2008 Posts: 5
|
|
Posted: Mon Nov 11, 2013 6:49 am |
|
|
Thanks .. I will try to modify my code according to your comments .. |
|
|
|
|
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
|