LPC2214 & SPI1

Started by jensalsig July 22, 2005
Hi,
I'm having some trouble with the SPI1 channel. My hardware
configuration is two 25LC640 connected to SPI1 channel via two
separate chip selects, GPIO's. I have connected the SSEL1 to 3.3V but
it still doesn't work.
When I meassure the SCLK1, MISO1 and MOSI1 pins they seam to float. I
have tried different configurations, like first set the SCLK1, MISO1
and MOSI1 pins as GPIO and output and then change the PINSEL1 so the
in become SCLK1, MISO1 and MOSI1, but this didn't work. :(
I'm using FreeRTOS as my RTOS.

I have included my init code and a write function.

My SPI.h:
#define SPI3MHz (unsigned portLONG) 0x20;
#define SPI1SCLK (unsigned portLONG) 0x0008
#define SPI1MISO (unsigned portLONG) 0x0020
#define SPI1MOSI (unsigned portLONG) 0x0080
#define SPI1SSEL (unsigned portLONG) 0x0200
#define SPI1 (unsigned portLONG) (SPI1SCLK |
SPI1MOSI | SPI1MISO | SPI1SSEL)

#define SPIF (unsigned portCHAR) (1<<7)

#define MEM_CS1 (unsigned portLONG) (1<<22)
#define MEM_CS2 (unsigned portLONG) (1<<16)

My SPI.c:
void InitSPI1()
{
PCB_PINSEL1 = (PCB_PINSEL1 & ~0x000003FC) | SPI1;
SCB_PCONP |= (1 << 10);
GPIO0_IODIR |= (MEM_CS2 | MEM_CS1 ); // Tder for CS
GPIO0_IOSET |= (MEM_CS2 | MEM_CS1);
SPI1_SPCR = (unsigned portLONG) 0x20;
SPI1_SPCCR = SPI3MHz;

}

void PutSPI1(unsigned portCHAR device, unsigned portCHAR ch, unsigned
portSHORT address)
{
if(device == MEM1)
{
GPIO0_IOCLR |= MEM_CS1;
SPI1_SPDR = MEM_WRITE;
while( !(SPI1_SPSR & SPIF)); //for kommando
SPI1_SPDR = (unsigned portCHAR)((address & 0xFF00) >> 8);
while( !(SPI1_SPSR & SPIF)); //for SPI high adresse
SPI1_SPDR = (unsigned portCHAR)(address & 0x00FF);
while( !(SPI1_SPSR & SPIF)); //for SPI high adresse
SPI1_SPDR = ch;
while( !(SPI1_SPSR & SPIF)); //for SPI high adresse
GPIO0_IOSET |= MEM_CS1;
}
else if(device == MEM2)
{
GPIO0_IOCLR |= MEM_CS2;
SPI1_SPDR = MEM_WRITE;
while( !(SPI1_SPSR & SPIF)); //for kommando
SPI1_SPDR = (unsigned portCHAR)((address & 0xFF00) >> 8);
while( !(SPI1_SPSR & SPIF)); //for SPI high adresse
SPI1_SPDR = (unsigned portCHAR)(address & 0x00FF);
while( !(SPI1_SPSR & SPIF)); //for SPI high adresse
SPI1_SPDR = ch;
while( !(SPI1_SPSR & SPIF));
GPIO0_IOSET |= MEM_CS2;
}

}

Regards Jens Alsig


An Engineer's Guide to the LPC2100 Series