2
\$\begingroup\$

I have been working on this kit for the past month and have simulated some basic programs using Keil (non os using just C). I was assigned a project of making a data logger which stores the data in SDLC (synchronous data link protocol) format on SD card.

Thus my project has 2 very straight forward parts:

  1. Receive the data in sdlc format (TTL compatible).

  2. Store on SD Card.

I have searched the forums of both Keil as well as Mini 2440 but still clueless about the interfacing of an SD card interface using simple C. Everybody seems to be suggesting anything but C. I have read the manuals and other PDF regarding interfacing using both the SPI as well as SD bus mode and whatever I could make out of it was written in a code which is given below:

#include <S3C2440.H>
#include<stdio.h>
void sd_card_init(void);
void spi_delay(void);
int main()
{
    //pclk is 12MHZ
    GPECON=0x0a800000; //clk mosi miso 13 12 11
    GPGCON=0x00000030;//ss 2
    SPCON0=0x18;//set the clk & enable the master
    SPPRE0=0x0e;//set the clk at 400 khz
    SPPIN0=0x01;//derive the mosi level
    sd_card_init(); 
    return 0;
} 

//**************************************************************
void sd_card_init()
{
    unsigned char x;
    unsigned int cmd0[]={0x40 ,0x00 , 0x00, 0x00 ,0x00 ,0x95};
    unsigned int cmd55[]={0x77 ,0x00 , 0x00, 0x00 ,0x00 ,0x95};
    unsigned int cmd41[]={0x69 ,0x00 , 0x00, 0x00 ,0x00 ,0x95};

    GPEDAT|=0x1000;

    //mosi=1;

    GPGDAT=GPGDAT|0x0004;

    //cs=1;

    spi_delay();

    //********************RESET COMMAND************************

    GPGDAT=GPGDAT|0xFFFB;

    //cs=0;

    for(x=0;x<6;x++)

        SPTDAT0=cmd0[x];

    //**********************check if card is ready or not.******************

    while((SPRDAT0==0x01)||(SPSTAT0&0x01==0))
    { 
        for(x=0;x<6;x++)
            SPTDAT0=cmd55[x];
        for(x=0;x<6;x++)
            SPTDAT0=cmd41[x]; 
    }
}

void spi_delay()
{
    unsigned char i,j; //wait for 74 clk cycles or more

    for(i=0;i<255;i++)
        for(j=0;j<255;j++);
    }
}

This is my code which I am trying to simulate on Keil for SPI. I have even tested this using an oscilloscope but could not even find the clock, so if anything else has to be done please tell. I am in great need of your comments and help.

\$\endgroup\$
  • \$\begingroup\$ can I have some ans please \$\endgroup\$ – Srishti Jul 6 '13 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.