I have a problem with a simple SPI example program.
Part: LPC2129
PCK: 14.7 MHz
Mode: Master, CPOL=0, CPHA=0, LSIF=0.
I initialise the SPI like this:-
void SPI_Init(void)
{
S0SPCCR = 0x26; // Divides PCK to give about 400kHz
S0SPCR = 0x20; // Select Master mode
}
And then use the SPI like this:-
void SPI_Transfer( char *buf, int count)
{
int r = 0, i = 0;
for( ; i < count; i++ )
{
S0SPDR = buf[i]; // Write data
do{ r = S0SPSR; }while(!(r & 0x80));// Wait for SPIF
// Read status - to be done
buf[i] = S0SPDR; // Read data
}
}
Sometimes I power up the device and this function runs correctly
with problem whatsoever. Other times the function just hangs. If I
attach a JTAG debugger (Keil ULINK) I find that the function is
hanging at the line "do{ r = S0SPSR; }while(!(r & 0x80));" on the
first itteration.
There is no hardware attached to the SPI port. I figured that the
device should put data out onto an unconnected pin without any
problem and that I should be able to get the software working before
thinking about ading hardware.
Has anyone got any ideas what might be going wrong?
Thanks,
PaulMessage
SPI Code hangs
2006-03-08 by brightside_design
Attachments
- No local attachments were found for this message.