Yahoo Groups archive

Lpc2000

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

Thread

SPI MOSI NOT RESPONDING

SPI MOSI NOT RESPONDING

2005-04-05 by rockraj_2003

Hello Mark,

I am using SPI to configure the DP1203.

LPC2106 - FULL DUPLEX.
DP1203 - HALF DUPLEX.

I just wrote ur program in IAR but when the SSEL is low it's not 
responding.
There is no SCK.

When SSEL pin is high it's responding correctly.
I can able to see the Serial Clock and the Data Transmission in the 
MOSI line as well.
But I can't able to receive any data in the MISO line.
It's in low state. There is no response.

When i transmit the Tx1 it's giving only "00" for 8 times.
Here is the simple code. 

#include "LPC210x.H"
#include "ma_uart0.h"

void main (void)
{
 unsigned char Tx[] = {1,2,3,4,5,6,7,8}; 
 unsigned char Tx1[8];

 unsigned short Length;

 unsigned char *ptrData,*Rx;

 MA_Init_UART0();
 MA_Reset_UART0();
 Length = sizeof(Tx);

 ptrData = Tx;
 VPBDIV = 0;
 Rx = Tx1;
 
 IODIR = 0x80;
 IOSET = 0x80;
 PINSEL0 = 0x5505;
 SPI_SPCCR = 0xFF;
 SPI_SPCR = 0x20;

while (Length--) 
{
  IOSET = 0x80; // remove SSEL
  SPI_SPDR = *ptrData++; // Set data Byte
  while((SPI_SPSR & 0x80)==0);
  IOCLR = 0x80; // activate SSEL
  *Rx++ = (unsigned char)SPI_SPDR;
}  
for(short i=0;i<=7;i++)
  {
    while(U0LSR==0x00){;}
    U0THR = Tx1[i] ;  
    }
}

Kindly Help me to solve the probl.

Is there any other example code that send as well as receive data in 
MOSI & MISO line throu SCK.

with regards,
Rajendra R



Hi Rajendra (Mark),

Mark has covered SPI operation very well, that's the nuts and bolts 
of it.

Maybe one last remark to make it sink in a bit easier again.
Think of SPI as a 16 bit shift register, with a "Master" as 8 bit 
shift
register,
and a Slave as an 8 bit shift register, and with a feedback from the 
output of
bit 15
into bit 0.

Thus, all that happens is that Master and Slave _exchange_ their 8 
bits when the
8 clock pulses are issued. No matter which side (ie. Master or 
Slave), data is
read
on one edge of clock pulses, while data is output on the opposite 
edge of the
clock pulse.
This means the Master for example can change the "1" or "0" data 
output while
it's
reading the data line, since the Slave is NOT sampling MOSI at that 
moment, and
vice-versa
for the Slave with MISO.

The only thing that qualifies a Master from a Slave is whom issues 
the clock
pulses.
Hence the whole system is synchronous.
There might even be times where it is handy to "hold" the SPI 
transfer. That
even can
be one in HW : Some SPI (SLAVE) devices have a /HOLD input pin.
(A bit restricting IMO, because you can only change /Hold when 
clock "idle").

Because you can clock data at rising or falling edge - and - you can 
keep your
clock "Idle"
High or Low _between_ bit transfers, there are FOUR combinations ::::
referred to sometimes as SPI Mode 0,1,2 and 3.

Happy trails
-- Kris

> Hallo Rajendra
>
> When the SPI (master) sends 8 bits of data over the MOSI line it
> also clocks in 8 bits of data via the MISO line. Therefore when a
> byte of data has successfully been sent (SPI_SPSR & 0x80 becomes
> true) it also has a byte of received data which can be read from
> SPI_SPDR. (when no slave it is probably 0xff or 0x00 depending on
> the line state - if the slave has nothing to send it depends on the
> device - eg. the LPC210x in slave mode sends byte the last received
> byte)
>
> This means that the slave must prepare and send data - the exact
> sequence will depend on your peripheral device but it generally
> means that you must first send a command byte to inform which data
> it should sent to you and then you can read it (one or a sequence of
> bytes). If the master has no data to send while reading the byte(s)
> it can send a dummy byte (0xff or 0x00 etc.).
>
> The code to send and also read in full duplex (assuming the slave
> supports it) could look like this:
>
> void fnSendReceive(unsigned char *out, unsigned char *in, unsigned
> short usLength)
> {
> while (usLength--) {
> IOCLR = SPI_SSEL_OUT; // activate SSEL
> SPDR = *out; // send data byte
> while (!(SPSR & SPIF)) {}; // wait for transmission to
> complete
> IOSET = SPI_SSEL_OUT; // remove SSEL
> *in++ = (unsigned char)SPDR; // save data
> }
> }
>
> Note that the LPC210x has a very simple SPI which has only one
> interrupt flag to indicate when the transmission has completed and
> the received data is available. There is no buffering in the
> transmitter and so it is imperative that the flag is set before
> sending the next byte otherwise it may be lost - as consequence the
> throughput tends to suffer since the software processing has to take
> place almost completely between transmission periods and it is
> hardly possible to do any work during the byte transmission 
interval.
Show quoted textHide quoted text
>
> Regards
>
> Mark Butcher
>
> www.mjbc.ch
>
>
> --- In lpc2000@yahoogroups.com, "rockraj_2003" <rockraj_2003@y...>
> wrote:
> >
> > Hello Mark,
> >
> > Thanks for Ur Response.I tried Ur Code its working fine.
> > I aslo changed my prog.This Code is also giving the Same response.
> > I didn't CLR the SSEL pin at all.But I regularly changed SPIF to
> 0x00.
> >
> > Now, my doubt is if i want to use MISO as well what should i do.
> > Since in the Data Sheet THE mentioned SPI as duplex.
> >
> > How I can use MISO.
> >
> > Silly Question, but I don't know about this.
> > If the SPI is in MOSI, it can send DATA (MASTER OUTPUT) at the
> Same
> > time it receive data in SLAVE.(SLAVE INPUT).How much time it will
> > wait to receive DATA. If again I put some Data to the SPI_SPDR it
> > will transmit or it will wait to receive.
> >
> > > > #define SPI_SPCR (*((volatile unsigned char *)
> 0xE0020000))
> > > > #define SPI_SPSR (*((volatile unsigned char *)
> 0xE0020004))
> > > > #define SPI_SPDR (*((volatile unsigned char *)
> 0xE0020008))
> > > > #define SPI_SPCCR (*((volatile unsigned char *)
> 0xE002000C))
> > > > #define SPI_SPTCR (*((volatile unsigned char *)
> 0xE0020010))
> > > > #define SPI_SPTSR (*((volatile unsigned char *)
> 0xE0020014))
> > > > #define SPI_SPTOR (*((volatile unsigned char *)
> 0xE0020018))
> > > > #define SPI_SPINT (*((volatile unsigned char *)
> 0xE002001C))
> > > >
> > > > int main (void)
> > > > {
> > > > int i;
> > > > VPBDIV = 1;
> > > > IODIR = 0x80;
> > > > IOSET = 0x80;
> > > > PINSEL0 = 0x5500;
> > > > SPI_SPCCR = 0x93;
> > > > SPI_SPCR = 0x20;
> > > > while (1) {
> > > > do SPI_SPDR = 0x55;
> > > > while((SPI_SPSR & 0x80)==0);
> > > > SPI_SPSR = 0x00;
> > > > do SPI_SPDR = 0x0F;
> > > > while((SPI_SPSR & 0x80)==0);
> > > > SPI_SPSR = 0x00;
> > > > do SPI_SPDR = 0xF0;
> > > > while((SPI_SPSR & 0x80)==0);
> > > > SPI_SPSR = 0x00;
> > > > }
> > > > }
> >
> >
> > with Regards
> > Rajendra R
> >
>
>
>
>
>
> 
>
>

Re: SPI MOSI NOT RESPONDING

2005-04-05 by Mark Butcher

Hallo Rajendra

I think you have the following problems

while (Length--)
{
IOSET = 0x80; // remove SSEL      ------------------ 1/2
SPI_SPDR = *ptrData++; // Set data Byte
while((SPI_SPSR & 0x80)==0);
IOCLR = 0x80; // activate SSEL    ------------------ 3
*Rx++ = (unsigned char)SPI_SPDR;
}
for(short i=0;i<=7;i++)
{
while(U0LSR==0x00){;}
U0THR = Tx1[i] ;
}
}

1. The SPI has a problem with the SSEL line. You are using it as a 
general purpose port which doesn't work. You have to leave the SSEL 
line programmed as SSEL and use another general purpose I/O as SSEL 
output. [if the SSEL line is not programmed as SSEL and is not 
pulled high the SPI doesn't work in master mode.]

2/3. You are controlling the polarity inversely to the code which I 
suggested. SSEL must be set low at 1/2 and removed (high) at 3.

Summary:
#define MY_SSEL 0x40   // use P0.6 as SSEL output
PINSEL0 &= ~0x0000ff00;
PINSEL0 |= 0x00005500; // use all SPi lines as special purpose
IOSET = MY_SSEL;       // 
IODIR |= MY_SSEL ;     // drive my SSEL output high

...
...


while (Length--)
{
IOCLR = MY_SSEL;       // activate SSEL ('0')
SPI_SPDR = *ptrData++; // Set data Byte
while((SPI_SPSR & 0x80)==0);   // wait for Tx and Rx to complete
IOCLR = 0x80;         // remove SSEL ('1')
*Rx++ = (unsigned char)SPI_SPDR; // store received byte for later
}

This should work then (don't forget to pull up the real SSEl line 
to '1').

Regards

Mark

www.mjbc.ch





--- In lpc2000@yahoogroups.com, "rockraj_2003" <rockraj_2003@y...> 
wrote:
> 
> Hello Mark,
> 
> I am using SPI to configure the DP1203.
> 
> LPC2106 - FULL DUPLEX.
> DP1203 - HALF DUPLEX.
> 
> I just wrote ur program in IAR but when the SSEL is low it's not 
> responding.
> There is no SCK.
> 
> When SSEL pin is high it's responding correctly.
> I can able to see the Serial Clock and the Data Transmission in 
the 
> MOSI line as well.
> But I can't able to receive any data in the MISO line.
> It's in low state. There is no response.
> 
> When i transmit the Tx1 it's giving only "00" for 8 times.
> Here is the simple code. 
> 
> #include "LPC210x.H"
> #include "ma_uart0.h"
> 
> void main (void)
> {
>  unsigned char Tx[] = {1,2,3,4,5,6,7,8}; 
>  unsigned char Tx1[8];
> 
>  unsigned short Length;
> 
>  unsigned char *ptrData,*Rx;
> 
>  MA_Init_UART0();
>  MA_Reset_UART0();
>  Length = sizeof(Tx);
> 
>  ptrData = Tx;
>  VPBDIV = 0;
>  Rx = Tx1;
>  
>  IODIR = 0x80;
>  IOSET = 0x80;
>  PINSEL0 = 0x5505;
>  SPI_SPCCR = 0xFF;
>  SPI_SPCR = 0x20;
> 
> while (Length--) 
> {
>   IOSET = 0x80; // remove SSEL
>   SPI_SPDR = *ptrData++; // Set data Byte
>   while((SPI_SPSR & 0x80)==0);
>   IOCLR = 0x80; // activate SSEL
>   *Rx++ = (unsigned char)SPI_SPDR;
> }  
> for(short i=0;i<=7;i++)
>   {
>     while(U0LSR==0x00){;}
>     U0THR = Tx1[i] ;  
>     }
> }
> 
> Kindly Help me to solve the probl.
> 
> Is there any other example code that send as well as receive data 
in 
Show quoted textHide quoted text
> MOSI & MISO line throu SCK.
> 
> with regards,
> Rajendra R
>

Re: [lpc2000] SPI MOSI NOT RESPONDING

2005-04-05 by Marko Pavlin (home)

Check this message:

http://groups.yahoo.com/group/lpc2000/message/4363

rockraj_2003 wrote:
Show quoted textHide quoted text
>
> Hello Mark,
>
> I am using SPI to configure the DP1203.
>
> LPC2106 - FULL DUPLEX.
> DP1203 - HALF DUPLEX.
>
> I just wrote ur program in IAR but when the SSEL is low it's not
> responding.
> There is no SCK.
>
> When SSEL pin is high it's responding correctly.
> I can able to see the Serial Clock and the Data Transmission in the
> MOSI line as well.
> But I can't able to receive any data in the MISO line.
> It's in low state. There is no response.
>
> When i transmit the Tx1 it's giving only "00" for 8 times.
> Here is the simple code.
>
> #include "LPC210x.H"
> #include "ma_uart0.h"
>
> void main (void)
> {
> unsigned char Tx[] = {1,2,3,4,5,6,7,8};
> unsigned char Tx1[8];
>
> unsigned short Length;
>
> unsigned char *ptrData,*Rx;
>
> MA_Init_UART0();
> MA_Reset_UART0();
> Length = sizeof(Tx);
>
> ptrData = Tx;
> VPBDIV = 0;
> Rx = Tx1;
>
> IODIR = 0x80;
> IOSET = 0x80;
> PINSEL0 = 0x5505;
> SPI_SPCCR = 0xFF;
> SPI_SPCR = 0x20;
>
> while (Length--)
> {
>   IOSET = 0x80; // remove SSEL
>   SPI_SPDR = *ptrData++; // Set data Byte
>   while((SPI_SPSR & 0x80)==0);
>   IOCLR = 0x80; // activate SSEL
>   *Rx++ = (unsigned char)SPI_SPDR;
> } 
> for(short i=0;i<=7;i++)
>   {
>     while(U0LSR==0x00){;}
>     U0THR = Tx1[i] ; 
>     }
> }
>
> Kindly Help me to solve the probl.
>
> Is there any other example code that send as well as receive data in
> MOSI & MISO line throu SCK.
>
> with regards,
> Rajendra R
>
>
>
> Hi Rajendra (Mark),
>
> Mark has covered SPI operation very well, that's the nuts and bolts
> of it.
>
> Maybe one last remark to make it sink in a bit easier again.
> Think of SPI as a 16 bit shift register, with a "Master" as 8 bit
> shift
> register,
> and a Slave as an 8 bit shift register, and with a feedback from the
> output of
> bit 15
> into bit 0.
>
> Thus, all that happens is that Master and Slave _exchange_ their 8
> bits when the
> 8 clock pulses are issued. No matter which side (ie. Master or
> Slave), data is
> read
> on one edge of clock pulses, while data is output on the opposite
> edge of the
> clock pulse.
> This means the Master for example can change the "1" or "0" data
> output while
> it's
> reading the data line, since the Slave is NOT sampling MOSI at that
> moment, and
> vice-versa
> for the Slave with MISO.
>
> The only thing that qualifies a Master from a Slave is whom issues
> the clock
> pulses.
> Hence the whole system is synchronous.
> There might even be times where it is handy to "hold" the SPI
> transfer. That
> even can
> be one in HW : Some SPI (SLAVE) devices have a /HOLD input pin.
> (A bit restricting IMO, because you can only change /Hold when
> clock "idle").
>
> Because you can clock data at rising or falling edge - and - you can
> keep your
> clock "Idle"
> High or Low _between_ bit transfers, there are FOUR combinations ::::
> referred to sometimes as SPI Mode 0,1,2 and 3.
>
> Happy trails
> -- Kris
>
> > Hallo Rajendra
> >
> > When the SPI (master) sends 8 bits of data over the MOSI line it
> > also clocks in 8 bits of data via the MISO line. Therefore when a
> > byte of data has successfully been sent (SPI_SPSR & 0x80 becomes
> > true) it also has a byte of received data which can be read from
> > SPI_SPDR. (when no slave it is probably 0xff or 0x00 depending on
> > the line state - if the slave has nothing to send it depends on the
> > device - eg. the LPC210x in slave mode sends byte the last received
> > byte)
> >
> > This means that the slave must prepare and send data - the exact
> > sequence will depend on your peripheral device but it generally
> > means that you must first send a command byte to inform which data
> > it should sent to you and then you can read it (one or a sequence of
> > bytes). If the master has no data to send while reading the byte(s)
> > it can send a dummy byte (0xff or 0x00 etc.).
> >
> > The code to send and also read in full duplex (assuming the slave
> > supports it) could look like this:
> >
> > void fnSendReceive(unsigned char *out, unsigned char *in, unsigned
> > short usLength)
> > {
> > while (usLength--) {
> > IOCLR = SPI_SSEL_OUT; // activate SSEL
> > SPDR = *out; // send data byte
> > while (!(SPSR & SPIF)) {}; // wait for transmission to
> > complete
> > IOSET = SPI_SSEL_OUT; // remove SSEL
> > *in++ = (unsigned char)SPDR; // save data
> > }
> > }
> >
> > Note that the LPC210x has a very simple SPI which has only one
> > interrupt flag to indicate when the transmission has completed and
> > the received data is available. There is no buffering in the
> > transmitter and so it is imperative that the flag is set before
> > sending the next byte otherwise it may be lost - as consequence the
> > throughput tends to suffer since the software processing has to take
> > place almost completely between transmission periods and it is
> > hardly possible to do any work during the byte transmission
> interval.
> >
> > Regards
> >
> > Mark Butcher
> >
> > www.mjbc.ch
> >
> >
> > --- In lpc2000@yahoogroups.com, "rockraj_2003" <rockraj_2003@y...>
> > wrote:
> > >
> > > Hello Mark,
> > >
> > > Thanks for Ur Response.I tried Ur Code its working fine.
> > > I aslo changed my prog.This Code is also giving the Same response.
> > > I didn't CLR the SSEL pin at all.But I regularly changed SPIF to
> > 0x00.
> > >
> > > Now, my doubt is if i want to use MISO as well what should i do.
> > > Since in the Data Sheet THE mentioned SPI as duplex.
> > >
> > > How I can use MISO.
> > >
> > > Silly Question, but I don't know about this.
> > > If the SPI is in MOSI, it can send DATA (MASTER OUTPUT) at the
> > Same
> > > time it receive data in SLAVE.(SLAVE INPUT).How much time it will
> > > wait to receive DATA. If again I put some Data to the SPI_SPDR it
> > > will transmit or it will wait to receive.
> > >
> > > > > #define SPI_SPCR (*((volatile unsigned char *)
> > 0xE0020000))
> > > > > #define SPI_SPSR (*((volatile unsigned char *)
> > 0xE0020004))
> > > > > #define SPI_SPDR (*((volatile unsigned char *)
> > 0xE0020008))
> > > > > #define SPI_SPCCR (*((volatile unsigned char *)
> > 0xE002000C))
> > > > > #define SPI_SPTCR (*((volatile unsigned char *)
> > 0xE0020010))
> > > > > #define SPI_SPTSR (*((volatile unsigned char *)
> > 0xE0020014))
> > > > > #define SPI_SPTOR (*((volatile unsigned char *)
> > 0xE0020018))
> > > > > #define SPI_SPINT (*((volatile unsigned char *)
> > 0xE002001C))
> > > > >
> > > > > int main (void)
> > > > > {
> > > > > int i;
> > > > > VPBDIV = 1;
> > > > > IODIR = 0x80;
> > > > > IOSET = 0x80;
> > > > > PINSEL0 = 0x5500;
> > > > > SPI_SPCCR = 0x93;
> > > > > SPI_SPCR = 0x20;
> > > > > while (1) {
> > > > > do SPI_SPDR = 0x55;
> > > > > while((SPI_SPSR & 0x80)==0);
> > > > > SPI_SPSR = 0x00;
> > > > > do SPI_SPDR = 0x0F;
> > > > > while((SPI_SPSR & 0x80)==0);
> > > > > SPI_SPSR = 0x00;
> > > > > do SPI_SPDR = 0xF0;
> > > > > while((SPI_SPSR & 0x80)==0);
> > > > > SPI_SPSR = 0x00;
> > > > > }
> > > > > }
> > >
> > >
> > > with Regards
> > > Rajendra R
> > >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
>
>
> *Yahoo! Groups Links*
>
>     * To visit your group on the web, go to:
>       http://groups.yahoo.com/group/lpc2000/
>        
>     * 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/>.
>
>

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.