Yahoo Groups archive

Lpc2000

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

Message

Re: SPI1

2005-08-17 by y4krys

Alsig,
 I'll try to build your application and check the configuration.  
What tools do you use?  Could you send me your lpc2114.h file?
If you can, put a break on "    TurnOnLed();" and use your debugger 
to check PCONP, PINSEL1 and SPI1_xxx register data.  It looks like 
your SPI1 may be disabled.  Also your slave will need a select/enable 
line active low to operate.
Krys
--- In lpc2000@yahoogroups.com, Jens Alsig <alsig@g...> wrote:
> Hi y4krys,
> 
> I've checked and double checked my source code and I can't find any 
> errors but it still doesn't work.
> The SPI pins seam to be set as input.
> I've included my source code and if you could take a look at it... 
Thanks.
> 
> Does anybody own a LPC with two SPI ports that would test the code 
for me?
> 
> Most of the code are generated by MakeApp from IAR.
> 
> Thanks in advance
> 
> Jens Alsig
> 
> main.c
> 
> 
> #include "lpc2114.h"
> 
> void init_spi(void);
> #define MA_PINSEL0_PCB         0x00000000  /* Pin Function Select 
> Register 0 */
> #define MA_PINSEL0_PCB_MASK    0xFFFFFFFF  /* Used bits */
> #define MA_PINSEL1_PCB         0x000002A8  /* Pin Function Select 
> Register 1 */
> #define MA_PINSEL1_PCB_MASK    0x3FCFFFFF  /* Used bits */
> #define MA_PINSEL2_PCB         0x006000F0  /* Pin Function Select 
> Register 2 */
> #define MA_PINSEL2_PCB_MASK    0x0FF3E9FC  /* Used bits */
> 
> 
> #define MA_S0SPCR_SPI          0x00000000  /* SPI0 Control Register 
*/
> #define MA_S0SPCR_SPI_MASK     0x000000F8  /* Used bits */
> #define MA_S0SPDR_SPI          0x00000000  /* SPI0 Data Register */
> #define MA_S0SPDR_SPI_MASK     0x000000FF  /* Used bits */
> #define MA_S0SPCCR_SPI         0x00000008  /* SPI0 Clock Counter 
Register */
> #define MA_S0SPCCR_SPI_MASK    0x000000FF  /* Used bits */
> #define MA_S1SPCR_SPI          0x00000020  /* SPI1 Control Register 
*/
> #define MA_S1SPCR_SPI_MASK     0x000000F8  /* Used bits */
> #define MA_S1SPDR_SPI          0x00000000  /* SPI1 Data Register */
> #define MA_S1SPDR_SPI_MASK     0x000000FF  /* Used bits */
> #define MA_S1SPCCR_SPI         0x00000008  /* SPI1 Clock Counter 
Register */
> #define MA_S1SPCCR_SPI_MASK    0x000000FF  /* Used bits */
> 
> 
> #define MA_OK        0
> #define MA_ERROR    1
> #define MA_EMPTY     2
> #define S1SPSR_SPIF    (1 << 7)
> #define S1SPSR_WCOL (1 << 6)
> #define S1SPSR_ROVR (1 << 5)
> #define S1SPSR_MODF (1 << 4)
> #define S1SPSR_ABRT (1 << 3)
> 
> #define PSelLED 0x30000000
> #define LED     0x40000000
> 
> void TurnOnLed(void)
> {
>     GPIO0_IOCLR  = LED;
> }
> 
> void TurnOffLed(void)
> {
>     GPIO0_IOSET  = LED;
> }
> 
> void spi1_init( void )
> {
>     PCB_PINSEL1  = ( PCB_PINSEL1 & ~MA_PINSEL1_PCB_MASK ) | 
MA_PINSEL1_PCB;
>     SPI1_SPCCR  = ( SPI1_SPCCR & ~MA_S1SPCCR_SPI_MASK ) | 
MA_S1SPCCR_SPI;
>     SPI1_SPCR   = ( SPI1_SPCR & ~MA_S1SPCR_SPI_MASK ) | 
MA_S1SPCR_SPI;
> }
> 
> signed char spi1_putch( unsigned char Data )
> {
>     signed char Status;
>     SPI1_SPDR = Data;
>     Status = MA_OK;
> 
>    
>     if( SPI1_SPSR )
>     {
>         Status = MA_ERROR;
>     }
>     return Status;
> 
> }
> 
> unsigned char spi1_getch( void )
> {
>     unsigned char Data;
>     Data = SPI1_SPDR;
>     return Data;
> 
> }
> 
> signed char spi1_get_status( void )
> {
>     signed char Status;
>     Status = (signed char) SPI1_SPSR;
> 
>     if( Status == 0 )
>     {
>         Status = MA_EMPTY;
>     }
>     else if( Status & ( S1SPSR_WCOL | S1SPSR_ROVR | S1SPSR_MODF | 
> S1SPSR_ABRT ) )
>     {
>         if( Status & S1SPSR_MODF )
>         {
>             SPI1_SPCR = MA_S1SPCR_SPI;
>         }
>     }
>     else if( Status & S1SPSR_SPIF )
>     {
>         Status = MA_OK;
>     }
>     return Status;
> 
> }
> 
> 
> int main(void)
> {
>     GPIO0_IODIR = LED;
>     spi1_init();
>     TurnOnLed();
>     while(1)
>     {
>     if(spi1_get_status() == MA_OK)
>         {
>             if(spi1_putch(0xAA) == MA_ERROR)
>                 TurnOffLed();
>         }
>     }
> }
> 
> 
> 
> y4krys wrote:
> 
> > Alsig,
> > One more thing, for the SSEL pullup to work the pin function must 
be
> > set to SPI (PINSEL1 |= 0x2A8).  (Note: corrected the config 
bits ;-))
> > Krys
> >
> > --- In lpc2000@yahoogroups.com, "y4krys" <krys.brukalo@a...> 
wrote:
> > > Alsig,
> > >  If you write a byte to the transmit register the SCK clock 
should
> > be
> > > generated.  Make sure the SPI1 peripheral is enabled and powered
> > > (Check PCONP bits).  You should be able to do your initial test
> > using
> > > your debugger and the direct access to the control registers. 
> > Also,
> > > only the MISO pin should show as an input, MOSI and SCK should 
be
> > > outputs driven SPI.  Once you are past the clock and MOSI hurdle
> > > you'll need the slave select signal from your LPC to the EE and 
the
> > > right SPI mode (CPOL and CPHA) for proper data access.
> > > I hope it helps.
> > > Regards,
> > > Krys
> > > --- In lpc2000@yahoogroups.com, Jens Alsig <alsig@g...> wrote:
> > > > Hi,
> > > > The all pins seam to float or be as input even after I 
configure
> > > the
> > > > PINSEL1 register. I'm using a LPC2214 as
> > > > the master and the 25Lc640 as a slave. I've connected the 
SSEL to
> > 3
> > > volt.
> > > > Regarding the setup of the registers I've tried the IAR 
MakeApp
> > > code for
> > > > the PCB module and the SPI module. And at the
> > > > moment this gives the same result.
> > > >
> > > > Regards Jens Alsig
> > > >
> > > >
> > > > y4krys wrote:
> > > >
> > > > > --- In lpc2000@yahoogroups.com, "jensalsig" <alsig@g...> 
wrote:
> > > > > > Hi,
> > > > > >
> > > > > > have anyone every used the SPI 1 channel on a LPC device 
that
> > > has 2
> > > > > > channels?
> > > > > >
> > > > > > I've tried without any luck and getting very frustrated! I
> > have
> > > tried
> > > > > > using the IAR MakeApp and that doesn't work either. My 
setup
> > is
> > > a
> > > > > > LPC2214 from Olimex and a MicroChip EEPROM.
> > > > > >
> > > > > > Any suggestions are VERY welcome.
> > > > > >
> > > > > > Regards Jens Alsig
> > > > >
> > > > > Hi Alsig,
> > > > > What do you mean by "doesn't work"?  Is SPI1 properly setup 
(IO
> > > pin
> > > > > selection and function, Master/Slave etc.) and enabled?  
Have
> > you
> > > > > checked the bus with a scope?  What hardware do you use?
> > > > >
> > > > > Krys
> > > > >
> > > > >
> > > > >
> > > > > ------------------------------------------------------------
----
> > --
> > > ------
> > > > > YAHOO! GROUPS LINKS
> > > > >
> > > > >     *  Visit your group "lpc2000
> > > > >       <http://groups.yahoo.com/group/lpc2000>" on the web.
> > > > >       
> > > > >     *  To unsubscribe from this group, send an email to:
> > > > >        lpc2000-unsubscribe@yahoogroups.com
> > > > >       <mailto:lpc2000-unsubscribe@yahoogroups.com?
> > > subject=Unsubscribe>
> > > > >       
> > > > >     *  Your use of Yahoo! Groups is subject to the Yahoo! 
Terms
> > of
> > > > >       Service <http://docs.yahoo.com/info/terms/>.
> > > > >
> > > > >
> > > > > ------------------------------------------------------------
----
> > --
> > > ------
> > > > >
> > > >
> > > >
> > > >
> > > > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> >
> > SPONSORED LINKS
> > Microcontrollers 
> > <http://groups.yahoo.com/gads?
t=ms&k=Microcontrollers&w1=Microcontrollers&w2=Microprocessor&w3=Intel
+microprocessors&w4=Pic+microcontrollers&w5=8085+microprocessor&c=5&s=
120&.sig=OPqm0ilH6VyGn-geZ0nNwA> 
> > 	Microprocessor 
> > <http://groups.yahoo.com/gads?
t=ms&k=Microprocessor&w1=Microcontrollers&w2=Microprocessor&w3=Intel+m
icroprocessors&w4=Pic+microcontrollers&w5=8085+microprocessor&c=5&s=12
0&.sig=e6n93hF7rArBsrPQJltQ_w> 
> > 	Intel microprocessors 
> > <http://groups.yahoo.com/gads?
t=ms&k=Intel+microprocessors&w1=Microcontrollers&w2=Microprocessor&w3=
Intel+microprocessors&w4=Pic+microcontrollers&w5=8085+microprocessor&c
=5&s=120&.sig=EENrTtKaQUw-Vd0BgTdDmw> 
> >
> > Pic microcontrollers 
> > <http://groups.yahoo.com/gads?
t=ms&k=Pic+microcontrollers&w1=Microcontrollers&w2=Microprocessor&w3=I
ntel+microprocessors&w4=Pic+microcontrollers&w5=8085+microprocessor&c=
5&s=120&.sig=iYT6za1gT3-VT1hwIylDpw> 
> > 	8085 microprocessor 
> > <http://groups.yahoo.com/gads?
t=ms&k=8085+microprocessor&w1=Microcontrollers&w2=Microprocessor&w3=In
tel+microprocessors&w4=Pic+microcontrollers&w5=8085+microprocessor&c=5
&s=120&.sig=PhYMBsCkQptYbazQFyNujQ> 
> >
> >
> >
> > ------------------------------------------------------------------
------
> > YAHOO! GROUPS LINKS
> >
> >     *  Visit your group "lpc2000
> >       <http://groups.yahoo.com/group/lpc2000>" on the web.
> >        
> >     *  To unsubscribe from this group, send an email to:
> >        lpc2000-unsubscribe@yahoogroups.com
> >       <mailto:lpc2000-unsubscribe@yahoogroups.com?
subject=Unsubscribe>
> >        
> >     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> >       Service <http://docs.yahoo.com/info/terms/>.
> >
> >
> > ------------------------------------------------------------------
------
> >
> 
> 
> 
> [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.