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 CCS Technical Support

memory size for MMC /SD cards

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



Joined: 29 May 2008
Posts: 3
Location: BEIRUT

View user's profile Send private message Send e-mail Visit poster's website AIM Address ICQ Number

memory size for MMC /SD cards
PostPosted: Fri May 30, 2008 8:32 am     Reply with quote

I am working on microSd nokia 256M .I use the library of mmcsd.c and the ex_mmcsd.c but I replace pic18f67j60 with pic18f252 and also the crystal 25M with 8M.
The mmcsd_init() works correctly,but I am reading the bytes of address 0000 till 3000 .It seems that value is always 00 .
What is the problem here???????
Please How can I know the memory size of My microSD cards?!...
does the mmcsd_init() function depends on the type of SD Card (sandisk , nokia ,kingston , etc....)

thanks !
maher[/b]
ckielstra



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

View user's profile Send private message

PostPosted: Fri May 30, 2008 9:56 am     Reply with quote

Quote:
Please How can I know the memory size of My microSD cards?!...
The card size is in the card's CSD register. The CCS library provides a function showing all the CSD values but then you still have to do some calculations to get the size in bytes.

Below is a function showing the card size. It should work for both MMC and SD cards.
I modified my code to use the card read functions from mmcsd.c
Code:
// make sure to include mmcsd.c before this routine.

MMCSD_err mmcsd_print_card_size()

   int8 CsdBuf[16];
   int8 i;
   int8 r1;
   int8 ReadBlockLen;
   int16 C_Size;
   int8 C_Size_Mult;
   int8 Multiplier;

   mmcsd_select();   
   mmcsd_send_cmd(SEND_CSD, 0);
   r1 = mmcsd_get_r1();
   if(r1 != MMCSD_GOODEC)
   {
      mmcsd_deselect();
      return r1;
   }
   
   r1 = mmcsd_wait_for_token(DATA_START_TOKEN);
   if(r1 != MMCSD_GOODEC)
   {
      mmcsd_deselect();
      return r1;
   }

   for(i = 0; i < 16; i++)
      CsdBuf[i] = spi_xfer(mmcsd_spi, 0xFF);
   mmcsd_deselect();

   ReadBlockLen = CsdBuf[5] & 0x0F;
   C_Size =  ((int16)(CsdBuf[6] & 0x03) << 10)
           | ((int16)(CsdBuf[7]) << 2)
           | ((CsdBuf[8] & 0b11000000) >> 6);
   C_Size_Mult = ((CsdBuf[9] & 0b00000011) << 1)
           | ((CsdBuf[10] & 0b10000000) >> 7);

   Multiplier = ReadBlockLen + C_Size_Mult + 2;
   MMC_Size = ((int32)(C_Size + 1)) << Multiplier;
   
   printf("Size = %lu bytes.\r\n", MMC_Size);

   return r1;
}


If the above function shows a correct size than you know the communication with the card is working correctly.

Note: Using this function on several cards I noticed that several 64Mb cards have different sizes. Even the same brand but bought a few years later has a slightly different size.
maher



Joined: 29 May 2008
Posts: 3
Location: BEIRUT

View user's profile Send private message Send e-mail Visit poster's website AIM Address ICQ Number

PostPosted: Mon Jun 02, 2008 3:28 am     Reply with quote

I've tried the mmcsd_print_card_size() function .The result always return "4" .It doesn't care , I will fix this problem later .But I need to fix the main problem which is "the result of reading the bytes of address 0000 till 3000 is always 00 " .


Note that the hardware connection is OK since the mmc_init() function works properly if and only if the mmc card is in its socket .
Also , I 've tested the SPI pins .They are varying when mmc_init() and stop varying when mmcsd_read_byte() . Confused
So, I guess that the problem is using the mmcsd.c read/write functions, So my questions :

1) Does the the memory size of the mmc card (256M) freeze the mmcsd_read_byte() from functioning ?!...

2) Does the the mmc_type (nokia microSD) freeze the mmcsd_read_byte() from functioning ?!...

Thank you a lot.
Best Regards Sad
ckielstra



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

View user's profile Send private message

PostPosted: Mon Jun 02, 2008 12:09 pm     Reply with quote

Quote:
I've tried the mmcsd_print_card_size() function .The result always return "4" .
0x04 == MMCSD_ILLEGAL_CMD
The code is a modification of my original code and I didn't test it so it might contain a bug. Embarassed
Another thing is that the CCS driver mentions this command not being supported by MMC cards which I think is strange as I can't find any reference to this in the standard documents I have.

I don't have the hardware here to test the code and don't know if I can test it soon so you are on your own here.

One thing we can learn from the 0x04 response is that the communication with the card is (partially) working otherwise you would have received a 0x80 (timeout) or 0x40 (parameter error) code.

You are constantly performing the same test and banging your head against the wall. It is possible the error is in a different area than where you are looking now, therefore I suggest you try some other tests. For example try writing to address 0x0000 and reading from this same address. Use address 0x0000 because this will prevent possible problems with address byte mixing (big endian versus little endian).
maher



Joined: 29 May 2008
Posts: 3
Location: BEIRUT

View user's profile Send private message Send e-mail Visit poster's website AIM Address ICQ Number

PostPosted: Mon Jun 02, 2008 11:46 pm     Reply with quote

Hi again.
May u please answer me the 2 previous questions Wink
With respect to hardware I'm sure about it because the mmc_init() function works only when I've add two pull_up resistors on SDI and SDO
and here is my simple code :
Code:



#include <18F252.h>
#fuses NOWDT, HS, NOPROTECT
#use delay(clock=8000000)

#use rs232(baud=9600, XMIT=PIN_C6,RCV=PIN_C7,BITS=8,parity=N)

#include <stdlib.h> // for atoi32

//meda library, a compatable media library is required for FAT.
#use fast_io(c)
#define MMCSD_PIN_SCL     PIN_C3 //o
#define MMCSD_PIN_SDI     PIN_C4 //i
#define MMCSD_PIN_SDO     PIN_C5 //o
#define MMCSD_PIN_SELECT  PIN_C2 //o
//////////////////////////////////////////////////
#include <mmcsd.c>

#include <input.c>
int sa;

void main(void)
{
   BYTE value;
   int32 address;
   set_tris_c(0x90);
   printf("\r\n\nex_mmcsd.c\r\n\n");
   
   if (mmcsd_init())
   {
      printf("Could not init the MMC/SD!!!!");
      while(TRUE);
   }
   while(TRUE)
      {
         sa=mmcsd_read_byte(address++, &value);
         printf("\r\nValue: %X address: %lu result: %X", value,address,sa);
         delay_ms(500);       
         //  mmcsd_write_byte(address,77);
         mmcsd_print_cid();
         mmcsd_get_r1();     
      }
}


Please ckielstra , I want to fix this problem in order to be getting started with mmc functions .
And thank u a lot Very Happy
ckielstra



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

View user's profile Send private message

PostPosted: Tue Jun 03, 2008 5:04 pm     Reply with quote

maher wrote:
May u please answer me the 2 previous questions Wink

Quote:
1) Does the the memory size of the mmc card (256M) freeze the mmcsd_read_byte() from functioning ?!...
The memory size shouldn't affect the reading. Only exception are the newer HS-MMC cards with a capacity >2Gb which are not supported by the current mmcsd.c driver.
Quote:
2) Does the the mmc_type (nokia microSD) freeze the mmcsd_read_byte() from functioning ?!...
I don't know. I don't have this card so can't test it but it seems highly unlikely.

mmcsd.c contains a bug:
Code:
#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, stream=mmcsd_spi)
The parameter for the sampling edge is missing meaning this will default to SAMPLE_FALL (according to the help file), equivalent to SPI mode 2. This is an invalid configuration for MMC cards who are supposed to work in SPI mode 0 or 3.

The problem is not easy to fix as the #use SPI directive is new in the CCS compiler and in testing it I discovered a lot of bugs. In v4.072 the only way to make it compile correctly was to declare the correct sampling edge and forcing it to use the hardware SPI module:
Code:
#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, SAMPLE_RISE, stream=mmcsd_spi, FORCE_HW)


Which compiler version are you using?
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