Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

spi.c

00001 /*! \file spi.c \brief SPI Interface Driver for LPC2100. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'spi.c'
00005 // Title        : SPI Interface Driver for LPC2100
00006 // Author       : Pascal Stang - Copyright (C) 2004
00007 // Created      : 2004.05.05
00008 // Revised      : 2004.07.12
00009 // Version      : 0.1
00010 // Target MCU   : ARM processors
00011 // Editor Tabs  : 4
00012 //
00013 // NOTE: This code is currently below version 1.0, and therefore is considered
00014 // to be lacking in some functionality or documentation, or may not be fully
00015 // tested.  Nonetheless, you can expect most functions to work.
00016 //
00017 // This code is distributed under the GNU Public License
00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00019 //
00020 //*****************************************************************************
00021 
00022 #include "lpc2000.h"
00023 #include "global.h"
00024 #include "spi.h"
00025 
00026 void spiInit(void)
00027 {
00028     // setup SCK pin P04
00029     PINSEL0 &= ~(3<<8);
00030     PINSEL0 |= 1<<8;
00031     // setup MISO pin P05
00032     PINSEL0 &= ~(3<<10);
00033     PINSEL0 |= 1<<10;
00034     // setup MOSI pin P06
00035     PINSEL0 &= ~(3<<12);
00036     PINSEL0 |= 1<<12;
00037     // setup SSEL pin P07
00038     PINSEL0 &= ~(3<<14);
00039     PINSEL0 |= 1<<14;
00040 
00041     // set maximum SPI rate
00042     S0SPCCR = 8;
00043     // set master mode, clock polarity and phase
00044     S0SPCR = (1<<SPCR_MSTR);
00045 }
00046 
00047 void spiSetClockDiv(u08 clockdiv)
00048 {
00049     S0SPCCR = clockdiv;
00050 }
00051 
00052 void spiSendByte(u08 data)
00053 {
00054     // wait until SPI bus is free
00055     while(!(S0SPSR & (1<<SPSR_SPIF)));
00056     // write SPI data
00057     S0SPDR = data;
00058 }
00059 
00060 u08 spiTransferByte(u08 data)
00061 {
00062     // write SPI data
00063     S0SPDR = data;
00064     // wait until SPI transfer completes
00065     while(!(S0SPSR & (1<<SPSR_SPIF)));
00066     // return received data
00067     return S0SPDR;
00068 }

Generated on Mon Nov 6 23:36:58 2006 for Procyon ARMlib by  doxygen 1.4.2