|
|
View previous topic :: View next topic |
Author |
Message |
Jody
Joined: 08 Sep 2006 Posts: 182
|
SD/MMC card problem (Tomi driver) |
Posted: Fri May 20, 2011 3:01 am |
|
|
Hello,
compiler: 4.119
pic: 18F8722
clock:40MHz
I have connected the SD card, at 3.3V and with resistor divider so far so good. When I do a MMC init.. it return oke...InitFat is oke...
I can ask the Label frrom the SD card....
Reading the SD card is oke.. I can display the files and the label of the SD card.
But... when I want to open a file to write it, it fails.. It keeps on communicating with the SD card but never return... I have found that there is something wrong with the FindDIrEntry but What ever I try I can't get it fixed.....
If anyone wants I will post the driver code...
But here is mine test code...
Regards,
Jody
Code: | #include "C:\MentorProjects\Teugel_Trek_Meter\PIC_CODE\MMC_PIC18F8722\MMC.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <MyMMCFAT32.h>
#include <MyMMCFAT32.c>
short one_tenth_fl;
short one_sec_fl;
char f,filename[20],res,i,c;
char gfilename[12];
char msg[50], shour[4], sminutes[4], sseconds[4],stenth[4], sTeugelkracht_links[4], sTeugelkracht_rechts[4];
char sPotmeter_links[4], sPotmeter_rechts[4], sres[4];
char dubbelpunt[3], minnetje[3], afsluiting[7], meting_naam[12], punt_txt[4];
#define LED1 pin_E3
#define LED2 pin_E2
void main()
{
setup_adc_ports(AN0_TO_AN3|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_20);
// setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
//setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
output_low(LED1);
output_low(LED2);
printf("\r\nversie 1.0\r\n");
while(1)
{
if(MMCInit() == MMC_OK)
{
printf("MMC initialized\r\n");
InitFAT();
strcpy(filename,"");
f = InitList(filename);
if(f & MMC_ERROR)
printf("Error");
else
{
do
{
res = ListFiles(f);
for(i=0;i<res;i++)
{
printf("i = %d\n",i);
printf("res = %d\n",res);
printf(FileList[i].name);
if(FileList[i].isDir)
{
printf("filelist");
printf("\\\r\n");//a "\" with row break
}
else
{
printf("\r\n");
}
}
} while(NextPage(f) == MMC_OK);
CloseList(f); // frees the file, but the list is
} // still there...
strcpy(filename,FileList[0].shortName);
printf("filename = %s",filename);
f = fopen(filename,'r'); // open file for reading
printf("file open");
if((f & MMC_ERROR) == 0) // No error, same as
{ // if(f < MAXFILES)
while(fgetch(&c,f) == MMC_OK)
printf(c);
fclose(f);
}
else if(f == MMC_NOT_FOUND)
printf("1st file in list was probebly a dir");
else
printf("Other error\r\n");
while(TRUE)
{
//fputstring(msg,f);
printf("Loop forever, program is finished\n\r");
delay_ms(1000);
}
}
else
printf("MMC init failed!\r\n");
delay_ms(1000);
printf("Trying once more..\r\n");
}
}
|
|
|
|
MikeW
Joined: 15 Sep 2003 Posts: 184 Location: Warrington UK
|
|
Posted: Fri May 20, 2011 7:24 am |
|
|
post the driver just in case |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 20, 2011 5:41 pm |
|
|
If it's the same Tomi code as in the CCS code library, then he should just
post a link to it. Don't post the whole code. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat May 21, 2011 9:10 am |
|
|
Code: | setup_spi2(SPI_SS_DISABLED); | SPI defaults to Master mode. Disabling the Slave Select pin on a Master results in an invalid configuration for SPI2. To disable SPI2 use:
What size is your card and how is it formatted? FAT32 or FAT16? FAT16 is much faster than FAT32 on the PIC processors but limited up to 2GB cards.
See also this comment from another thread: Pret wrote: | In Tomi's code and also in most of FAT implementations on small controllers, there is a constraint regarding sectors per cluster. Only one sector is allowed per cluster.
You can format a disk with this contraint in command line. You do not need third party software. Just type in cmd "format i: /A:512". I could not format disks smaller than 64M as FAT32. |
|
|
|
|
|
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
|