Yahoo Groups archive

Lpc2000

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

Thread

SPI usage

SPI usage

2005-01-04 by acetoel

Hello...

Is there any sample code that shows how to read and write a byte on
the SPI bus? or any SPI sample code?

Thanks

Ezequiel

Re: [lpc2000] SPI usage

2005-01-05 by Bruce Paterson

acetoel wrote:

> 
> Hello...
> 
> Is there any sample code that shows how to read and write a byte on
> the SPI bus? or any SPI sample code?
> 
> Thanks
> 
> Ezequiel

I just found ARMlib which contains SPI code:

http://hubbard.engr.scu.edu/embedded/arm/armlib/

-- 
Cheers,
Bruce

Re: [lpc2000] SPI usage

2005-01-05 by Bruce Paterson

acetoel wrote:

> 
> Hello...
> 
> Is there any sample code that shows how to read and write a byte on
> the SPI bus? or any SPI sample code?

Ooops sorry ! My message about ARMlib seems to be premature on furthur 
investigation. It's only byte (not interrupt message based) and has only 
C stubs at present.

-- 
Cheers,
Bruce
-------------------------------------------------------------------
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom
they are addressed. If you have received this email in error please
notify the system manager.

     /\\\/\\\/\\\    /   /      Bruce Paterson
    /  \\\ \\\ \\\  /   /    Senior Design Engineer
   /   /\\\/\\\/\\\/   /   8 Anzed Court, Mulgrave, Vic, 3170
  /   /  \\\ \\\ \\\  /  PO Box 4112, Mulgrave, Vic, 3170, Australia
/   /    \\\/\\\ \\\/   Ph: +61 3 8561 4232   Fax: +61 3 9560 9055
       Tele-IP Ltd.      Email: bruce@...    Icq: #32015991
                         WWW:   http://www.tele-ip.com       VK3TJN
-------------------------------------------------------------------

Re: SPI usage

2005-01-06 by acetoel

Ok... here is a piece of code that I make.. please somebody give a
hand, I don't want to bit bang a IO pin to make a SPI communication.
Eventhough I will communicate with a Atmel Dataflash, and the speed is
not important (I have to get at least 52k/sec, with SPI at 7.5MH I get
more than 900k/sec, and with bit banging at 1Mhz I get 125k/sec which
is enough).
Here is my code to send a byte, and to receive... really I need
something bidirectional (send and receive at the same time).


#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)) 


void spi_init(unsigned long PCLKBus, SPIRate, CPHA, CPOL, MSTR, LSBF,
SPIE) {
 unsigned long SPIDivider;
 SPI_SPCR=0x00000000; // Disable SPI
 
// Calculate SPI_SPCCR - MIN SPIC_SPCCR = 8 -> @60MHZ, SPIRate = 7.5Mhz 
 SPIDivider = PCLKBus / SPIRate;
 if (SPIDivider <= 0x7) {
   SPIDivider = 0x00000008; // MAX Speed for any PCLK Speed
}
 SPI_SPCCR = SPIDivider;
 
// Set The SPI Mode

 if (CPHA == 1 ) {
    SPI_SPCR = (SPI_SPCR + 0x00000008);
 }
 
 if (CPOL == 1) {
    SPI_SPCR = SPI_SPCR + 0x00000010;
 } 
 
 if (LSBF == 1) {
    SPI_SPCR = SPI_SPCR + 0x00000040; 
 }
 
 if (MSTR == 1) {
 	SPI_SPCR = SPI_SPCR + 0x00000020;
 } 
}

void spi_sendbyte (unsigned char spidata) {
	SPI_SPDR = spidata;
	while ((SPI_SPSR & 0x80) == 1) {} //Waits until TX is complete
	SPI_SPSR = SPI_SPSR & (1 << 7)
}


-------------------------------------------------------------
 

Thanks
Ezequiel


--- In lpc2000@yahoogroups.com, Bruce Paterson <bruce@t...> wrote:
> acetoel wrote:
> 
> > 
> > Hello...
> > 
> > Is there any sample code that shows how to read and write a byte on
> > the SPI bus? or any SPI sample code?
> 
> Ooops sorry ! My message about ARMlib seems to be premature on furthur 
> investigation. It's only byte (not interrupt message based) and has
only 
Show quoted textHide quoted text
> C stubs at present.
> 
> -- 
> Cheers,
> Bruce
> -------------------------------------------------------------------
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom
> they are addressed. If you have received this email in error please
> notify the system manager.
> 
>      /\\\/\\\/\\\    /   /      Bruce Paterson
>     /  \\\ \\\ \\\  /   /    Senior Design Engineer
>    /   /\\\/\\\/\\\/   /   8 Anzed Court, Mulgrave, Vic, 3170
>   /   /  \\\ \\\ \\\  /  PO Box 4112, Mulgrave, Vic, 3170, Australia
> /   /    \\\/\\\ \\\/   Ph: +61 3 8561 4232   Fax: +61 3 9560 9055
>        Tele-IP Ltd.      Email: bruce@t...    Icq: #32015991
>                          WWW:   http://www.tele-ip.com       VK3TJN
> -------------------------------------------------------------------

Re: SPI usage

2005-01-07 by teunvandeberg

Hi,

I've also write an SPI driver for the LPC2106 & LPC2292. I haven't 
fully tested it yet so I can't compare it with your code. (I hope I 
can do this soon.) If you like I can post it here.

Anyway, two hints:
1) Have a look at the errata sheet of the LPC you are using. I know 
for sure that there is a bug in the LPC2106 preventing you from 
correctly utilizing the status register.
2) I don't see a read function in your driver. Keep in mind that to 
receive data the clock needs to be driven by the master. This is only 
done on a transmission of data, so to receive data you need to send 
out (dummy) data. So SPI is basically always bi-directional. If the 
higher layer protocol is not you just add dummy data in the direction 
that you don't use (at that moment).

Hope this helps.

Kind Regards,
Teun van de Berg


--- In lpc2000@yahoogroups.com, "acetoel" <acetoel@y...> wrote:
> 
> Ok... here is a piece of code that I make.. please somebody give a
> hand, I don't want to bit bang a IO pin to make a SPI communication.
> Eventhough I will communicate with a Atmel Dataflash, and the speed 
is
> not important (I have to get at least 52k/sec, with SPI at 7.5MH I 
get
> more than 900k/sec, and with bit banging at 1Mhz I get 125k/sec 
which
> is enough).
> Here is my code to send a byte, and to receive... really I need
> something bidirectional (send and receive at the same time).
> 
> 
> #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)) 
> 
> 
> void spi_init(unsigned long PCLKBus, SPIRate, CPHA, CPOL, MSTR, 
LSBF,
> SPIE) {
>  unsigned long SPIDivider;
>  SPI_SPCR=0x00000000; // Disable SPI
>  
> // Calculate SPI_SPCCR - MIN SPIC_SPCCR = 8 -> @60MHZ, SPIRate = 
7.5Mhz 
>  SPIDivider = PCLKBus / SPIRate;
>  if (SPIDivider <= 0x7) {
>    SPIDivider = 0x00000008; // MAX Speed for any PCLK Speed
> }
>  SPI_SPCCR = SPIDivider;
>  
> // Set The SPI Mode
> 
>  if (CPHA == 1 ) {
>     SPI_SPCR = (SPI_SPCR + 0x00000008);
>  }
>  
>  if (CPOL == 1) {
>     SPI_SPCR = SPI_SPCR + 0x00000010;
>  } 
>  
>  if (LSBF == 1) {
>     SPI_SPCR = SPI_SPCR + 0x00000040; 
>  }
>  
>  if (MSTR == 1) {
>  	SPI_SPCR = SPI_SPCR + 0x00000020;
>  } 
> }
> 
> void spi_sendbyte (unsigned char spidata) {
> 	SPI_SPDR = spidata;
> 	while ((SPI_SPSR & 0x80) == 1) {} //Waits until TX is complete
> 	SPI_SPSR = SPI_SPSR & (1 << 7)
> }
> 
> 
> -------------------------------------------------------------
>  
> 
> Thanks
> Ezequiel
> 
> 
> --- In lpc2000@yahoogroups.com, Bruce Paterson <bruce@t...> wrote:
> > acetoel wrote:
> > 
> > > 
> > > Hello...
> > > 
> > > Is there any sample code that shows how to read and write a 
byte on
> > > the SPI bus? or any SPI sample code?
> > 
> > Ooops sorry ! My message about ARMlib seems to be premature on 
furthur 
> > investigation. It's only byte (not interrupt message based) and 
has
> only 
> > C stubs at present.
> > 
> > -- 
> > Cheers,
> > Bruce
> > ------------------------------------------------------------------
-
> > This email and any files transmitted with it are confidential and
> > intended solely for the use of the individual or entity to whom
> > they are addressed. If you have received this email in error 
please
> > notify the system manager.
> > 
> >      /\\\/\\\/\\\    /   /      Bruce Paterson
> >     /  \\\ \\\ \\\  /   /    Senior Design Engineer
> >    /   /\\\/\\\/\\\/   /   8 Anzed Court, Mulgrave, Vic, 3170
> >   /   /  \\\ \\\ \\\  /  PO Box 4112, Mulgrave, Vic, 3170, 
Australia
> > /   /    \\\/\\\ \\\/   Ph: +61 3 8561 4232   Fax: +61 3 9560 9055
> >        Tele-IP Ltd.      Email: bruce@t...    Icq: #32015991
> >                          WWW:   http://www.tele-ip.com       
VK3TJN
> > ------------------------------------------------------------------
-

Re: SPI usage

2005-01-07 by acetoel

Hello... That's the part that I didn't finish, the RX part. I'll use
SPI with Atmel DataFlash in a few weeks. My idea is to port a FAT16 FS
to LPC2106.
Please send the code to  sunixs@..., or post it here.
Thanks
Ezequiel


--- In lpc2000@yahoogroups.com, "teunvandeberg"
<teun.van.de.berg@p...> wrote:
Show quoted textHide quoted text
> 
> Hi,
> 
> I've also write an SPI driver for the LPC2106 & LPC2292. I haven't 
> fully tested it yet so I can't compare it with your code. (I hope I 
> can do this soon.) If you like I can post it here.
> 
> Anyway, two hints:
> 1) Have a look at the errata sheet of the LPC you are using. I know 
> for sure that there is a bug in the LPC2106 preventing you from 
> correctly utilizing the status register.
> 2) I don't see a read function in your driver. Keep in mind that to 
> receive data the clock needs to be driven by the master. This is only 
> done on a transmission of data, so to receive data you need to send 
> out (dummy) data. So SPI is basically always bi-directional. If the 
> higher layer protocol is not you just add dummy data in the direction 
> that you don't use (at that moment).
> 
> Hope this helps.
> 
> Kind Regards,
> Teun van de Berg
> 
> 
> --- In lpc2000@yahoogroups.com, "acetoel" <acetoel@y...> wrote:
> > 
> > Ok... here is a piece of code that I make.. please somebody give a
> > hand, I don't want to bit bang a IO pin to make a SPI communication.
> > Eventhough I will communicate with a Atmel Dataflash, and the speed 
> is
> > not important (I have to get at least 52k/sec, with SPI at 7.5MH I 
> get
> > more than 900k/sec, and with bit banging at 1Mhz I get 125k/sec 
> which
> > is enough).
> > Here is my code to send a byte, and to receive... really I need
> > something bidirectional (send and receive at the same time).
> > 
> > 
> > #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)) 
> > 
> > 
> > void spi_init(unsigned long PCLKBus, SPIRate, CPHA, CPOL, MSTR, 
> LSBF,
> > SPIE) {
> >  unsigned long SPIDivider;
> >  SPI_SPCR=0x00000000; // Disable SPI
> >  
> > // Calculate SPI_SPCCR - MIN SPIC_SPCCR = 8 -> @60MHZ, SPIRate = 
> 7.5Mhz 
> >  SPIDivider = PCLKBus / SPIRate;
> >  if (SPIDivider <= 0x7) {
> >    SPIDivider = 0x00000008; // MAX Speed for any PCLK Speed
> > }
> >  SPI_SPCCR = SPIDivider;
> >  
> > // Set The SPI Mode
> > 
> >  if (CPHA == 1 ) {
> >     SPI_SPCR = (SPI_SPCR + 0x00000008);
> >  }
> >  
> >  if (CPOL == 1) {
> >     SPI_SPCR = SPI_SPCR + 0x00000010;
> >  } 
> >  
> >  if (LSBF == 1) {
> >     SPI_SPCR = SPI_SPCR + 0x00000040; 
> >  }
> >  
> >  if (MSTR == 1) {
> >  	SPI_SPCR = SPI_SPCR + 0x00000020;
> >  } 
> > }
> > 
> > void spi_sendbyte (unsigned char spidata) {
> > 	SPI_SPDR = spidata;
> > 	while ((SPI_SPSR & 0x80) == 1) {} //Waits until TX is complete
> > 	SPI_SPSR = SPI_SPSR & (1 << 7)
> > }
> > 
> > 
> > -------------------------------------------------------------
> >  
> > 
> > Thanks
> > Ezequiel
> > 
> > 
> > --- In lpc2000@yahoogroups.com, Bruce Paterson <bruce@t...> wrote:
> > > acetoel wrote:
> > > 
> > > > 
> > > > Hello...
> > > > 
> > > > Is there any sample code that shows how to read and write a 
> byte on
> > > > the SPI bus? or any SPI sample code?
> > > 
> > > Ooops sorry ! My message about ARMlib seems to be premature on 
> furthur 
> > > investigation. It's only byte (not interrupt message based) and 
> has
> > only 
> > > C stubs at present.
> > > 
> > > -- 
> > > Cheers,
> > > Bruce
> > > ------------------------------------------------------------------
> -
> > > This email and any files transmitted with it are confidential and
> > > intended solely for the use of the individual or entity to whom
> > > they are addressed. If you have received this email in error 
> please
> > > notify the system manager.
> > > 
> > >      /\\\/\\\/\\\    /   /      Bruce Paterson
> > >     /  \\\ \\\ \\\  /   /    Senior Design Engineer
> > >    /   /\\\/\\\/\\\/   /   8 Anzed Court, Mulgrave, Vic, 3170
> > >   /   /  \\\ \\\ \\\  /  PO Box 4112, Mulgrave, Vic, 3170, 
> Australia
> > > /   /    \\\/\\\ \\\/   Ph: +61 3 8561 4232   Fax: +61 3 9560 9055
> > >        Tele-IP Ltd.      Email: bruce@t...    Icq: #32015991
> > >                          WWW:   http://www.tele-ip.com       
> VK3TJN
> > > ------------------------------------------------------------------
> -

Re: SPI usage

2005-01-07 by lpcarmed

You can also take a look at the code that IAR MakeApp generates for
the SPI. An eval version is downloadable on the IAR site - however I
don't know if the eval actually generates code or not.

--- In lpc2000@yahoogroups.com, "acetoel" <acetoel@y...> wrote:
Show quoted textHide quoted text
> 
> Hello... That's the part that I didn't finish, the RX part. I'll use
> SPI with Atmel DataFlash in a few weeks. My idea is to port a FAT16 FS
> to LPC2106.
> Please send the code to  sunixs@g..., or post it here.
> Thanks
> Ezequiel
> 
> 
> --- In lpc2000@yahoogroups.com, "teunvandeberg"
> <teun.van.de.berg@p...> wrote:
> > 
> > Hi,
> > 
> > I've also write an SPI driver for the LPC2106 & LPC2292. I haven't 
> > fully tested it yet so I can't compare it with your code. (I hope I 
> > can do this soon.) If you like I can post it here.
> > 
> > Anyway, two hints:
> > 1) Have a look at the errata sheet of the LPC you are using. I know 
> > for sure that there is a bug in the LPC2106 preventing you from 
> > correctly utilizing the status register.
> > 2) I don't see a read function in your driver. Keep in mind that to 
> > receive data the clock needs to be driven by the master. This is only 
> > done on a transmission of data, so to receive data you need to send 
> > out (dummy) data. So SPI is basically always bi-directional. If the 
> > higher layer protocol is not you just add dummy data in the direction 
> > that you don't use (at that moment).
> > 
> > Hope this helps.
> > 
> > Kind Regards,
> > Teun van de Berg
> > 
> > 
> > --- In lpc2000@yahoogroups.com, "acetoel" <acetoel@y...> wrote:
> > > 
> > > Ok... here is a piece of code that I make.. please somebody give a
> > > hand, I don't want to bit bang a IO pin to make a SPI communication.
> > > Eventhough I will communicate with a Atmel Dataflash, and the speed 
> > is
> > > not important (I have to get at least 52k/sec, with SPI at 7.5MH I 
> > get
> > > more than 900k/sec, and with bit banging at 1Mhz I get 125k/sec 
> > which
> > > is enough).
> > > Here is my code to send a byte, and to receive... really I need
> > > something bidirectional (send and receive at the same time).
> > > 
> > > 
> > > #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)) 
> > > 
> > > 
> > > void spi_init(unsigned long PCLKBus, SPIRate, CPHA, CPOL, MSTR, 
> > LSBF,
> > > SPIE) {
> > >  unsigned long SPIDivider;
> > >  SPI_SPCR=0x00000000; // Disable SPI
> > >  
> > > // Calculate SPI_SPCCR - MIN SPIC_SPCCR = 8 -> @60MHZ, SPIRate = 
> > 7.5Mhz 
> > >  SPIDivider = PCLKBus / SPIRate;
> > >  if (SPIDivider <= 0x7) {
> > >    SPIDivider = 0x00000008; // MAX Speed for any PCLK Speed
> > > }
> > >  SPI_SPCCR = SPIDivider;
> > >  
> > > // Set The SPI Mode
> > > 
> > >  if (CPHA == 1 ) {
> > >     SPI_SPCR = (SPI_SPCR + 0x00000008);
> > >  }
> > >  
> > >  if (CPOL == 1) {
> > >     SPI_SPCR = SPI_SPCR + 0x00000010;
> > >  } 
> > >  
> > >  if (LSBF == 1) {
> > >     SPI_SPCR = SPI_SPCR + 0x00000040; 
> > >  }
> > >  
> > >  if (MSTR == 1) {
> > >  	SPI_SPCR = SPI_SPCR + 0x00000020;
> > >  } 
> > > }
> > > 
> > > void spi_sendbyte (unsigned char spidata) {
> > > 	SPI_SPDR = spidata;
> > > 	while ((SPI_SPSR & 0x80) == 1) {} //Waits until TX is complete
> > > 	SPI_SPSR = SPI_SPSR & (1 << 7)
> > > }
> > > 
> > > 
> > > -------------------------------------------------------------
> > >  
> > > 
> > > Thanks
> > > Ezequiel
> > > 
> > > 
> > > --- In lpc2000@yahoogroups.com, Bruce Paterson <bruce@t...> wrote:
> > > > acetoel wrote:
> > > > 
> > > > > 
> > > > > Hello...
> > > > > 
> > > > > Is there any sample code that shows how to read and write a 
> > byte on
> > > > > the SPI bus? or any SPI sample code?
> > > > 
> > > > Ooops sorry ! My message about ARMlib seems to be premature on 
> > furthur 
> > > > investigation. It's only byte (not interrupt message based) and 
> > has
> > > only 
> > > > C stubs at present.
> > > > 
> > > > -- 
> > > > Cheers,
> > > > Bruce
> > > > ------------------------------------------------------------------
> > -
> > > > This email and any files transmitted with it are confidential and
> > > > intended solely for the use of the individual or entity to whom
> > > > they are addressed. If you have received this email in error 
> > please
> > > > notify the system manager.
> > > > 
> > > >      /\\\/\\\/\\\    /   /      Bruce Paterson
> > > >     /  \\\ \\\ \\\  /   /    Senior Design Engineer
> > > >    /   /\\\/\\\/\\\/   /   8 Anzed Court, Mulgrave, Vic, 3170
> > > >   /   /  \\\ \\\ \\\  /  PO Box 4112, Mulgrave, Vic, 3170, 
> > Australia
> > > > /   /    \\\/\\\ \\\/   Ph: +61 3 8561 4232   Fax: +61 3 9560 9055
> > > >        Tele-IP Ltd.      Email: bruce@t...    Icq: #32015991
> > > >                          WWW:   http://www.tele-ip.com       
> > VK3TJN
> > > > ------------------------------------------------------------------
> > -

Re: SPI usage

2005-01-13 by Bruce Paterson

Hi,

I've written an interrupt based SPI driver to fit into the newlib 
structure (ioctl, read, write).

It only handles SPI0 at present, but probably could be easily extended
to handle SPI1 as a subdevice. (btw, Why are UART0 and UART1 handled as 
seperate devices rather than sub-devices in  newlib ? Is it because 
UART1 has full handshaking potential and UART0 doesn't ?).

Since SPI is inherently bi-directional, you use read before write to 
setup where you want the received data to go (if you wish). You must do 
a write for anything to happen (read or write), so if you only want to 
read (unusual in an SPI master) just write some crap. Both read and 
write return immediately (this is an interrupt based driver!). You can 
poll for transaction completion, however, by observing return status of 
write with 0 length requested.
Open resets the buffer pointers to nowhere, and ensures only one thread 
can open an SPI device at a time.
Ioctl can be used to setup the speed, clocking polarities and bit order.

It will be quite a while before I'm in a position to test it. Anyone 
willing to give it a bash ? (probable bugs apologised for in advance).

-- 
Cheers,
Bruce
-------------------------------------------------------------------
     /\\\/\\\/\\\    /   /      Bruce Paterson
    /  \\\ \\\ \\\  /   /    Senior Design Engineer
   /   /\\\/\\\/\\\/   /   8 Anzed Court, Mulgrave, Vic, 3170
  /   /  \\\ \\\ \\\  /  PO Box 4112, Mulgrave, Vic, 3170, Australia
/   /    \\\/\\\ \\\/   Ph: +61 3 8561 4232   Fax: +61 3 9560 9055
       Tele-IP Ltd.      Email: bruce@...    Icq: #32015991
                         WWW:   http://www.tele-ip.com       VK3TJN
-------------------------------------------------------------------

Re: [lpc2000] Re: SPI usage

2005-01-13 by Bruce Paterson

Bruce Paterson wrote:

> 
> Hi,
> 
> I've written an interrupt based SPI driver to fit into the newlib 
> structure (ioctl, read, write).

A hardware question (it seems to be my day for questions!).
If you have SPI port enabled, used as a Master, do you have to tie the
SSEL0 pin high, or can you program that pin as a GPIO (and somehow the 
SPI core gets a permanent high supplied to it internally) ?

Seems a waste of an I/O pin to have to tie it high where most SPI 
applications would be SPI master

-- 
Cheers,
Bruce
-------------------------------------------------------------------
     /\\\/\\\/\\\    /   /      Bruce Paterson
    /  \\\ \\\ \\\  /   /    Senior Design Engineer
   /   /\\\/\\\/\\\/   /   8 Anzed Court, Mulgrave, Vic, 3170
  /   /  \\\ \\\ \\\  /  PO Box 4112, Mulgrave, Vic, 3170, Australia
/   /    \\\/\\\ \\\/   Ph: +61 3 8561 4232   Fax: +61 3 9560 9055
       Tele-IP Ltd.      Email: bruce@...    Icq: #32015991
                         WWW:   http://www.tele-ip.com       VK3TJN
-------------------------------------------------------------------

Re: [lpc2000] Re: SPI usage

2005-01-13 by Aalt Lokhorst

Hello All,

I want to use the SPI bus for communication between a LPC2129 and a 
FPGA. I think that I will decide to make the processor the 'Master'.

But I was wondering, suppose that I would use the LPC2129 as a Slave 
instead of a Master, how can I guarantee that the write buffer gets 
filled at the right moment. There is no buffer between the write buffer 
and the actual shift register, so the register needs to be written in 
the short interval between the transmission of the bytes (assuming a 
message with several bytes).

The problem is, if the LPC2129 is used as the Slave then the timing is 
determined by the Master at the other end. Isn't this getting tricky?

Regards,

-- 
==============================
Aalt Lokhorst
Schut Geometrische Meettechniek bv
Duinkerkenstraat 21
9723 BN Groningen
P.O. Box 5225
9700 GE Groningen
The Netherlands
Tel: +31-50-5877877
Fax: +31-50-5877899
E-mail: Lokhorst@...
==============================

Re: SPI usage

2005-01-13 by acetoel

Hello... I'm using SPI with the PC2106, but in Master Mode. 
I beleive that for the Slave mode, you should check the "Chip Select"
Pin, and when the master selects you, then be prepared to receive and
send bytes.
Hope helps a bit

Ezequiel
sunixs@...



--- In lpc2000@yahoogroups.com, "Aalt Lokhorst" <lokhorst@s...> wrote:
Show quoted textHide quoted text
> Hello All,
> 
> I want to use the SPI bus for communication between a LPC2129 and a 
> FPGA. I think that I will decide to make the processor the 'Master'.
> 
> But I was wondering, suppose that I would use the LPC2129 as a Slave 
> instead of a Master, how can I guarantee that the write buffer gets 
> filled at the right moment. There is no buffer between the write buffer 
> and the actual shift register, so the register needs to be written in 
> the short interval between the transmission of the bytes (assuming a 
> message with several bytes).
> 
> The problem is, if the LPC2129 is used as the Slave then the timing is 
> determined by the Master at the other end. Isn't this getting tricky?
> 
> Regards,
> 
> -- 
> ==============================
> Aalt Lokhorst
> Schut Geometrische Meettechniek bv
> Duinkerkenstraat 21
> 9723 BN Groningen
> P.O. Box 5225
> 9700 GE Groningen
> The Netherlands
> Tel: +31-50-5877877
> Fax: +31-50-5877899
> E-mail: Lokhorst@S...
> ==============================

Re: [lpc2000] Re: SPI usage

2005-01-13 by Bill Knight

On Thu, 13 Jan 2005 13:22:31 +1100, Bruce Paterson wrote:


Bruce Paterson wrote:

> 
> Hi,
> 
> I've written an interrupt based SPI driver to fit into the newlib 
> structure (ioctl, read, write).

A hardware question (it seems to be my day for questions!).
If you have SPI port enabled, used as a Master, do you have to tie the
SSEL0 pin high, or can you program that pin as a GPIO (and somehow the 
SPI core gets a permanent high supplied to it internally) ?

Seems a waste of an I/O pin to have to tie it high where most SPI 
applications would be SPI master
------------------------------------------------------------------
Bruce
  I believe the answer is yes, you must tie the SSEL0 pin high even
when operating in Master mode and yes, it seems a waste.

-Bill Knight
http://www.theARMPatch.com

RE: [lpc2000] Re: SPI usage

2005-01-13 by Charles R. Grenz

Hi Bruce,

	Yes you do have to tie it high. 

Regards,
Charles
Show quoted textHide quoted text
-----Original Message-----
From: Bill Knight [mailto:BillK@...] 
Sent: Thursday, January 13, 2005 6:40 AM
To: lpc2000@yahoogroups.com
Subject: Re: [lpc2000] Re: SPI usage



On Thu, 13 Jan 2005 13:22:31 +1100, Bruce Paterson wrote:


Bruce Paterson wrote:

> 
> Hi,
> 
> I've written an interrupt based SPI driver to fit into the newlib
> structure (ioctl, read, write).

A hardware question (it seems to be my day for questions!).
If you have SPI port enabled, used as a Master, do you have to tie the SSEL0
pin high, or can you program that pin as a GPIO (and somehow the 
SPI core gets a permanent high supplied to it internally) ?

Seems a waste of an I/O pin to have to tie it high where most SPI 
applications would be SPI master
------------------------------------------------------------------
Bruce
  I believe the answer is yes, you must tie the SSEL0 pin high even when
operating in Master mode and yes, it seems a waste.

-Bill Knight
http://www.theARMPatch.com




 
Yahoo! Groups Links

Re: [lpc2000] Re: SPI usage

2005-01-13 by Kerem Or

Bruce,

Two days ago I was dealing with the same problem. Then I had to tie the pin 
to VCC and define it as SSEL and had the SPI working as master.

If you define the port as output the SPI continues to get "slave abort". 
Also the LPC2214 user manual states the following in bold in page 163 
"...configured to operate as SPI master MUST select SSEL functionality on an 
appropriate pin...". Which means you have to make the pin a SSEL pin as it 
says "select SSEL functionality".

Anyways the pin is wasted like I'm unable to use PWM outputs as the same 
pins share serial port I/O while some of the pins only have one function.

Kerem


----- Original Message ----- 
Show quoted textHide quoted text
From: "Bill Knight" <BillK@...>
To: <lpc2000@yahoogroups.com>
Sent: Thursday, January 13, 2005 1:39 PM
Subject: Re: [lpc2000] Re: SPI usage


>
> On Thu, 13 Jan 2005 13:22:31 +1100, Bruce Paterson wrote:
>
>
> Bruce Paterson wrote:
>
>>
>> Hi,
>>
>> I've written an interrupt based SPI driver to fit into the newlib
>> structure (ioctl, read, write).
>
> A hardware question (it seems to be my day for questions!).
> If you have SPI port enabled, used as a Master, do you have to tie the
> SSEL0 pin high, or can you program that pin as a GPIO (and somehow the
> SPI core gets a permanent high supplied to it internally) ?
>
> Seems a waste of an I/O pin to have to tie it high where most SPI
> applications would be SPI master
> ------------------------------------------------------------------
> Bruce
>  I believe the answer is yes, you must tie the SSEL0 pin high even
> when operating in Master mode and yes, it seems a waste.
>
> -Bill Knight
> http://www.theARMPatch.com
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

Re: [lpc2000] Re: SPI usage

2005-01-13 by Robert Adsett

At 11:42 AM 1/13/05 +1100, you wrote:
>I've written an interrupt based SPI driver to fit into the newlib
>structure (ioctl, read, write).
>
>It only handles SPI0 at present, but probably could be easily extended
>to handle SPI1 as a subdevice. (btw, Why are UART0 and UART1 handled as
>seperate devices rather than sub-devices in  newlib ? Is it because
>UART1 has full handshaking potential and UART0 doesn't ?).

I could give you a long winded explanation, but the truth is it was 
submitted to me that way.

I would have done it that way myself.  I suspect for the UARTs it's the 
correct way to go since it allows you to choose which one to use 
easily.  Feel free to implement a joint pair though I'd love to see it.

>Since SPI is inherently bi-directional, you use read before write to
>setup where you want the received data to go (if you wish). You must do
>a write for anything to happen (read or write), so if you only want to
>read (unusual in an SPI master) just write some crap. Both read and
>write return immediately (this is an interrupt based driver!). You can
>poll for transaction completion, however, by observing return status of
>write with 0 length requested.
>Open resets the buffer pointers to nowhere, and ensures only one thread
>can open an SPI device at a time.
>Ioctl can be used to setup the speed, clocking polarities and bit order.
>
>It will be quite a while before I'm in a position to test it. Anyone
>willing to give it a bash ? (probable bugs apologised for in advance).

I was going to tackle this shortly as well so I'd be will to take a crack 
at it.  I've got a board with some spots on it specifically so I could 
start testing SPI since I expect I will need it in the not too distant future.

Contact me  through one of the contact links on 
http://www.aeolusdevelopment.com That's probably the easiest way. (One of 
the links uses a obfuscated mailto link, if that doesn't work send me your 
contact through one of the forms.  If its marked clearly it'll get through 
to me).


Robert


" 'Freedom' has no meaning of itself.  There are always restrictions,
be they legal, genetic, or physical.  If you don't believe me, try to
chew a radio signal. "

                         Kelvin Throop, III

Re: SPI usage

2005-01-13 by lp2000c

This was true for the older devices, but according to Philips, this 
is no longer required for the 213x parts.  You can use SSEL as GPIO. 

--- In lpc2000@yahoogroups.com, "Bill Knight" <BillK@t...> wrote:
> On Thu, 13 Jan 2005 13:22:31 +1100, Bruce Paterson wrote:
> 
> 
> Bruce Paterson wrote:
> 
> A hardware question (it seems to be my day for questions!).
> If you have SPI port enabled, used as a Master, do you have to tie 
the
> SSEL0 pin high, or can you program that pin as a GPIO (and somehow 
the 
Show quoted textHide quoted text
> SPI core gets a permanent high supplied to it internally) ?
> 
> Seems a waste of an I/O pin to have to tie it high where most SPI 
> applications would be SPI master
> ------------------------------------------------------------------
> Bruce
>   I believe the answer is yes, you must tie the SSEL0 pin high even
> when operating in Master mode and yes, it seems a waste.
> 
> -Bill Knight
> http://www.theARMPatch.com

RE: [lpc2000] Re: SPI usage

2005-01-13 by Charles R. Grenz

HI all,

	Does that also include the SSP or only the SPI for the LPC2138?

Regards,
Charles
Show quoted textHide quoted text
-----Original Message-----
From: lp2000c [mailto:lp2000c@...] 
Sent: Thursday, January 13, 2005 4:22 PM
To: lpc2000@yahoogroups.com
Subject: [lpc2000] Re: SPI usage




This was true for the older devices, but according to Philips, this 
is no longer required for the 213x parts.  You can use SSEL as GPIO. 

--- In lpc2000@yahoogroups.com, "Bill Knight" <BillK@t...> wrote:
> On Thu, 13 Jan 2005 13:22:31 +1100, Bruce Paterson wrote:
> 
> 
> Bruce Paterson wrote:
> 
> A hardware question (it seems to be my day for questions!). If you 
> have SPI port enabled, used as a Master, do you have to tie
the
> SSEL0 pin high, or can you program that pin as a GPIO (and somehow
the 
> SPI core gets a permanent high supplied to it internally) ?
> 
> Seems a waste of an I/O pin to have to tie it high where most SPI
> applications would be SPI master
> ------------------------------------------------------------------
> Bruce
>   I believe the answer is yes, you must tie the SSEL0 pin high even
> when operating in Master mode and yes, it seems a waste.
> 
> -Bill Knight
> http://www.theARMPatch.com





 
Yahoo! Groups Links

Re: SPI usage - answer

2005-01-13 by smt5211

We had the same problem with comms between a SPI master and slave. 
Unless we used CS to synchronize the start of each byte, we had 
problems with the slave determining the start of each byte.

With an FPGA, it would be active and possibly transmitting bytes 
long before the ARM was active. In this case, you will definitely 
need to use CS so that the slave wont get confused.

--- In lpc2000@yahoogroups.com, "Aalt Lokhorst" <lokhorst@s...> 
wrote:
> Hello All,
> 
> I want to use the SPI bus for communication between a LPC2129 and 
a 
> FPGA. I think that I will decide to make the processor 
the 'Master'.
> 
> But I was wondering, suppose that I would use the LPC2129 as a 
Slave 
> instead of a Master, how can I guarantee that the write buffer 
gets 
> filled at the right moment. There is no buffer between the write 
buffer 
> and the actual shift register, so the register needs to be written 
in 
> the short interval between the transmission of the bytes (assuming 
a 
> message with several bytes).
> 
> The problem is, if the LPC2129 is used as the Slave then the 
timing is 
> determined by the Master at the other end. Isn't this getting 
tricky?
Show quoted textHide quoted text
> 
> Regards,
> 
> -- 
> ==============================
> Aalt Lokhorst
> Schut Geometrische Meettechniek bv
> Duinkerkenstraat 21
> 9723 BN Groningen
> P.O. Box 5225
> 9700 GE Groningen
> The Netherlands
> Tel: +31-50-5877877
> Fax: +31-50-5877899
> E-mail: Lokhorst@S...
> ==============================

Re: SPI usage

2005-01-14 by acetoel

Hello... I'm trying to use the SPI of the LPC2106 to drive an Atmel
Dataflash.. I made a very primitive SPI driver in Ansi C. Would you
mind sharing your code with me, so I can improve or modify mine?
Please, write me to sunixs@...
Thanks
Ezequiel

--- In lpc2000@yahoogroups.com, "Kerem Or" <k.or@s...> wrote:
> Bruce,
> 
> Two days ago I was dealing with the same problem. Then I had to tie
the pin 
> to VCC and define it as SSEL and had the SPI working as master.
> 
> If you define the port as output the SPI continues to get "slave
abort". 
> Also the LPC2214 user manual states the following in bold in page 163 
> "...configured to operate as SPI master MUST select SSEL
functionality on an 
> appropriate pin...". Which means you have to make the pin a SSEL pin
as it 
> says "select SSEL functionality".
> 
> Anyways the pin is wasted like I'm unable to use PWM outputs as the
same 
> pins share serial port I/O while some of the pins only have one
function.
Show quoted textHide quoted text
> 
> Kerem
> 
> 
> ----- Original Message ----- 
> From: "Bill Knight" <BillK@t...>
> To: <lpc2000@yahoogroups.com>
> Sent: Thursday, January 13, 2005 1:39 PM
> Subject: Re: [lpc2000] Re: SPI usage
> 
> 
> >
> > On Thu, 13 Jan 2005 13:22:31 +1100, Bruce Paterson wrote:
> >
> >
> > Bruce Paterson wrote:
> >
> >>
> >> Hi,
> >>
> >> I've written an interrupt based SPI driver to fit into the newlib
> >> structure (ioctl, read, write).
> >
> > A hardware question (it seems to be my day for questions!).
> > If you have SPI port enabled, used as a Master, do you have to tie the
> > SSEL0 pin high, or can you program that pin as a GPIO (and somehow the
> > SPI core gets a permanent high supplied to it internally) ?
> >
> > Seems a waste of an I/O pin to have to tie it high where most SPI
> > applications would be SPI master
> > ------------------------------------------------------------------
> > Bruce
> >  I believe the answer is yes, you must tie the SSEL0 pin high even
> > when operating in Master mode and yes, it seems a waste.
> >
> > -Bill Knight
> > http://www.theARMPatch.com
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >

Re: [lpc2000] Re: SPI usage - answer

2005-01-14 by Aalt Lokhorst

Thanks Ezequiel and 'smt5211'

Hmm, seems that Philips already made the decision for me that the ARM 
has to be the Master in my case. A byte for byte communication is not 
acceptable for me, to much synchronisation issues.

In my imagination I am dreaming of an SPI which uses a kind of DMA. Give 
it some pointers to Tx/Rx buffers, total number of bytes and go...

Probably we need a processor with a small FPGA integrated to it so that 
we have the possibility to design 'custom' on chip peripherals.

Nice dreaming, for now I will open my eyes again and continue working.

Thanks

-- 
==============================
Aalt Lokhorst
Schut Geometrische Meettechniek bv
Duinkerkenstraat 21
9723 BN Groningen
P.O. Box 5225
9700 GE Groningen
The Netherlands
Tel: +31-50-5877877
Fax: +31-50-5877899
E-mail: Lokhorst@...
==============================

Re: [lpc2000] Re: SPI usage - answer

2005-01-14 by microbit

Hi,

> In my imagination I am dreaming of an SPI which uses a kind of DMA. Give 
> it some pointers to Tx/Rx buffers, total number of bytes and go...
> 
> Probably we need a processor with a small FPGA integrated to it so that 
> we have the possibility to design 'custom' on chip peripherals.
> 
> Nice dreaming, for now I will open my eyes again and continue working.
> 
> Thanks

I know it's not nice to mention on this group, but have you looked at Atmel's SAM7 SPI ?
It has advanced DMA (PDC) allright, and it is the most versatile SPI I've seen so far.
It has up to 8 programmable CS lines, and each individual Slave CS can be programmed
for a different clock rate, Tdelay after CS assertion, Thold before strobing with CS, 
different inter-char delays, extended float time on the SPI bus of a slave etc. etc.
Thus when you switch (or even INT driven) to another slave, all the new settings
for that Slave automatically take effect.
You can even put it in a 4 -> 16 Mux mode for up to 16 Slaves.

It is a very nice SPI, and you can tell it's designed to operate at very high throughput
with ZERO user intervention.

From your comments above, sounds like you could do with that.

D/L a datasheet on eg. AT91SAM7S64, and see if it's what you need - I'd say so.

-- Kris


[Non-text portions of this message have been removed]

Re: [lpc2000] Re: SPI usage - answer

2005-01-14 by Aalt Lokhorst

Hello microbit,

Probably I have to look over the horizon.

I am in the lucky position that I have the control over the processor 
and the FPGA.
So I am not really forced to the SLAVE mode, but I was a little 
disappointed when I saw the limitations.

Thanks for your tip, I will take a look.

-- 
==============================
Aalt Lokhorst
Schut Geometrische Meettechniek bv
Duinkerkenstraat 21
9723 BN Groningen
P.O. Box 5225
9700 GE Groningen
The Netherlands
Tel: +31-50-5877877
Fax: +31-50-5877899
E-mail: Lokhorst@...
==============================

RE: [lpc2000] Re: SPI usage - answer

2005-01-14 by Joe Hlebasko

Infineon's C16x family can do what you describe. It use a form of DMA called
Peripheral Event Controller, give it a pointer for the source, the
destination, number of transfers and let it rip!

Joe 
Show quoted textHide quoted text
> -----Original Message-----
> From: Aalt Lokhorst [mailto:lokhorst@...] 
> Sent: Friday, January 14, 2005 4:27 AM
> To: lpc2000@yahoogroups.com
> Subject: Re: [lpc2000] Re: SPI usage - answer
> 
> 
> Thanks Ezequiel and 'smt5211'
> 
> Hmm, seems that Philips already made the decision for me that 
> the ARM has to be the Master in my case. A byte for byte 
> communication is not acceptable for me, to much 
> synchronisation issues.
> 
> In my imagination I am dreaming of an SPI which uses a kind 
> of DMA. Give it some pointers to Tx/Rx buffers, total number 
> of bytes and go...
> 
> Probably we need a processor with a small FPGA integrated to 
> it so that we have the possibility to design 'custom' on chip 
> peripherals.
> 
> Nice dreaming, for now I will open my eyes again and continue working.
> 
> Thanks
> 
> --
> ==============================
> Aalt Lokhorst
> Schut Geometrische Meettechniek bv
> Duinkerkenstraat 21
> 9723 BN Groningen
> P.O. Box 5225
> 9700 GE Groningen
> The Netherlands
> Tel: +31-50-5877877
> Fax: +31-50-5877899
> E-mail: Lokhorst@...
> ==============================
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 
>

Re: SPI usage - answer

2005-01-15 by lpc2100_fan

Hello Aalt,

did you have a look at the SSP interface of the LPC2130-series. It
offers flexible data length and Fifos. Still not a DMA but definitely
a big increase in functionality.

Cheers Bob

--- In lpc2000@yahoogroups.com, "Aalt Lokhorst" <lokhorst@s...> wrote:
Show quoted textHide quoted text
> Hello microbit,
> 
> Probably I have to look over the horizon.
> 
> I am in the lucky position that I have the control over the processor 
> and the FPGA.
> So I am not really forced to the SLAVE mode, but I was a little 
> disappointed when I saw the limitations.
> 
> Thanks for your tip, I will take a look.
> 
> -- 
> ==============================
> Aalt Lokhorst
> Schut Geometrische Meettechniek bv
> Duinkerkenstraat 21
> 9723 BN Groningen
> P.O. Box 5225
> 9700 GE Groningen
> The Netherlands
> Tel: +31-50-5877877
> Fax: +31-50-5877899
> E-mail: Lokhorst@S...
> ==============================

Re: SPI usage - answer

2005-01-15 by charlesgrenz

Yep, that was one of the things I liked about the 2138 was that it had
variable length data from 4 to 16 bits and the FIFO.

regards,
Charles


--- In lpc2000@yahoogroups.com, "lpc2100_fan" <lpc2100_fan@y...> wrote:
Show quoted textHide quoted text
> 
> Hello Aalt,
> 
> did you have a look at the SSP interface of the LPC2130-series. It
> offers flexible data length and Fifos. Still not a DMA but definitely
> a big increase in functionality.
> 
> Cheers Bob
> 
> --- In lpc2000@yahoogroups.com, "Aalt Lokhorst" <lokhorst@s...> wrote:
> > Hello microbit,
> > 
> > Probably I have to look over the horizon.
> > 
> > I am in the lucky position that I have the control over the processor 
> > and the FPGA.
> > So I am not really forced to the SLAVE mode, but I was a little 
> > disappointed when I saw the limitations.
> > 
> > Thanks for your tip, I will take a look.
> > 
> > -- 
> > ==============================
> > Aalt Lokhorst
> > Schut Geometrische Meettechniek bv
> > Duinkerkenstraat 21
> > 9723 BN Groningen
> > P.O. Box 5225
> > 9700 GE Groningen
> > The Netherlands
> > Tel: +31-50-5877877
> > Fax: +31-50-5877899
> > E-mail: Lokhorst@S...
> > ==============================

Re: [lpc2000] Re: SPI usage - answer

2005-01-17 by Aalt Lokhorst

Thanks all,

Thanks for the response for the SPI alternatives.

-- 
==============================
Aalt Lokhorst
Schut Geometrische Meettechniek bv
Duinkerkenstraat 21
9723 BN Groningen
P.O. Box 5225
9700 GE Groningen
The Netherlands
Tel: +31-50-5877877
Fax: +31-50-5877899
E-mail: Lokhorst@...
==============================

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.