EmbeddedRelated.com
Forums

UART+SPI, help needed

Started by "fx.marquand" May 6, 2008
Hello,

I'm currently student in placement (and french by the way, sorry if i
do some mistakes on my posts ^^'). I have to connect several sensors to
the kickstartboard (lpc2106) and monitor them on a terminal (for the
moment). The problem is I'm a real newbie when talking about ARM, I
only know PIC uC, and it's really different as you know... I'm not able
to send something on spi AND to send to uart in the same time.

Do some libraries exist (like for PIC) for quick programming?
Do you have a allready done example program with spi and uart together?
examples i found where not adapted or not compatible (uart example+spi
example)

I'm not the kind of parasite who post aiming that somebody will do the
job for me but i really need help. My placement tutor should help me
getting through this, teachin me, but he is never here, so i need you.
when i'll be more experimented, i'll contribute positively to the forum.

merci d'avance pour votre aide, :)

joris

An Engineer's Guide to the LPC2100 Series

--- In l..., "fx.marquand" wrote:
>
> Hello,
>
> I'm currently student in placement (and french by the way, sorry if i
> do some mistakes on my posts ^^'). I have to connect several sensors to
> the kickstartboard (lpc2106) and monitor them on a terminal (for the
> moment). The problem is I'm a real newbie when talking about ARM, I
> only know PIC uC, and it's really different as you know... I'm not able
> to send something on spi AND to send to uart in the same time.
>
> Do some libraries exist (like for PIC) for quick programming?
> Do you have a allready done example program with spi and uart together?
> examples i found where not adapted or not compatible (uart example+spi
> example)
>
> I'm not the kind of parasite who post aiming that somebody will do the
> job for me but i really need help. My placement tutor should help me
> getting through this, teachin me, but he is never here, so i need you.
> when i'll be more experimented, i'll contribute positively to the forum.
>
> merci d'avance pour votre aide, :)
>
> joris
>

I have no idea where to start so if you already have some of this,
just ignore:

1) Download "ARM Cross Development with Eclipse" At a minimum you
will use the startup code and the linker script.
http://www.sparkfun.com/tutorial/ARM/ARM_Cross_Development_with_Eclipse.pdf
The code is at http://www.olimex.com/dev/soft/arm/LPC/sourcecode.zip

2) Download and install YAGARTO (assuming WinXP) This will give you a
nicely integrated development platform.

3) Make the blinking LED project from step 1 work with YAGARTO. This
will verify that you can program the chip.

4) You can get UART code from the LPC21-6_Examples.zip file in the
Files section here on Yahoo. There is also a file LPC210xSPI.zip but
it is written for the IAR compiler. It is probably useless in that it
is designed for some kind of RTOS. But, SPI is simple, especially if
your device is a master. You can get the LPC2148 version in the fatfs
folder of the sample code at www.jcwren.com/arm/ The 2106 version is
nearly identical.

Richard

> I have no idea where to start so if you already have some of this,
> just ignore:
>
> 1) Download "ARM Cross Development with Eclipse" At a minimum you
> will use the startup code and the linker script.
>
http://www.sparkfun.com/tutorial/ARM/ARM_Cross_Development_with_Eclips
e.pdf
> The code is at http://www.olimex.com/dev/soft/arm/LPC/sourcecode.zip
>
> 2) Download and install YAGARTO (assuming WinXP) This will give
you a
> nicely integrated development platform.
>
> 3) Make the blinking LED project from step 1 work with YAGARTO.
This
> will verify that you can program the chip.
>
> 4) You can get UART code from the LPC21-6_Examples.zip file in the
> Files section here on Yahoo. There is also a file LPC210xSPI.zip
but
> it is written for the IAR compiler. It is probably useless in that
it
> is designed for some kind of RTOS. But, SPI is simple, especially
if
> your device is a master. You can get the LPC2148 version in the
fatfs
> folder of the sample code at www.jcwren.com/arm/ The 2106 version
is
> nearly identical.
>
> Richard
>
thanks for reply Richard.

I've tried with IAR worbench. here is the code i tried on my
kickstart board for spi :

#include"LPC210x.h"

void Initialize(void);

/* Macro Definitions */

#define SPIF (1<<7) //this is 0x01 ie spiflag right?
#define DATA 0xC1 //rdm data to send

/************************* MAIN *************************/
int main()
{
Initialize();

while(1)
{
/* Write data out */
SPDRA; //once smthing is written to SPDR data trans begin
right?

while(!(SPSR & SPIF)){} //wait for the flag
}
}
/*************** System Initialization ***************/
void Initialize()
{
/* Configure Pin Connect Block */
PINSEL0=0x005500; //p0.4 .5 .6 .7
/* Set pclk to same as cclk */
VPBDIV=0x1;
/* Set to highest speed for SPI at 10 MHz- > 1.25 MHz */
SPCCR=0x8;
/* Device selected as master */
SPCR=0x14;
}

and this code doesn't work... :( i dont mind transmition speed for
the moment, I only watch the spi output on the board with the
oscilloscope... and nothing happens...

have suggestions?

thanks

joris
I forgot to say that blinkin leds work well, and uart too.
--- In l..., "fx.marquand" wrote:
>
> > I have no idea where to start so if you already have some of this,
> > just ignore:
> >
> > 1) Download "ARM Cross Development with Eclipse" At a minimum you
> > will use the startup code and the linker script.
> >
> http://www.sparkfun.com/tutorial/ARM/ARM_Cross_Development_with_Eclips
> e.pdf
> > The code is at http://www.olimex.com/dev/soft/arm/LPC/sourcecode.zip
> >
> > 2) Download and install YAGARTO (assuming WinXP) This will give
> you a
> > nicely integrated development platform.
> >
> > 3) Make the blinking LED project from step 1 work with YAGARTO.
> This
> > will verify that you can program the chip.
> >
> > 4) You can get UART code from the LPC21-6_Examples.zip file in the
> > Files section here on Yahoo. There is also a file LPC210xSPI.zip
> but
> > it is written for the IAR compiler. It is probably useless in that
> it
> > is designed for some kind of RTOS. But, SPI is simple, especially
> if
> > your device is a master. You can get the LPC2148 version in the
> fatfs
> > folder of the sample code at www.jcwren.com/arm/ The 2106 version
> is
> > nearly identical.
> >
> > Richard
> >
> thanks for reply Richard.
>
> I've tried with IAR worbench. here is the code i tried on my
> kickstart board for spi :
>
> #include"LPC210x.h"
>
> void Initialize(void);
>
> /* Macro Definitions */
>
> #define SPIF (1<<7) //this is 0x01 ie spiflag right?
> #define DATA 0xC1 //rdm data to send
>
> /************************* MAIN *************************/
> int main()
> {
> Initialize();
>
> while(1)
> {
> /* Write data out */
> SPDRA; //once smthing is written to SPDR data trans begin
> right?
>
> while(!(SPSR & SPIF)){} //wait for the flag
> }
> }
> /*************** System Initialization ***************/
> void Initialize()
> {
> /* Configure Pin Connect Block */
> PINSEL0=0x005500; //p0.4 .5 .6 .7
> /* Set pclk to same as cclk */
> VPBDIV=0x1;
> /* Set to highest speed for SPI at 10 MHz- > 1.25 MHz */
> SPCCR=0x8;
> /* Device selected as master */
> SPCR=0x14;
> }
> and this code doesn't work... :( i dont mind transmition speed for
> the moment, I only watch the spi output on the board with the
> oscilloscope... and nothing happens...
>
> have suggestions?
>
> thanks
>
> joris
>

I'm not sure your initialization is correct. From my spi.h file:

// bits for SPI_SPCR - spi control register
#define SPI_SPIE (0x00000080) // 1->interrupt set when SPIF or MODF
bits are set
#define SPI_LSBF (0x00000040) // 1->spi data is transferred LSB first
#define SPI_MSTR (0x00000020) // 1->spi operates as Master
#define SPI_CPOL (0x00000010) // 1->SCK is active low, else active high
#define SPI_CPHA (0x00000008) // Clock phase control - page 128

>From my setup.c file:

PINSEL0 |= 0x00005500; // set proper bits for SPI
SPI_SPCR = SPI_MSTR | SPI_CPOL | SPI_CPHA | SPI_LSBF; // set spi as
a master
SPI_SPCCR = SPI_DIVIDER; // set divider

I think the way you handle PINSEL0 (not OR'ing the bits) may cause a
problem with other IO's.

Also, you need to be certain that P0.7 (SSEL') is pulled high even
though you are operating in MASTER mode.

Richard

--- In l..., "rtstofer" wrote:
>
> --- In l..., "fx.marquand" wrote:
> >
> > > I have no idea where to start so if you already have some of
this,
> > > just ignore:
> > >
> > > 1) Download "ARM Cross Development with Eclipse" At a minimum
you
> > > will use the startup code and the linker script.
> > >
> >
http://www.sparkfun.com/tutorial/ARM/ARM_Cross_Development_with_Eclips
> > e.pdf
> > > The code is at
http://www.olimex.com/dev/soft/arm/LPC/sourcecode.zip
> > >
> > > 2) Download and install YAGARTO (assuming WinXP) This will
give
> > you a
> > > nicely integrated development platform.
> > >
> > > 3) Make the blinking LED project from step 1 work with
YAGARTO.
> > This
> > > will verify that you can program the chip.
> > >
> > > 4) You can get UART code from the LPC21-6_Examples.zip file in
the
> > > Files section here on Yahoo. There is also a file
LPC210xSPI.zip
> > but
> > > it is written for the IAR compiler. It is probably useless in
that
> > it
> > > is designed for some kind of RTOS. But, SPI is simple,
especially
> > if
> > > your device is a master. You can get the LPC2148 version in
the
> > fatfs
> > > folder of the sample code at www.jcwren.com/arm/ The 2106
version
> > is
> > > nearly identical.
> > >
> > > Richard
> > >
> >
> >
> > thanks for reply Richard.
> >
> > I've tried with IAR worbench. here is the code i tried on my
> > kickstart board for spi :
> >
> >
> >
> > #include"LPC210x.h"
> >
> > void Initialize(void);
> >
> > /* Macro Definitions */
> >
> > #define SPIF (1<<7) //this is 0x01 ie spiflag right?
> > #define DATA 0xC1 //rdm data to send
> >
> > /************************* MAIN *************************/
> > int main()
> > {
> > Initialize();
> >
> > while(1)
> > {
> > /* Write data out */
> > SPDRA; //once smthing is written to SPDR data trans begin
> > right?
> >
> >
> >
> > while(!(SPSR & SPIF)){} //wait for the flag
> > }
> > }
> > /*************** System Initialization ***************/
> > void Initialize()
> > {
> > /* Configure Pin Connect Block */
> > PINSEL0=0x005500; //p0.4 .5 .6 .7
> > /* Set pclk to same as cclk */
> > VPBDIV=0x1;
> > /* Set to highest speed for SPI at 10 MHz- > 1.25 MHz */
> > SPCCR=0x8;
> > /* Device selected as master */
> > SPCR=0x14;
> > }
> >
> >
> >
> >
> > and this code doesn't work... :( i dont mind transmition speed
for
> > the moment, I only watch the spi output on the board with the
> > oscilloscope... and nothing happens...
> >
> > have suggestions?
> >
> > thanks
> >
> > joris
> > I'm not sure your initialization is correct. From my spi.h file:
>
> // bits for SPI_SPCR - spi control register
> #define SPI_SPIE (0x00000080) // 1->interrupt set when SPIF
or MODF
> bits are set
> #define SPI_LSBF (0x00000040) // 1->spi data is transferred
LSB first
> #define SPI_MSTR (0x00000020) // 1->spi operates as Master
> #define SPI_CPOL (0x00000010) // 1->SCK is active low, else
active high
> #define SPI_CPHA (0x00000008) // Clock phase control - page
128
>
> From my setup.c file:
>
> PINSEL0 |= 0x00005500; // set proper bits for SPI
> SPI_SPCR = SPI_MSTR | SPI_CPOL | SPI_CPHA | SPI_LSBF;
// set spi as
> a master
> SPI_SPCCR = SPI_DIVIDER; // set divider
>
> I think the way you handle PINSEL0 (not OR'ing the bits) may cause a
> problem with other IO's.
>
> Also, you need to be certain that P0.7 (SSEL') is pulled high even
> though you are operating in MASTER mode.
>
> Richard
>

I put | (or) as you told me for pinsel. i also put your spcr config
(master mode, Cpol, phase control and lsb first). i tried with p07
high and low, but no changes... gettin mad lol

i thought my oscillo was to blame but my logic analyser stay quiet
too... I dont understand why...

is it possible jtag debug mode interfer with spi?
> I put | (or) as you told me for pinsel. i also put your spcr config
> (master mode, Cpol, phase control and lsb first). i tried with p07
> high and low, but no changes... gettin mad lol
>
> i thought my oscillo was to blame but my logic analyser stay quiet
> too... I dont understand why...
>
> is it possible jtag debug mode interfer with spi?
>

Master SPI is the easiest possible peripheral to get working. Are you
sure you aren't doing PINSEL = somewhere else, perhaps while
initializing the UART. This would turn off the SPI gadget.

Try writing a program that just sends chars out the SPI gadget. No
extra features, just SPI master output. If it still doesn't work,
ZIP it up (include all files, linker script and makefile) and post it
in the Files folder. Post the file name.

The entire C code should be less than 50 lines and the crt.s code
should be pretty standard.

I am working with slave SPI at the moment so it might not take long
to find the error.

Richard

--- In l..., "fx.marquand" wrote:

>
> I've tried with IAR worbench. here is the code i tried on my
> kickstart board for spi :
>
> #include"LPC210x.h"
>
> void Initialize(void);
>
> /* Macro Definitions */
>
> #define SPIF (1<<7) //this is 0x01 ie spiflag right?
> #define DATA 0xC1 //rdm data to send
>
> /************************* MAIN *************************/
> int main()
> {
> Initialize();
>
> while(1)
> {
> /* Write data out */
> SPDRA; //once smthing is written to SPDR data trans begin
> right?
>
> while(!(SPSR & SPIF)){} //wait for the flag
> }
> }
> /*************** System Initialization ***************/
> void Initialize()
> {
> /* Configure Pin Connect Block */
> PINSEL0=0x005500; //p0.4 .5 .6 .7
> /* Set pclk to same as cclk */
> VPBDIV=0x1;
> /* Set to highest speed for SPI at 10 MHz- > 1.25 MHz */
> SPCCR=0x8;
> /* Device selected as master */
> SPCR=0x14;
> }
> and this code doesn't work... :( i dont mind transmition speed for
> the moment, I only watch the spi output on the board with the
> oscilloscope... and nothing happens...
>
> have suggestions?
>
> thanks
>
> joris
>

The send/receive byte procedure in a pooling mode should look
something like this:

SPDRA; //Send a byte.
while(!(SPSR & SPIF)){} //Wait for the flag
SPDR; // Read the data register

Check also:
1. You have powered up the SPI in PCONP register;
2. You are not accidentally reconfigure PINSEL register after SPI
initialization;
3. You have configured SSEL pin in PINSEL register and have externally
a pullup resistor tied to it;

Regards
Zdravko Dimitrov

--- In l..., "rtstofer" wrote:
>
> > I put | (or) as you told me for pinsel. i also put your spcr
config
> > (master mode, Cpol, phase control and lsb first). i tried with
p07
> > high and low, but no changes... gettin mad lol
> >
> > i thought my oscillo was to blame but my logic analyser stay
quiet
> > too... I dont understand why...
> >
> > is it possible jtag debug mode interfer with spi?
> > Master SPI is the easiest possible peripheral to get working. Are
you
> sure you aren't doing PINSEL = somewhere else, perhaps while
> initializing the UART. This would turn off the SPI gadget.
>
> Try writing a program that just sends chars out the SPI gadget. No
> extra features, just SPI master output. If it still doesn't work,
> ZIP it up (include all files, linker script and makefile) and post
it
> in the Files folder. Post the file name.
>
> The entire C code should be less than 50 lines and the crt.s code
> should be pretty standard.
>
> I am working with slave SPI at the moment so it might not take long
> to find the error.
>
> Richard
>
ok i understood my error... the program is "lost" at the beginning.
It doent know where to start! i think a file is needed for init, and
i didnt know about it... can somebody tell me the basics?

thanks for all !

joris