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

MMC help!!!

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



Joined: 30 Jan 2007
Posts: 56
Location: Viana do Castelo - Portugal

View user's profile Send private message

MMC help!!!
PostPosted: Tue Feb 27, 2007 5:32 pm     Reply with quote

Hi

I need write some values of 24bits adc on MMC.
I don't know how can start with MMC. Embarassed
I'm looking a simple example for start.

Thanks
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Feb 27, 2007 9:38 pm     Reply with quote

You can download hardware reference designs on my site for interfacing an SD/MMC card to a PIC. I sell CCS implementations of SD/MMC card drivers and SD/MMC file system if this is of interest.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
joven



Joined: 30 Jan 2007
Posts: 56
Location: Viana do Castelo - Portugal

View user's profile Send private message

PostPosted: Wed Feb 28, 2007 5:19 am     Reply with quote

I'm thinking using the driver of CCS, but they don't have any example.
ckielstra



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

View user's profile Send private message

PostPosted: Wed Feb 28, 2007 7:06 am     Reply with quote

joven wrote:
I'm thinking using the driver of CCS, but they don't have any example.
The CCS driver is not very difficult to use, have a look at the code and create your own example. If you can't get it to work, than post your code and we will have a look.

Just a few remarks:
- Use a PIC18 processor if possible as it will save you a lot of problems. Data has to be written to the MMC card in blocks of 512 bytes, the PIC16 processors don't have enough RAM to support this.
- Have your processor run at the same voltage as the MMC card, i.e. 3.0V or 3.3V. These lower voltages are no problem for most newer PIC models, it saves you an extra regulator and the electronics for voltage level adaptation. Many schematics you will find on the web with a processor at 5V have design flaws regarding this respect. Again, save yourself wasting time by not making this mistake.
- The CCS driver is a good starting point, it looks much better than most other drivers I've seen on this forum.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Feb 28, 2007 7:28 am     Reply with quote

ckielstra wrote:

- Have your processor run at the same voltage as the MMC card, i.e. 3.0V or 3.3V. These lower voltages are no problem for most newer PIC models, it saves you an extra regulator and the electronics for voltage level adaptation. Many schematics you will find on the web with a processor at 5V have design flaws regarding this respect. Again, save yourself wasting time by not making this mistake.


You still need to be careful when selecting the PIC. To get optimal performance out of the MMC card you want to run the SPI bus as fast as possible. At 3 volts a lot of PICs have a lower maximum frequency (and therefore lower SPI bus speed) than at five volts. If you are moving large blocks of data between the PIC and the Card, the SPI bus speed plays can play a significant role in terms of maximum system performance.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
joven



Joined: 30 Jan 2007
Posts: 56
Location: Viana do Castelo - Portugal

View user's profile Send private message

PostPosted: Wed Feb 28, 2007 10:45 am     Reply with quote

For testing the first time thinking use 18F4550 but can use 18LF4550.
For the prototype maybe will use the 18LF4620.
joven



Joined: 30 Jan 2007
Posts: 56
Location: Viana do Castelo - Portugal

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 2:03 pm     Reply with quote

I've successful initialized, write and read on SD 128mb.

how can know the maximum number of blocks 512 bytes i can write?
ckielstra



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

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 4:49 pm     Reply with quote

For information on which commands are supported by the MMC card study the MMC specification documents, these used to be free for download but now must be bought from the MMC Association. Having said this, Samsung (a major backer of MMC) provides a highly detailed datasheet which contains most of the essential information for writing an MMC driver.

Below is the function I use for reading the MMC memory size. I converted it from my own access routines to use the CCS mmc_spi library but didn't test the conversion.
Code:
#include <mmc_spi.c>
int32 MMC_Size;                   // Size of the MMC memory space (manufacturer dependent)


// Command codes
#define MMC_CMD_SEND_CSD       9 // Card sends its card-specific data (CSD)

#define CSD_BUF_LEN       (128/8) // Buffer size [bytes] for storing the CSD register data

#define RESPONSE_R1             1 // R1 response type

// Response codes
#define R1_OK               0x00
#define R1_IDLE_STATE       0x01
#define R1_ERASE_RESET      0x02
#define R1_ILLEGAL_CMD      0x04
#define R1_COM_CRC_ERR      0x08
#define R1_ERASE_SEQ_ERR    0x10
#define R1_ADDRESS_ERR      0x20
#define R1_PARAM_ERR        0x40


//-----------------------------------------------------------------------------
// Read the Card Specific Data register.
// MMC memory size will be stored in the global variable MMC_Size.
//
// Copyright C. Kielstra
// Distribute freely with copyright notice intact.
//-----------------------------------------------------------------------------
void MMC_ReadCSD()
{
  int8 Result;
  int8 CsdBuf[CSD_BUF_LEN];
  int8 i;
  int8 ReadBlockLen;
  int16 C_Size;
  int8 C_Size_Mult;
  int8 Multiplier;

  mmc_select();
  Result = mmc_send_cmd(MMC_CMD_SEND_CSD, 0, RESPONSE_R1);

  if (Result == R1_OK)
  {
    // Get the CSD data
    // Note that bit 127 is the first bit read.
    while (mmc_read_data() == 0xFF)
        ;   // skip all bytes including the Start Byte (0xFE)
    for (i=0; i<sizeof(CsdBuf); i++)
    {
      CsdBuf[i] = mmc_read_data();
    }
    // Skip the 16-bit CRC
    mmc_read_data();
    mmc_read_data();
   
    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;
  }
  mmc_deselect();
}


//-----------------------------------------------------------------------------
void main()
{
  MMC_Size = 0;
 
  if (mmc_init() == MMC_EC_OK)
  {
    MMC_ReadCSD();
    printf("MMC size = %lu bytes.\r\n", MMC_Size);
  }
  else
    printf("MMC init error!\r\n");
 
  while(TRUE);
}
joven



Joined: 30 Jan 2007
Posts: 56
Location: Viana do Castelo - Portugal

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 5:03 pm     Reply with quote

thanks ckielstra.

I'll be big help, when i test will say something.
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Mon Mar 05, 2007 2:21 am     Reply with quote

Hi ckielstra

I see that You are very familiar with MMC SD Cards,
So pls can You explain me in some easy way the difference between MMC and SD Cards ??

I have got the smaple from CCS named MMC..... but I like to use SD cards.

any help very appriacted

Andreas
ckielstra



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

View user's profile Send private message

PostPosted: Mon Mar 05, 2007 5:19 am     Reply with quote

Andreas wrote:
I see that You are very familiar with MMC SD Cards,
So pls can You explain me in some easy way the difference between MMC and SD Cards ??
The physical form factor, pin assignment and data transfer protocol of the SD Card are forward compatible with the MMC Card, with some additions. Most notable are the addition of encryption hardware (hence the 'Secure' in the name) and faster data speeds through a higher allowed clock rate and 4 data lines instead of 1 data line. In theory, the encryption would allow some enforcement of Digital rights management schemes on digital music, but the capability is rarely used. New versions of the MMC standard do exist now which have similar speeds to the fastest SD card standards.

Physical difference: Most SD cards are physically thicker than MMC cards. SD cards generally measure 32 mm × 24 mm × 2.1 mm, but can be as thin as 1.4 mm, just like MMC cards. Most SD cards have an optional write protect switch. Most SD card holders will also accept MMC cards. The original SD cards have 9 pins with 7 pins for the MMC cards but newer versions of the standards have increased the pin numbers on both.

All SD cards are required to support the older SPI/MMC mode which supports the slightly slower four-wire serial interface (clock, serial in, serial out, chip select) that is compatible with SPI ports on many microcontrollers.

Practically:
When using a PIC connected to a memory card you will very likely use it with the SPI bus, in this mode MMC and SD are very similar. The fastest PIC at 40MHz has a maximum SPI bus clock of 10MHz, much lower than the allowed 20MHz of the slowest MMC standard.
SD requires a few more commands to start up but than there should be no difference in protocol when using SPI mode.

I personally like MMC over SD as SD cards tend to be slightly more expensive while offering about 5% less available memory capacity (memory reserved for the security features which you are never going to use). The other positive features of the SD card like higher data speed are useless in the slow PIC processors.

More reading:
http://en.wikipedia.org/wiki/SDCard
http://en.wikipedia.org/wiki/MultiMediaCard
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Mon Mar 05, 2007 6:25 am     Reply with quote

Thanks ckielstra !

This information was really very uselfull for me and I think also for many others.

Lokking thru the SD Card specs I am not ready by now to find the additional sequences You mentioned, but the day is still long I will give it another try

best regards

Andreas
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