SD CARD interfacing

roger
Hi all!!

I am working on implementing a data logger using sd card interfacing ie
data logs into it...I have tried according to the manual provided but in
the process I feel that my card was corrupted as a 2gb card was reduced to
121mb....I would be thankful if anyone can provide me with the bit of help
on this issue..
Also is it viable to do this interfacing on no os platform..??


Thanks
roger

Gautam
Hi Roger,

Check these links. They may be useful.

1. http://elm-chan.org/fsw/ff/00index_e.html

2. http://elm-chan.org/docs/mmc/mmc_e.html

Cheers!

Gautam

roger
#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
  //**************************************************************
  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=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 but since SPI
peripheral is not available there for this board it is of no use
Can somebody suggest another simulator for this board so that I can really
see if it is working or not..I have even tested this using oscilloscope but

could not even find the clock...so anything else has o be done please tell
me I am in great need of your comments and help and please tell me that
should I pursue this code on NO OS platform further...
I am eagerly waiting for the answers...

Thank you
Roger

davef
You want to use SPI to talk to an external SDcard.  For some reason you
don't want to use the internal SD card interface.

I think domdom did some SPI for WinCE.  I've done it for Linux but that's
not what you are operating on.

roger
Yeah my first choice of interfacing was with spi as it appeared to be
easier one but eventually nothing happened so I am trying with SD 1 bit
protocol on NO OS platform.

If anyone has tried please help with your codes..

Thankyou
Roger

davef
My understanding is that the non-SPI mode of SD comms is "closed-source".

That is why elm-chan's code or any other SPI SD card code is popular.

roger
Yes but I found it a little difficult so 
I have been working on the code too. 
Also if you could help me on the aspect that if somehow I store the data in
sd card and if I wanted to open it as a text file on the desktop how it
might be possible if the card is FAT compatible.


Thanks 
Roger

davef
Well, I'll tell you what I do.

I run TinyFs from elm-chan on a ATmega32 8 bit uP from Atmel. The data is
saved in a format that Windows Excel will display in a spreadsheet as well
as graph it for me.  It is FAT compatiable and written in C code.

Still, I am curious why you can't use the SDcard interface on the mini2440.
 Is it a school project?

If I had to do this, seeing as I spent quite a bit of effort getting the
SPI driver working for 3.7, I would port TinyFs or FatFs (seeing as size is
not important) to run in Linux on the mini2440.  Even so I would expect
this would take more than "a few days" to accomplish.  Maybe, even several
weeks!

Are you sure nobody hasn't done this and posted a tutorial on the WWW?

roger
Hi all!!

I want a serious help on sd card interfacing either using SPI or Sd 1 bit
protocol.

I have already tried using SPI and 1 bit too on No OS platform but in vain.
So any help containing codes for reading and writing data on sd card on NO
OS platform will be APPRECIATED.

Thank you
Roger

roger
Hi all!!

No help!! that was not expected...Is there anyone who has tried this??

Please help me..

anatoly
Instead of roaring here you'd better look at your DVD... Sorry!

roger
Sorry for being rude but can you be more clear

anatoly
Roger, I'm sorry - I was rude, (had a hard day).
As I see, you have mini2440 board. I meant that if you have bought it, you
have a DVD with programs. Otherwise, you can download any of them.
Try to find (if didn't still see it) the Test2440.
It has a part working with the SD cards.
Learning it you'll be able to read/write data. If you want to have a deal
with files, attach some FAT code. If you will work with mini210, you may
need to read the second partition. And last, if want just to build the data
logger quickly, you can use startos.

Arun Gowda
Hi All,
I have started to work on LPC2148. Can anyone help me out on how to
interface  SD card with the board.

davef
Think your request is totally unrelated to FriendlyArm product.  Don't you
want a NXP forum.

http://en.wikipedia.org/wiki/NXP_LPC