ombrastein
Joined: 14 Jul 2007 Posts: 7
|
mmcsd.c and fat.c |
Posted: Sat Jul 14, 2007 10:13 am |
|
|
Hello all
im using the 4.042 PCH compiler with 18F452 chip
Has anyone tried to use the drivers uplied with the PCH compiler for reading and writing to a mmcsd card using the fat system?
Im having problems getting the fat part to work properly and i am wondering what i could be doing wrong.
It initialises nicley, returns a 0 meaning GOOD EC.
Then i call mk_file to create a file, and this also returns 0, wich means no errors. But when i look at the card on a computer no file has been created.
Also whenever i try to call fatopen on either a file already created on the card with a PC or the file i just made with mk_file i get an error. it returns -1 or EOF if you will.
Thirdly i have tried to call mmcsd_flush_buffer my self after creating the file thinking it could be a problem with actualy flushing the data onto the card. WHen i do this i get a return value of 0x40 wich is suposed to mean "argument error". The problem there is that mmcsd_flush_buffer doesnt take any arguments....
Both the mmcsd.c and the fat.c is found in the driver folder and im asuming it has been tested and found to work properly. I realise its new features of the compiler and probably there are buggs here ...
this is what my code looks like:
Code: |
void main (){
int nRet;
FILE fTest;
FILE *pTestFile;
char cTest;
char sFileName[20] = "/test.txt";
char sFileName2[20] = "/made.txt";
char sPermission[5] = "r";
int pData[100];
int i;
delay_ms(1000);
// init();
//setup MMC
printf("\fInitsialising MMC\n\r");
delay_ms(1000);
nRet = 0xFF;
while(nRet != 0) {
nRet = fat_init();
if(nRet == 0){
printf("Init MMC successfull ( 0x%X ).\n\r",nRet);
delay_ms(1000);
}
else{
printf("Init MMC failed ( 0x%X ). Trying again in 3 sec.\n\r",nRet);
delay_ms(3000);
}
}
printf("Making file ( %s )\n\r",sFileName2);
nRet = mk_file(sFileName2);
printf("-> mk_file returned ( %X )\n\r",nRet);
nRet = mmcsd_flush_buffer();
printf("-> mmcsd_flush_buffer() returned ( %X )\r\n",nRet);
delay_ms(1000);
printf("Opening file ( %s ) with permission ( %s )\n\r",sFileName2,sPermission);
pTestFile = malloc(sizeof(FILE));
nRet = fatopen(sFileName2,sPermission,pTestFile);
printf("-> fatopen returned ( %X )\n\r",nRet);
printf("Printing file");
fatprintf(pTestFile);
|
and this is what i read in hyperterminal:
Code: |
Initsialising MMC
Init MMC successfull ( 0x00 ).
Making file ( /made.txt )
-> mk_file returned ( 00 )
-> mmcsd_flush_buffer() returned ( 40 )
Opening file ( /made.txt ) with permission ( r )
-> fatopen returned ( FF )
Printing file
|
Im trying to track the problem by stepping thru the drivers.
From what i can tell when i call the mmcsd_flush_buffer the command gets send properly
then the driver calls a function called mmcsd_get_r1 wich ofcourse is ment to get the response to the command from the MMC card.
This response is then 64 or 0x40 wich means argument error.
The comand that is beeing send is "WRITE_BLOCK" and the argument is the adress of the block to write. The adres that is send is: 2249512448
my MMC card is only 1 GB so that looks very odd.... the mmcsd_flush_buffer function does indeed try to flush somthing and the flag that the buffer has changed is set to TRUE.
Any help? Has anyone tried these drivers and gotten them working?
Hope somone can help me out here ... this is confusing ...
Last edited by ombrastein on Sat Jul 14, 2007 3:32 pm; edited 1 time in total |
|