Yahoo Groups archive

Lpc2000

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

Message

Re: SPI Interface code

2004-12-14 by haack0815

Hi Sridhar,

you are writing any values to the PINSEL0 register in the
initial_serial function?
Is the powercontrol for the SPI0 controller enabled ?

In your init_spi_read function you missed a semicolon.
But your code in this function will not work anyway.
You must do a dummy write (generate 8 clock pulses) to the SOSPDR
before you can read the received value.
(1. dummy write SPDR, 2. wait until send complete , 3. read SPDR)


Andreas Haack

--- In lpc2000@yahoogroups.com, Sridhar gadda <sridhargadda@y...> wrote:
> Hello Friends, 
>  
>                           I defined an SPI interface, µc as master and 
> only one salve, I cannot see clock generating at SCK0...I tested with 
> Oscilloscope....Please you check the code ..and where am I doing error 
> ???
>  
> void init_spi(void)
> {  
>    S0SPCCR = 0x08;  /* SPI clock */ 
>    S0SPCR =  0x60;  /* µc as master, LSB as first bit,  CPOL = 0, CPHA 
> = 0 */ 
>    IOSET1 = 0x00010000;  /* Blink LED */
> }  
>  int init_spi_write(void)
>  {
>  S0SPDR = 0x01;        /* Write Data Address to SPI */
>  while ((S0SPSR & 0x80) == 0); /* Wait Until SPIE bit is set */
>  IOSET1 = 0x00100000;   /* Blink the LED */ 
>  return (S0SPSR);    /* When SPIE is Set, read the Status register*/
>  }                    
>  int init_spi_read(void)
>  {
>    unsigned int dummy;        
>    dummy = S0SPDR /* Read the value from SPI */
>    while ((S0SPSR & 0x80) == 0); /* wait until SPIE bit is set */
>    IOSET1 = 0x00200000;  /* Blink the LED */
>    return (S0SPSR);    /* When SPIE bit is set read Status Register */
>  }
> int main (void)
> {
>   initial_serial();    /* Initialize the Serial Interface with UART */
>   PINSEL0 |= 0x00005500;     /* SCK0, MISO, MOSI for SPI0 enabled & 
> SSEL*/
>   IODIR0 = 0x00003C00;   /* P.10.. P.13 defined as outputs */
>   IOSET0 = 0x00001400;    /* p.10, p.12 high & P.11, p13 are low to 
> select CS*/
>   IODIR1 = 0x00FF0000;  /* Define P1.16 to P1.23 as outside */
>   IOCLR1 = 0x00000000;       /* Turn off LEDs, you can check your flash 
> is working or not */   
>   init_spi();               /* Initialize the SPI Interface */ 
>    init_spi_write();  /* Write the data to SPI */
>    init_spi_read();  /* Read data from SPI data register */
>    
> }
>  
> I made High on SSLE ...P0.7 to 3.3v........Still I dont see any clock 
> generating st SCK0 nor any signal at MOSI or MISO.......
>  
> I am waiting for your replies, 
>  
> Thanks in Advance, 
>  
> Sridhar
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> [Non-text portions of this message have been removed]

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.