Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

regarding interfacing sd card with pic 18f4520

Status
Not open for further replies.

gopal_kmu54

Newbie level 6
Joined
Feb 1, 2010
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,291
Location
india
Activity points
1,395
I am interfacing my micro sd card with the above circuit diagram(in the attachment file). I am initializing my sd card with the following sample code, i am displaying the response in my lcd. According to the code i am expecting blank display where as it shows one. which means it is not initialized or card is not accepted.

kindly help me to get me out of this.is there any other resource for interfacing the sd card. i am using 18f4520. my compiler is ccs version 4.057

my code is:


#if defined(__PCM__)
#if defined(__PCH__)
#endif
#endif

#include <stdio.h>
#include <string.h>
#include <mmcsd.c>
#include <input.c>
#fuses XT,NOWDT,NOPROTECT,NOLVP

#use delay(clock=4000000)
#use standard_io(B)
#use standard_io(C)
#use standard_io(D)


#define LCD_ENABLE_PIN PIN_B0
#define LCD_RS_PIN PIN_B2
#define LCD_RW_PIN PIN_B1
#define LCD_TYPE 2

#define SPI_SDI PIN_C4 //PIN 23
#define SPI_SDO PIN_C5 //PIN 24
#define SPI_SCK PIN_C3 //PIN 18
#define SPI_SS PIN_C2 //PIN 07

#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)

void lcd_init();
void lcd_cmd(cmd);
void lcd_data(data);
void nibbel_split(unsigned long DataIn);

int mmc_init();
int mmc_response(unsigned char response);
int mmc_get_status();
int mmc_write_block(unsigned long block_number);
int mmc_read_block(unsigned long block_number);

unsigned char cmd,data;
int i,j=0;
int res,rcvdat;
char send_data[]={"TRANSINNOVA INSTRUMENTS PVT LTD"};
int read[32];
int DDLN,DDUN,LN,UN;
int errvalue;
void main()
{

set_tris_b(0x00);
set_tris_d(0x00);
set_tris_c(0x10);

lcd_init();

// cmd to setup spi mode

lcd_data((mmc_init()+0x30));
output_low(PIN_C2);

// mmc_get_status();
// mmc_write_block(0x0002);
//mmc_read_block(0x0002);
}


int mmc_init()
{
setup_spi(SPI_MASTER|SPI_MODE_0|SPI_CLK_DIV_16);

output_high(PIN_C2); // set high slave select signal before sending cmd0
output_high(PIN_C5);

for(i=0;i<10;i++) // initialise the MMC card into SPI mode by sending clks on
{
SPI_WRITE(0xFF);
}

output_low(PIN_C2);

spi_write(0x40);
spi_write(0x00);
spi_write(0x00);
spi_write(0x00);
spi_write(0x00);
spi_write(0x95);

if( mmc_response(0x01)==1);
return 1 ;
}

int mmc_response(unsigned int response)
{
unsigned long count = 0xFFFF;

while(SPI_READ(0xFF) != response && --count > 0);
if(count==0) return 1; // loop was exited due to timeout
else return 0; // loop was exited before timeout
}
 

Attachments

  • mmc connection.jpg
    mmc connection.jpg
    52.1 KB · Views: 126

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top