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

mmcsd.c + PIC24

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



Joined: 12 Nov 2007
Posts: 5

View user's profile Send private message

mmcsd.c + PIC24
PostPosted: Tue Feb 01, 2011 1:51 pm     Reply with quote

Hello fellows!

I'm trying to run the ex_mmcsd.c with a PIC24FJ but I always get the Could not init the MMC/SD!!!! message...

I've already checked my hardware connections and it's fine. But I have just one question about this, once the PIC's power supply is also 3v3, do I need to use the pull-up resistors?

The #use spi works with the PIC24 family?

My compiler version is 4.114

Just one more thing, I'm using a MicroSD with the SD adapter.

Here is my code:


Code:

/////////////////////////////////////////////////////////////////////////
////                      ex_mmcsd.c                                 ////
////                                                                 ////
//// Similar to ex_extee.c, an example that demonstrates             ////
//// writing and reading to an MMC/SD card.                          ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 2007 Custom Computer Services              ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////

//These settings are for the CCS PICEEC development kit which contains
//an MMC/SD connector.
#include <24FJ128GA010.h>
#fuses NOWDT, NOPROTECT
#use delay(internal=8M)

#use rs232(baud=9600, UART2, errors)

#include <stdlib.h> // for atoi32

//meda library, a compatable media library is required for FAT.
#use fast_io(g)
#define MMCSD_PIN_SCL     PIN_G6 //o
#define MMCSD_PIN_SDI     PIN_G7 //i
#define MMCSD_PIN_SDO     PIN_G8 //o
#define MMCSD_PIN_SELECT  PIN_D12 //o
#include <mmcsd.c>

#include <input.c>

void main(void)
{
   BYTE value, cmd;
   int32 address;

   printf("\r\n\nex_mmcsd.c\r\n\n");
   
   if (mmcsd_init())
   {
      printf("Could not init the MMC/SD!!!!");
      while(TRUE);
   }
   
   do {
      do {
         printf("\r\nRead or Write: ");
         cmd=getc();
         cmd=toupper(cmd);
         putc(cmd);
      } while ( (cmd!='R') && (cmd!='W') );

      printf("\n\rLocation: ");

      address = gethex();
      address = (address<<8)+gethex();

      if(cmd=='R')
      { 
         mmcsd_read_byte(address, &value);
         printf("\r\nValue: %X\r\n", value);
      }

      if(cmd=='W') {
         printf("\r\nNew value: ");
         value = gethex();
         printf("\n\r");
         mmcsd_write_byte(address, value);
         mmcsd_flush_buffer();
      }
   } while (TRUE);   
}
baltazar



Joined: 12 Nov 2007
Posts: 5

View user's profile Send private message

PostPosted: Wed Feb 02, 2011 10:07 am     Reply with quote

I've tried to put 10k pull-up resistors in SS, SDO and SDI pins, but it's still not working...

I'm pretty sure that there is something wrong with the mmcsd library and PIC24 family, but I can't find the problem.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Feb 02, 2011 10:21 am     Reply with quote

Pull-up resistors are required by MMC and SD card specification for those card signals not driven by the processor (SDI and contacts unused in SPI mode). But they are very unlikely a reason for the protocol to fail.

Most likely, either problems with the SPI setup or specific PCD bugs, that causes failure of some internal library operation, e.g. block calculations.

Basically, I see no other option than tracing the library action with a hardware debugger (preferably MPLAB), identify the problems and change the code accordingly.

#use spi won't allow some necessary operations, e.g. SPI frequency change. I never used it with PCD.
baltazar



Joined: 12 Nov 2007
Posts: 5

View user's profile Send private message

PostPosted: Wed Feb 02, 2011 10:57 am     Reply with quote

Hi FvM!

I did what you said:

Quote:

Basically, I see no other option than tracing the library action with a hardware debugger (preferably MPLAB), identify the problems and change the code accordingly.


and I found something interesting...

I'm working on it by now, but seems that, for some reason, the library identifies the SD card as a MMC card and because of that many functions does not work as they should do.

To be more specific, the "identification problem" occurs in this fragment of the mmcsd.c library:

Code:

   /* an mmc will return an 0x04 here */
   if(r1 == 0x04)
      g_card_type = MMC;
   else
      g_card_type = SD;


If I force the library to accept the SD format as a card type, then it works! At least it seems to work until now...

Do you have any idea about this "strange behavior"?

Thanks for the help!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Feb 02, 2011 11:42 am     Reply with quote

That's faster success than expectable.

There's no understandable reason, why ACMD41 is answered by a SD card with the illegal command bit.
So something must be wrong. I noticed that the mmcsd driver doesn't reduce the SPI clock during identification
phase as required by the standard. Are you possibly clocking the card too fast?

However, I have a good SD card driver from brushelectronics.com and don't need to fix the rather
limited mmcsd code.

Good luck!
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