Hi All,
Has anyone set up the SPI or SSP on the LPC2148?
I cant get SPI0 to work at all, i.e. no SCK when I scope the dev board
(I have pull ups on SCK, MOSI0, MOI0 & SSEL0) and it is turned on in
the power reg.
void SPI_Init (void)
{
PINSEL0 = 0x00005500; // SPI Pins
IODIR0 = 0x00000400; // Chipselect
S0SPCCR = 0x000000FF; // bit timing
S0SPCR = 0x000000A0; // Master, Ints enabled
VICVectCntl0 = 0x0000002A;
VICVectAddr0 = (unsigned);
VICIntEnable = 0x00000400;
}
while(1)
{
SOSPDR = 0x5555; // write continuously to stimulate SCK
}
So I thought I'll try the SSP instead.
Set that up with, no interrupts: -
void SPI1_Init (void)
{
PINSEL1 = 0x000002A8; // SPI1 pins
SSPCR0 = 0x00000007;
SSPCR1 = 0x00000002;
SSPCPSR = 0x00000002; // 30 MHz SCK
SSPCPSR = 0x00007530;
}
And the SPI1 SCK is there when I scope the hardware. Great!
But no.... try reading data from the SPI and it's not there. So I
start single stepping and find the data only stays in the SSPDR reg
for one assembler instruction and is then lost (Keil Bug?).
My read command is 0x9F, which should return 0x20.
So my function is:
void read_Device_Type(void)
{
IOCLR0 = 0x00000400; // Pull Chip Sel low
while (SSPSR & BSY); // wait for SPI Idle
SSPDR = 0x009F; // Write command (1)
while (!(SSPSR & TNF)); // Wait transmit
SSPDR = 0x0000; // Dummy write (2)
while (!(SSPSR & TNF)); // Wait transmit
input = SSPDR; // Data from device (3)
IOSET0 = 0x00000400; // Chip select high
}
Now, looking at the memory location of SSPDR I find that after (1)
SSPDR = 0xFF, then after (2) SSPDR = 0x20 (what I expect) but when I
read SSPDR at (3) it returns 0x00.
If I replace (2) with (3) I return 0x00
The disasembler reveals an STRH R1, [R0] instruction which shows the
correct return value but this is lost in the next LDR instruction.
Have scoped the data in and data out pins and I can see the correct
data on both.
Hope that gives you enough to understand, I spent all day on this....
Thanks,
MalcomMessage
SPI, SSP on LPC2148 MCB2140 Keil Bug?
2005-09-01 by highgatematem28
Attachments
- No local attachments were found for this message.