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

Unable to read sector from SD card on LPC2148 dev board.

Hi,

I am trying to access data on an SD/MMC card on a Blueboard LPC2148 development kit using the sample SD_CARD app that comes with KeilSampleProjects. I believe I have all of the pin and register configurations set up correctly but when I send a Read command to the card (CMD17),
it returns a valid return code and data token, but the data block is almost all zeroes with a handful of random characters/values near the end.

It responds fine to CMD0 and CMD1 also, so this leads me to believe that the pin and register configuration is correct.

The memory card is connected to the SSP bus so it is using SCK1, MISO1, MOSI1, and GPIO on pins P0.17-P0.20.

The relevant code in sd_readSector is:

        sd_Command(CMD17, (euint16) (place >> 16), (euint16) place);

        cardresp = sd_Resp8b(); /* Card response */

         /* Wait for startblock */
        do
                firstblock=sd_Resp8b();
        while(firstblock==0xff && fb_timeout--);

        if(cardresp!=0x00 || firstblock!=0xfe){
                sd_Resp8bError(firstblock);
                return(-1);
        }

        for(i=0;i<512;i++){
                c = if_spiSend(0xff);
                if(i<len)
                        buf[i] = c;
        }

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

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

         return(incoming);
      }

cardresp is coming back as 0 and firstblock is coming back as 0xfe as expected.

I am trying to read sector 0 and am expecting to see the characters 'F', 'A', 'T', '1', '6'
starting at byte 54, but as I mentioned, I am seeing zeros in the first several hundred bytes.

I have tried modifying the SCR value to change the clock rate of SPI1 but that did not have any effect.

To summarize the register configuration:

PINSEL1 = 0xa8
IO0DIR = 0x103c00
SSPCR0 = 0x23c7
SSPCR1 = 2
SSPCPSR = 2

I hope I have provided sufficient information but if there are any other details I can provide, please let me know.

And the obvious question, is there something I am missing? Any ideas on why I am not getting valid data back when issuing a Read Block command to the SD/MMC card?

Thanks.

Martin

0