Forums

Problems with SPIO(LPC214x)

Started by venkat_oct10 November 8, 2008
(code corrected)
Hello,

In my code i have interfaced atmel serial data flash,
i have given my spi code here and the operation i have done is that,
i am reading the SPI data register. Note here i am not communicating
with my slave. I came to know that my SPI write has some problems
hence i am not communicating with my device.Even if i communicate i
am getting the write and read values as 00 and sometimes FF

If u see in my below code i am just writting a char to S0SPDR thro
serial and reading the same. When viewed in serial i am getting the
correct value for sometime and getting 00,FF,3F,3d randomly. Even
the correct value occurs once in 5 to 6 times. What might be the
problem and where i have to concentrate. Here is my code,

void SPI_Setup(void)
{
unsigned char dummy;

PCONP |= 0x00000100;
PINSEL0 &= 0xFFFF00FF;
PINSEL0 |= 0x00001500;
//SPI0 setup
S0SPCCR = 0x3c;
S0SPCR = 0x0020;
dummy = S0SPSR;
dummy = S0SPDR;
}

unsigned char send_spibyte( unsigned char data)
{

unsigned char dummy;
S0SPSR=0;
S0SPDR = data;
while((S0SPSR & SPI0_SPSR_SPIF)==0x00); //
dummy=S0SPDR; // Flush the data Reg
return dummy;

}

unsigned char recieve_spibyte( void)
{
char status;
S0SPDR=0x00; //Dummt write for sending SCLk to recieve data
while((S0SPSR & SPI0_SPSR_SPIF) ==0x00) ;
status = S0SPSR;
return(S0SPDR) ;
}

In main i have called this
while(1)
{
temp=getchar( );
temp1=send_ spibyte(temp) ;
printf("\ntemp- \n");
printf("%x\n" ,temp);
printf("\ntemp1- \n");
printf("%x\n" ,temp1);
}
The value of temp is displayed correctly,hence no problem with
getting char frm serial. I have also tried by just writting some 10
char putting the same in a for loop and i get the output.
i have tried reducing the clock in S0SPCCR reg and i dnt see any
improvement

Please help me in this regard
Thanks in advance
-venkat

An Engineer's Guide to the LPC2100 Series