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:
>
> 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
> > > > ------------------------------------------------------------------
> > -Message
Re: SPI usage
2005-01-07 by lpcarmed
Attachments
- No local attachments were found for this message.