EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

SPI SD card help

Started by tanermutlu September 17, 2006
Michael Anton wrote:
>
> > -----Original Message-----
> > From: lpc2000@yahoogroups .com
> > [mailto:lpc2000@yahoogroups .com
> ]On Behalf
> > Of philippcp
> > Sent: Tuesday, April 24, 2007 12:49 AM
> > To: lpc2000@yahoogroups .com
> > Subject: [lpc2000] Re: SPI SD card help
> >
> >
> > Hello,
> >
> > the sample code (raw sd-mmc access) is running with an workaround. I
> > used another GPIO Pin for the CS. If someones got an idea how its
> > working with the SSEL Pin, please let me know.
>
> The SSEL0 pin is not used in master mode, so for SD card access, you
> must configure this as a GPIO, and toggle it in software (if this is
> allowed on the LPC2294, as on some parts, this must be used, and held
> high). Even if it could be used in master mode, the SSEL0 line must
> be held low for the entire SD card access, so you cannot raise this
> line in between bytes.
>

I have yet to see any LPC2000 part accept SSEL programmed as a GPIO
output pin and have the master mode working. I've tried this on
LPC2106, LPC2138, and LPC2214, none of them will do this. The only
thing that I've found to work is to program SSEL as a control input for
the SPI, then tie it high.

On the SPI0 for the LPC2214, CPHA and CPOL must be set to "zero" for me
to talk with the MMC (SD) card. I have SSEL0 tied to +3.3 volts (fixed
at Master Mode). Effectively, then set only bit 5 in SP0CR (0x20).

I've also set SP0SPCCR to '8'. These work for me:

=========== begin =============
#define SPI0_PINMASK 0x0000ff00
#define SPI0_PINSEL 0x00005500

static void setupSPI0 (void)
{// setup basic operation of the SPI0 controller.
volatile uchar byt;
// set pins for SPI0 operation.
PINSEL0 = (PINSEL0 & ~SPI0_PINMASK) | SPI0_PINSEL;
// set clock rate to approx 3.93MHz (58.98MHz / 15);
// 254 sets a 7.5us clockrate.
S0SPCCR = SPI0_XFER_CLOCK;
// turn off the SPI INT system.
S0SPCR = 0;
// ack any pending interrupt.
// reset SPI state.
S0SPINT = 1; byt = S0SPSR; byt = S0SPDR;
// just turn on master mode for now.
// clock is rising edge, pre-drive data bit before clock.
// Most significant bit shifted out first.
// resting state of the clock will be LOW.
// data is first driven out, then clock rising edge latches it.
S0SPCR = SPI_MASTER;
}
=========== snip ==============
TomW

--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net http://cyberiansoftware.com http://openzipit.org
"Windows? No thanks, I have work to do..."
----------------

An Engineer's Guide to the LPC2100 Series

> -----Original Message-----
> From: l...
> [mailto:l...]On Behalf
> Of Tom Walsh
> Sent: Tuesday, April 24, 2007 5:39 PM
> To: l...
> Subject: Re: [lpc2000] Re: SPI SD card help
> Michael Anton wrote:
> >
> >
> >
> > > -----Original Message-----
> > > From: lpc2000@yahoogroups .com
> > > [mailto:lpc2000@yahoogroups .com
> > ]On Behalf
> > > Of philippcp
> > > Sent: Tuesday, April 24, 2007 12:49 AM
> > > To: lpc2000@yahoogroups .com
> > > Subject: [lpc2000] Re: SPI SD card help
> > >
> > >
> > > Hello,
> > >
> > > the sample code (raw sd-mmc access) is running with an
> workaround. I
> > > used another GPIO Pin for the CS. If someones got an
> idea how its
> > > working with the SSEL Pin, please let me know.
> >
> > The SSEL0 pin is not used in master mode, so for SD card access, you
> > must configure this as a GPIO, and toggle it in software (if this is
> > allowed on the LPC2294, as on some parts, this must be
> used, and held
> > high). Even if it could be used in master mode, the SSEL0 line must
> > be held low for the entire SD card access, so you cannot raise this
> > line in between bytes.
> > I have yet to see any LPC2000 part accept SSEL programmed as a GPIO
> output pin and have the master mode working. I've tried this on
> LPC2106, LPC2138, and LPC2214, none of them will do this. The only
> thing that I've found to work is to program SSEL as a control
> input for
> the SPI, then tie it high.
>

Well, LPC2148 works correctly with SSEL0 as a GPIO, but then it does
mention this specifically in the manual (if I remember correctly).
This is one of the things that was "fixed" in this part.

Mike
...
>
> I have yet to see any LPC2000 part accept SSEL programmed as a GPIO
> output pin and have the master mode working. I've tried this on
> LPC2106, LPC2138, and LPC2214, none of them will do this. The only
> thing that I've found to work is to program SSEL as a control input
for
> the SPI, then tie it high.
>

I am using SSEL line as GPIO (chip select for a SPI device) while using
the SPI in master mode on the LPC2103. It works fine.

Best regards

Thomas Augustinus
Amfitech ApS

The 2024 Embedded Online Conference