Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: SPI Problem,

2005-10-25 by rtstofer

--- In lpc2000@yahoogroups.com, "yodathgreat" 
<christophe.darnet@l...> wrote:
>
> Hi All,
> 
> Who can send me some exemples for make the Init on SPI of the 
> LPC2214.
> 
> SPI Master Mode.. (for SD Card).
> 
> Best regards
> Yodathegreat

The code below (abbreviated, somewhat) is for the LPC2106 and is 
copied from the app note.  It should work and it looks a lot like 
that German code.

spi.h
============

#define SPI_MSTR	(0x00000020)	// 1->spi operates as Master

// spi clock counter setting
// the maximum spi speed will be limited by the MP3 chip at 1/6 of 
the 24.576
// MHz crystal.
// Divider = (14.6456 MHz * 4) / (24.576 MHz / 6) = 14.4, call it 16
// NOTE: divider MUST be an even number and > 14.4
#define SPI_DIVIDER	(16)			// approx 3.7 MHz


spi.c
============


#include "lpc210x.h"
#include "spi.h"

void spiInit(void)
{
	PINSEL0  |= 0x00005500;		// set proper bits for SPI
	SPI_SPCR  = SPI_MSTR;		// set spi as a master
	SPI_SPCCR = SPI_DIVIDER;	// set for 500 kHz
}

void spiSendByte(unsigned char c)
{
	SPI_SPDR = c;
	while (!(SPI_SPSR & SPI_SPIF))
		;
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.