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

Problem with MMC initialization

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



Joined: 28 Aug 2007
Posts: 45

View user's profile Send private message

Problem with MMC initialization
PostPosted: Wed Nov 12, 2008 7:46 am     Reply with quote

I want to write MMC library . But I have a problem at the beginning . In this code the first level or reset MMC (GO_IDLE_STATE) is successful and MMC return 0x01.but in next level or SEND_OP_COND MMC return 0xFF instead 0x00. Where is the problem? My Compiler is 4.057 and proteus 6.9 here is the like of code and proteus file .

http://rapidshare.com/files/163053853/MMC_TEST.rar.html

Code:

#include "mmc1.h"

////////////////////////////////////////////////////////////////////////////////
#define GO_IDLE_STATE 0
#define SEND_OP_COND 1
#define CS PIN_C2
////////////////////////////////////////////////////////////////////////////////
char Command(unsigned int cmd, unsigned int arg)


     // sends a command to the MMC
        unsigned char resp;
        unsigned char retry=0;
        output_high(CS);
        output_low(CS);
        spi_write(0xFF);
        spi_write(cmd | 0x40);                               
        spi_write(arg>>24);
        spi_write(arg>>16);
        spi_write(arg>>8);
        spi_write(arg);
        spi_write(0x95);   
        spi_write(0xFF);
        while((resp = spi_read(0xFF)) == 0xFF)
                if(retry++ > 8) break;   
        return resp;
}

void main()
{
   int i;
   char R1;
   setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
   /////////////////////////////////////////////////////////////////////////////
   output_high(CS);                     //   _   
   for(i=0;i<10;i++)                    //    |
      Spi_Write(0xFF);                  //    |     ...: CMD0 :...
   R1=Command(GO_IDLE_STATE,0);         //    |
   printf("CMD0=%x\r\n",R1);            //   _|
   /////////////////////////////////////////////////////////////////////////////
   R1=Command(SEND_OP_COND,0);          //    |     ...: CMD1 :...
   printf("CMD1=%x\r\n",R1);            //    |
   /////////////////////////////////////////////////////////////////////////////

}
ckielstra



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

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 6:37 pm     Reply with quote

Why not use the CCS provided MMC driver mmcsd.c?

Code:
        spi_write(arg>>24);
Your function definition defines arg as an 8-bit integer, the shift of 24 bits will fail...
Define as an int32 instead.

Code:
   setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
MMC cards work either in SPI mode 0 or 3. Here you have defined SPI mode 1. Try the following code instead:
Code:
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)

setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_16);


Code:
        while((resp = spi_read(0xFF)) == 0xFF)
                if(retry++ > 8) break;   
The 8 retries probably are too short for some commands.
Another thing I don't like here is that you have an assignment ('=') inside the while test. This makes your code difficult to read and is difficult to step through with a debugger. Another way to write the same code is:
Code:
while(retry++ < 255)
{
  resp = spi_read(0xFF);
  if (resp != 0xFF)
    break;
}
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