LPC2148 and Micro SD

Hello,

I have interfaced an LPC-H2148 from Olimex to a Micro SD break out board from Sparkfun.

I use the SPI0 module on the LPC2148, since I already have assigned the SSP pins to other peripherals.

Here is the wiring description:

Micro SD <—> LPC2148

CS <—> P0.7 (GPIO output)

DI <—> P0.6 (MOSI0)

SCK <—> P0.4 (SCK0)

DO <—> P0.8 (MISO0)

On the Micro SD break out board, I have connected C0 to VCC (3.3V) using a 1M pull up resistor. Apparently this is to limit current consumption…

I am using a Micro SD card of 1G from SanDisk. I’ve checked the card is working, I can access it from a card reader using window.

I used AN10406 from NXP to generate code for communicating with the SD card. However, I had to update that code since the AN uses the SSP port, not the SPI.

I’ve modified the PINSEL0 register so it defines the SPI pins as active.

PCLOCK is 1/2 of CCLK.

I have checked the SPI peripheral is powered.

I’ve initialized the SPI control register so it is master, MSB first, CPHA = 0, CPOL = 0, as defined for the SSP module in AN10406. I only send 8 bits per transaction.

I used the same initialization sequence as used in AN10406, which consists of sending 10 dummy bytes to the card to initialize it in SPI mode, then send the 40 00 00 00 00 95 command (GO_IDLE_STATE).

As shown in the example, I set the SD CS before sending the dummy bytes, but clear it before sending the GO_IDLE_STATE command.

I’ve tried that sequence a different rates for the clock prescale register (minimum and maximum value).

From what I understand of the SPI protocol, the slave is supposed to mirror the bytes the master is sending. However, every time I send a byte (whatever the value is), SSPDR returns 0xFF. Eventually I never receive any answer from the card.

What am I missing???

Thanks!

The slave does not just mirror the bytes you send, the master has to transmit until the slave finished sending its response. When I implemented the SD driver for my project I found this page very useful:

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

You may also try my code, the link is in the signature, it uses the SSP but it should not be much different. Note that SPI peripheral has a much lower transfer rate than SSP.

Check the Martin Thomas pages http://www.siwawi.arubi.uni-kl.de/avr_p … index.html and EFSL project. It works on SPI0 or SSP.

Angelo

Polux rsv:
Check the Martin Thomas pages http://www.siwawi.arubi.uni-kl.de/avr_p … index.html and EFSL project. It works on SPI0 or SSP.

Angelo

Hello,

Thanks for the heasup, your information was useful and I got the interface to work OK.