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

Need help about interface with MMC card 18F4620

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



Joined: 13 Aug 2011
Posts: 9
Location: Viet Nam

View user's profile Send private message

Need help about interface with MMC card 18F4620
PostPosted: Fri Aug 26, 2011 12:07 am     Reply with quote

Sad Hello all!
I'm a beginner of CCS. I had used "mmc_spi.c" from CCS library and used the function mmc_init() but it always respond "1"= failed! Can somebody give me the reason and solve this problem for me? Thank all. <Sorry about my English>
Here is my simple code
Code:

#include "18F4620.h"
#fuses HS,NOWDT,NOPROTECT,NODEBUG
#use delay(clock=4000000)

//#include "input.c"
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
//#include "input.c"
#include "mmc_spi.c"
#include <stdio.h>

void main()
{
   BYTE value,cmd;
   int32 address;
   int1 check;
  // int8 i;

   printf("\r\nCheck MMC Card\n\r");
   check=mmc_init();

   if(check==1)
   {
      printf("Check Card Failed\n\r");
   }

   if(check==0)
   {
      printf("Check Card Sucessful\n\r");     
   }
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Aug 26, 2011 3:47 am     Reply with quote

Many things can be wrong, but here is at least one error to fix:
Code:
   int1 check;
...
   check=mmc_init();
If you look in the file mmc_spi.c you will see the mmc_init function returns an enum of the type MMC_EC. This will not fit into an int1 !

Change your code to something like:
Code:
#include "18F4620.h"
#fuses HS,NOWDT,NOPROTECT,NODEBUG
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS)

#include "mmc_spi.c"

void main()
{
   MMC_EC check;

   printf("\r\nCheck MMC Card\n\r");
   check = mmc_init();

   if (check == MMC_EC_OK)
   {
      printf("Check Card Sucessful\n\r");     
   }
   else
   {
      printf("Check Card Failed\n\r");
   }
   for(;;);
}


Note that I also added the ERRORS directive to the '#use rs232' line, this will reset some errors in the hardware UART when necessary.
mrYalamen



Joined: 13 Aug 2011
Posts: 9
Location: Viet Nam

View user's profile Send private message

PostPosted: Fri Aug 26, 2011 9:21 am     Reply with quote

Thanks a lot for your helpful! Just because I'm too negligent. I only see the function that does not care about the return values and void main's details. I'll try it more!
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