EmbeddedRelated.com
Forums

First time programming SPI on LPC2000

Started by jdauchot November 8, 2007
Hi

I need to program the SPI interface. I am using the example from the
AN10369 UART/SPI/IIC code examples. The code does not work

#include"LPC2.h"
void Initialize(void);
/* Macro Definitions */
#define SPIF (1<<7)
#define DATA 0xC1
/************************* MAIN *************************/
int main()
{
Initialize();
/* Do forever */
while(1)
{
/* Write data out */
SPDR=DATA;
/* Wait for transfer to be completed */
while(!(SPSR & SPIF)){}
}
}
/*************** System Initialization ***************/
void Initialize()
{
/* Configure Pin Connect Block */
PINSEL0=0x5500;
/* 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=0x20;
}
I do not have any devices connected to the SPI bus and I only want to
see the signals with a scope.

Can anyone help

Regards

Jean-Jacques



An Engineer's Guide to the LPC2100 Series

----- Original Message -----
From: "jdauchot"
To:
Sent: Thursday, November 08, 2007 7:52 PM
Subject: [lpc2000] First time programming SPI on LPC2000
Hi

I need to program the SPI interface. I am using the example from the
AN10369 UART/SPI/IIC code examples. The code does not work
Have you got the output connected to the input? You need that for a loopback
test.

Leon
----- Original Message -----
From: "jdauchot"
To:
Sent: Thursday, November 08, 2007 8:01 PM
Subject: [lpc2000] Re: First time programming SPI on LPC2000
> Do I really need to loopback to monitor the signals on a scope ?

Yes. Think of SPI as being two connected shift registers, one on the master
and one on the slave.

Leon
Sorry, but I fail to understand this, I should be able to see the CLK output
and the data going out without looping back

Bit like looking at a UART port output?

Jean-Jacques

> Do I really need to loopback to monitor the signals on a scope ?

Yes. Think of SPI as being two connected shift registers, one on the master
and one on the slave.

Leon
----- Original Message -----
From: "Jean-Jacques Dauchot"
To:
Sent: Thursday, November 08, 2007 8:52 PM
Subject: RE: [lpc2000] Re: First time programming SPI on LPC2000
> Sorry, but I fail to understand this, I should be able to see the CLK
> output
> and the data going out without looping back

If you loopback you can check that the data are coming back OK, using the
debugger.

Leon
Jean-Jacques,

Yes you can see the SPI outputs on the scope. I have done this.

In your original code post it appears that you are setting up the SPI
in master mode, but you've configured all of the SPI pins for SPI mode
including the SSEL pin (PINSEL0=0x5500;)

The User Manual says that SSEL is an input only pin. (Chapter 12
section 3). When I first starting working with the SPI interface it
wouldn't work if I configured it as a Master and the pin as SSEL. If
you want the SPI to be a Master, try setting PINSEL |= 0x1500.

Regards
--- In l..., "jdauchot" wrote:
>
> Do I really need to loopback to monitor the signals on a scope ?
> Jean-Jacques
>

Hi,

I've used the SPI port on the LPC2132 and I have verified the
signals using a Logic Analyzer without looping back the signals or
connecting them to another SPI port.

I noticed in your original post that you attempting to setup the SPI
as a master but have also configured the IO for SSEL (PINSEL 0x5500). The User's Manual for the LPC2132 (chp. 12-3) states that
SSEL is only an input. I believe that I had an issue where the SPI
would not send out any information if it's setup to be a master and
SSEL IO is chosen.

If you really want the SPI to be a Master, try not setting up the
SSEL functionality (PINSEL |= 0x1500).

Chris
Hi

I use the code from a NXP application note.

Does this SSEL0 pin has to be pulled up to VCC or is it done already
done on chip?

Regards
Jean-Jacques
--- In l..., "geeseelam"
wrote:
>
> --- In l..., "jdauchot" wrote:
> >
> > Do I really need to loopback to monitor the signals on a scope ?
> >
> >
> > Jean-Jacques
> > Hi,
>
> I've used the SPI port on the LPC2132 and I have verified the
> signals using a Logic Analyzer without looping back the signals or
> connecting them to another SPI port.
>
> I noticed in your original post that you attempting to setup the
SPI
> as a master but have also configured the IO for SSEL (PINSEL > 0x5500). The User's Manual for the LPC2132 (chp. 12-3) states that
> SSEL is only an input. I believe that I had an issue where the SPI
> would not send out any information if it's setup to be a master and
> SSEL IO is chosen.
>
> If you really want the SPI to be a Master, try not setting up the
> SSEL functionality (PINSEL |= 0x1500).
>
> Chris
>
Hi Chris

Yes I got it going now, thanks.

Now, I have got to learn how to use SPI protocol

I want to use analog devices AD7708.

I understand that you can receive data while sending data at the same time.
But the master drives the clock

So if I want to read from a register I got to send the address of the
register on the bus than send it again to clock its data in the LPC2000.

Is this correct?

Regards

Jean-Jacques

>>In my particular application, I have left the pin float and observed
>>it on a scope and logic analyzer. Any luck?

>>Regards,
>>Chris

_,_._,___
> So if I want to read from a register I got to send
> the address of the
> register on the bus than send it again to clock its
> data in the LPC2000.
>
> Is this correct?
>
>
>
> Regards
>
>
>
> Jean-Jacques
>
>
Hi

The way you are thinking is half duplex mode, wich is
when you send the register address on one clock burts
sequence and then you must drive another clock burst
with no valid info to read the devices response.
To work in full duplex mode, you need to send the
next address and on the same clock burst youll have
the last address data response. For a raw example,
your code starts and you want ro read the register
address 0x01, so you send this address on the bus, and
dont read nothing, because the program just strated
now. So, the next address you want to read is 0x02, so
when you send 0x02 on the bus, you can read the answer
from the previous address (0x01), on the same clock
burst used to transmit the 0x02, and this goes on.

Hope this helps
Abra sua conta no Yahoo! Mail, o ico sem limite de espa para armazenamento!
http://br.mail.yahoo.com/