This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SD care interface with LPC2148 on Development

Hi,

I am trying to integrate SDcard on to my project. My basic Aim is to transfer files to SDcard. The files are nearly 5MB to 10 MB in size. I used NSK electronics LPC 2148 development board. There are some sample SD card programs given.
I compiled the code. The SD card initialization was unsuccessful. The sd_initinialize() function has two conditions : sd_init() and sd_state() is returning is returning a negative value, which means that the SD card is not initialized.

The LCD shows "SD CARD - not OK"
I crossed checked the PIN configuration and spisend() function check, but i still couldn't figure what is wrong ?

Source code for main.c

#include <LPC214X.H>
#include "lcd.h"
#include "type.h"
#include "types.h"
#include "lpc2000_spi.h"
//#include "ssp.h"

//void delay(unsigned long int count1);
void wait (void);
U8 init_sdcard(void);

int main (void)
{
  unsigned char i;
  unsigned status;
  unsigned char SDCheckFlag;

  lcd_init();                                                                                     {
        lcd_write_control(0x01);
        goto_cursor(0x00);
        if(init_sdcard())
        {
        lcd_print("SD card - OK");
                SDCheckFlag = 1;
        }
        //else if(init_sdcard() == -1)
        //{
        // lcd_print("SD Card-error = -1");
        //}
        //else if(init_sdcard() == -2)
        //{
        //  lcd_print("SD Card-error = -2");
        //}
        else
        {
        lcd_print("SD card - not OK");
                SDCheckFlag = 0;
        }

    delay(100000);

  }

}

Source Code for lpc2000_sd.c

#include <LPC214x.H>              /* LPC214x definitions */
#include "lpc2000_spi.h"
#include "sd.h"
#include "type.h"
#include "ssp.h"
#include "utils.h"

#define SD_CARD BIT20
#define SD_SELECTION_DIR_SET (IO0DIR |= SD_CARD)
#define SD_SELECTION_SET (IO0SET = SD_CARD)
#define SD_SELECTION_CLR (IO0CLR = SD_CARD)

esint8 if_initInterface(eint8* opts)
{
  if_spiInit();
 if(sd_Init()<0)
  {
        DBG((TXT("Card failed to init, breaking up...\n")));
        return(-1);
  }
 if(sd_State()<0)
        {
                DBG((TXT("Card didn't return the ready state, breaking up...\n")));
                return(-2);
        }
//  file->sectorCount=4; /* FIXME ASAP!! */
//  DBG((TXT("Init done...\n")));
  else
  return(0);
}

euint8 if_spiSend(euint8 outgoing)
{
  euint8 incoming=0;

  while ( !(SSPSR & SSPSR_TNF) );
  SSPDR = outgoing;

  while (!(SSPSR & SSPSR_RNE));
  incoming = SSPDR;

  return(incoming);
}

void if_spiInit()
{
  spi1_init();
  SD_SELECTION_DIR_SET;
  SD_SELECTION_CLR;
}
#if 0
esint8 if_readBuf(hwInterface* file,euint32 address,euint8* buf)
{
  return(sd_readSector(file,address,buf,512));
}

esint8 if_writeBuf(hwInterface* file,euint32 address,euint8* buf)
{
  return(sd_writeSector(file,address, buf));
}
#endif


0