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

Need helping about unstable phenomenon when comm SDcard

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



Joined: 08 Jun 2010
Posts: 13

View user's profile Send private message Yahoo Messenger

Need helping about unstable phenomenon when comm SDcard
PostPosted: Thu Jul 08, 2010 7:35 am     Reply with quote

I'm trying debug to confirm the hardware communication SD card and 18f4550 is true.
I used voltage source 3,3 V for both PIC and SD card (I tested blinking led with above fabric.The circuit worked)
Then I carried out installation SD connected 18F4550.
A portion my schematic :
I directly connected the pins SPI together !
My code (I used CCS):
Code:

#include "basicsd.h"

#define CS   PIN_B2
#define SCK  PIN_B1
#define SDO  PIN_C7
#define SDI  PIN_B0
#use spi( DI=SDI, DO=SDO, CLK=SCK, BITS=8,MODE=3 , stream=sspi)

#define _DEBUG

#ifdef _DEBUG
#define dbg(str) printf(str)
#endif

// Prototypes
void command(int8, int16, int16, int8);
int mmc_init();
int  i;

// Implementations

// Send 6-byte Command to MMC
void command(int8 cmd, int16 adh, int16 adl, int8 crc)
{
   spi_xfer(sspi,cmd);
   spi_xfer(sspi,make8(adh,1));
   spi_xfer(sspi,make8(adh,0));
   spi_xfer(sspi,make8(adl,1));
   spi_xfer(sspi,make8(adh,0));
   spi_xfer(sspi,crc);
}

// Initialize the Card
int mmc_init()
{
   int16 i;
  // Unselect Card and Send some Dummy Clocks
   output_high(CS);
   for(i= 0; i< 10; i++) 
   {
      spi_xfer(sspi,0xEF);
   }

   // Select Card
   output_low(CS);

   // Send Command 0x40: Wake Up the Card
   command(0x40, 0, 0, 0x95);
   for(i= 0; i< 100; i++)
   {
      if(spi_xfer()== 0x01)
      {
         break;
      }
   }

   if(i>= 100) // Check for Time-out Error
   {
      return(1);
   }
   dbg("CMD40 OK (R1= 0x01)\n\r");

   // Send Command 0x41: Start Initialize
   command(0x41, 0, 0, 0xFF);
   for(i= 0; i< 1000; i++)
   {
      if(spi_xfer()== 0x00)
      {
         break;
      }
   }
   if(i>= 1000) // Check for Time-out Error           
   {
      return(1);
   }
   dbg("CMD41 OK (R1= 0x00)\n\r");

   // Return OK
   return 0;
}


void main()
{
   //TRISD =0b00100010;

   printf("> MMC Test by DEBUGGER...\n\r");
   printf("> Start MMC Init...\n\r");
   /*while(1)
    {
    for(i=0;i<5;i++)
    {
    printf("test");
    delay_ms(200);
    }
  i=fgetc(GPS);
  if(i=='c') printf("\ni =10");
    }*/

   if(mmc_init()== 0)
   {
      printf("> MMC Init Ok...\r\n");
   }
   else
   {
      printf("> Continue Debug ...!\r\n");
   }
 
   while(1);

}

The above code well work Proteus simulation !
When I run on real circuit, the circuit was unstable.
At power up, result can be fail or success, very unstable !
I have spent many time to debug but still fail ! (Hic, it is sad,i have failed many times when comm it...)
Thanks for reading and hope get helping !
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