SAM3S8/SD8 Software Package: examples/spi_slave/main.c Source File

SAM3S8/SD8 Software Package 1.2

# main.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------------
    00002  *         ATMEL Microcontroller Software Support
    00003  * ----------------------------------------------------------------------------
    00004  * Copyright (c) 2011, Atmel Corporation
    00005  *
    00006  * All rights reserved.
    00007  *
    00008  * Redistribution and use in source and binary forms, with or without
    00009  * modification, are permitted provided that the following conditions are met:
    00010  *
    00011  * - Redistributions of source code must retain the above copyright notice,
    00012  * this list of conditions and the disclaimer below.
    00013  *
    00014  * Atmel's name may not be used to endorse or promote products derived from
    00015  * this software without specific prior written permission.
    00016  *
    00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
    00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
    00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
    00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
    00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00027  * ----------------------------------------------------------------------------
    00028  */
    00029
    00030 /**
    00031  * \page spi_slave SPI Slave Example
    00032  *
    00033  * \section Purpose
    00034  *
    00035  * This example uses Serial Peripheral Interface (SPI) in slave mode to
    00036  * communicate to another SPI master) interface.
    00037  *
    00038  * \section Requirements
    00039  *
    00040  * This package can be used with two sam3s-ek2 board.
    00041  * Please connect the SPI pins from one board to another.
    00042  *        - <b>SAM3S(MASTER)--SAM3S(SLAVE)</b>
    00043  *        - NPCS0 -- NPCS0 (PA11)
    00044  *        - MISO  -- MISO  (PA12)
    00045  *        - MOSI  -- MOSI  (PA13)
    00046  *        - SPCK  -- SPCK  (PA14)
    00047  *        - GND   -- GND
    00048  * Because PA11 is multiplexed with ADS7843 (by default) and this example, so
    00049  * please remove R66 on the EK board to make PA11 is dedicated to this example.
    00050  *
    00051  * \section Descriptions
    00052  *
    00053  * This example shows control of the SPI slave, how to configure and
    00054  * transfer data with SPI slave. By default, example runs in SPI slave mode,
    00055  * waiting SPI slave & UART inputs.
    00056
    00057  * The code can be roughly broken down as follows:
    00058  * <ul>
    00059  * <li> 't' will start SPI transfer test
    00060  * <ol>
    00061  * <li>Configure SPI as master, setup SPI clock.
    00062  * <li>Send 4 byte CMD_TEST to indicate the start of test.
    00063  * <li>Send several 64 bytes block, on transmitting next block, the content of last block is returned.
    00064  * <li>Send CMD_STATUS command and waiting for the status reprots from slave.
    00065  * <li>Send CMD_END command to indicate the end of test.
    00066  * </ol>
    00067  * <li>Setup SPI clock for master.
    00068  * </ul>
    00069  *
    00070  * \section Usage
    00071  *
    00072  * -# Compile the application.
    00073  * -# Connect the UART port of the evaluation board to the computer and open
    00074  * it in a terminal.
    00075  *    - Settings: 115200 bauds, 8 bits, 1 stop bit, no parity, no flow control.
    00076  * -# Download the program inside the evaluation board and run it. Please refer to
    00077  *    <a href="http://www.atmel.com/dyn/resources/prod_documents/6421B.pdf">
    00078  *    SAM-BA User Guide</a>, the
    00079  *    <a href="http://www.atmel.com/dyn/resources/prod_documents/doc6310.pdf">
    00080  *    GNU-Based Software Development</a> application note or to the
    00081  *    <a href="http://www.iar.com/website1/1.0.1.0/78/1/">
    00082  *    IAR EWARM User and reference guides</a>, depending on your chosen solution.
    00083  * -# Upon startup, the application will output the following line on the terminal:
    00084  *    \code
    00085  *     -- Spi slave Example  xxx --
    00086  *     -- xxxxxx-xx
    00087  *     -- Compiled: xxx xx xxxx xx:xx:xx --
    00088  *    \endcode
    00089  * -# The following traces detail operations on the spl slave example, displaying success
    00090  *    or error messages depending on the results of the commands.
    00091  *
    00092  * \section References
    00093  * - spi_slave/main.c
    00094  * - spi.c
    00095  */
    00096
    00097 /**
    00098  * \file
    00099  *
    00100  * This file contains all the specific code for the spi slave example.
    00101  */
    00102
    00103
    00104 /*----------------------------------------------------------------------------
    00105  *        Headers
    00106  *----------------------------------------------------------------------------*/
    00107
    00108 #include "board.h"
    00109
    00110 #include <stdio.h>
    00111 #include <stdarg.h>
    00112
    00113 /*----------------------------------------------------------------------------
    00114  *        Local definitions
    00115  *----------------------------------------------------------------------------*/
    00116 /** SPI base address for SPI master mode*/
    00117 #define SPI_MASTER_BASE      SPI
    00118 /** SPI base address for SPI slave mode, (on different board) */
    00119 #define SPI_SLAVE_BASE       SPI
    00120
    00121 /** SPI slave states for this example*/
    00122 #define SLAVE_STATE_IDLE           0
    00123 #define SLAVE_STATE_TEST           1
    00124 #define SLAVE_STATE_DATA           2
    00125 #define SLAVE_STATE_STATUS_ENTRY   3
    00126 #define SLAVE_STATE_STATUS         4
    00127 #define SLAVE_STATE_END            5
    00128
    00129 /** SPI example commands for this example */
    00130 /** slave test state, begin to return RC_RDY */
    00131 #define CMD_TEST    0x10101010
    00132 /** slave data state, begin to return last data block*/
    00133 #define CMD_DATA    0x29380000
    00134 /** slave status state, begin to return RC_RDY + RC_STATUS*/
    00135 #define CMD_STATUS  0x68390384
    00136 /** slave idle state, begin to return RC_SYN*/
    00137 #define CMD_END     0x68390484
    00138 /** General return value*/
    00139 #define RC_SYN      0x55AA55AA
    00140 /** Ready status*/
    00141 #define RC_RDY      0x12345678
    00142 /** Number of commands logged in status */
    00143 #define NB_STATUS_CMD   20
    00144 /** Number of SPI clock configurations */
    00145 #define NUM_SPCK_CONFIGURATIONS 4
    00146 /*----------------------------------------------------------------------------
    00147  *        Tyoes
    00148  *----------------------------------------------------------------------------*/
    00149
    00150 /** Status block */
    00151 typedef struct _StatusBlock
    00152 {
    00153     /** Number of data blocks */
    00154     uint32_t totalNumBlocks;
    00155     /** Number of SPI commands (including data blocks) */
    00156     uint32_t totalNumCommands;
    00157     /** Command list */
    00158     uint32_t cmdList[NB_STATUS_CMD];
    00159 } StatusBlock ;
    00160
    00161 /*----------------------------------------------------------------------------
    00162  *        Local variables
    00163  *----------------------------------------------------------------------------*/
    00164
    00165 /** PIOs for all SPI modes */
    00166 static const Pin pSpiPins[] = {PINS_SPI, PIN_SPI_NPCS0_PA11};
    00167
    00168 /** SPI Clock setting (Hz) */
    00169 static uint32_t spiClock = 100000;
    00170 /** Current SPI return code */
    00171 static uint32_t spiCmd = RC_SYN;
    00172
    00173 /** Current SPI state */
    00174 static uint8_t spiState = 0;
    00175
    00176 /** 64 bytes data buffer for SPI transfer and receive */
    00177 static uint8_t spiBuffer[64];
    00178
    00179 /** SPI Status */
    00180 static StatusBlock spiStatus;
    00181
    00182 static uint8_t numTestBlocks;
    00183
    00184 /** SPI clock configuration */
    00185 static const uint32_t clockConfigurations[] = { 100000, 500000, 1000000, 5000000};
    00186
    00187 /*----------------------------------------------------------------------------
    00188  *        Local functions
    00189  *----------------------------------------------------------------------------*/
    00190
    00191 /**
    00192  * \brief Displays the user menu on the terminal.
    00193  */
    00194 static void DisplayMenu( void )
    00195 {
    00196     uint32_t i ;
    00197
    00198     printf( "\n\rMenu :\n\r" ) ;
    00199     printf( "------\n\r" ) ;
    00200
    00201     for ( i = 0 ; i < NUM_SPCK_CONFIGURATIONS ; i++ )
    00202     {
    00203         printf("  %u: Set SPCK = %7d Hz\n\r", (unsigned int)i, (int)clockConfigurations[i] ) ;
    00204     }
    00205     printf( "  t: Perform SPI master\n\r" ) ;
    00206     printf( "  h: Display this menu again\n\r\n\r" ) ;
    00207 }
    00208
    00209 /**
    00210  * \brief Perform SPI slave transfer using PDC.
    00211  * \param pBuf Pointer to 1st buffer to transfer.
    00212  * \param size Size of the 1st buffer.
    00213  * \param pNextBuf Pointer to 2nd buffer to transfer.
    00214  * \param nextSize Size of the 2nd buffer.
    00215  */
    00216 static void SpiSlaveTransfer( void* pBuf, uint16_t size, void* pNextBuf, uint16_t nextSize )
    00217 {
    00218     uint32_t spiIER ;
    00219
    00220     SPI_PdcSetTx( SPI_SLAVE_BASE, pBuf, size, pNextBuf, nextSize ) ;
    00221     SPI_PdcSetRx( SPI_SLAVE_BASE, pBuf, size, pNextBuf, nextSize ) ;
    00222
    00223     /* Enable the RX and TX PDC transfer requests */
    00224     SPI_PdcEnableRx( SPI_SLAVE_BASE ) ;
    00225     SPI_PdcEnableTx( SPI_SLAVE_BASE ) ;
    00226
    00227     /* Transfer done handler is in ISR ... */
    00228     spiIER = SPI_IER_NSSR | SPI_IER_RXBUFF | (pNextBuf ? SPI_IER_ENDRX : 0) ;
    00229     SPI_EnableIt( SPI_SLAVE_BASE, spiIER ) ;
    00230 }
    00231
    00232 /**
    00233  * \brief  SPI Command block process
    00234  */
    00235 static void SpiSlaveCommandProcess( void )
    00236 {
    00237     if ( spiCmd == CMD_END )
    00238     {
    00239         spiState = SLAVE_STATE_IDLE;
    00240         spiStatus.totalNumBlocks   = 0;
    00241         spiStatus.totalNumCommands = 0;
    00242     }
    00243     else
    00244     {
    00245         switch( spiState )
    00246         {
    00247             case SLAVE_STATE_IDLE:
    00248                 /* Only CMD_TEST accepted*/
    00249                 if ( spiCmd == CMD_TEST )
    00250                 {
    00251                     spiState = SLAVE_STATE_TEST ;
    00252                 }
    00253             break ;
    00254
    00255             case SLAVE_STATE_TEST:
    00256                 /* Only CMD_DATA accepted*/
    00257                 if ( (spiCmd & 0xffff0000) == CMD_DATA )
    00258                 {
    00259                     spiState = SLAVE_STATE_DATA ;
    00260                 }
    00261                 numTestBlocks = spiCmd & 0x0000ffff ;
    00262             break;
    00263
    00264             case SLAVE_STATE_DATA:
    00265                 spiStatus.totalNumBlocks++ ;
    00266
    00267                 if ( spiStatus.totalNumBlocks == numTestBlocks )
    00268                 {
    00269                     spiState = SLAVE_STATE_STATUS_ENTRY;
    00270                 }
    00271             break ;
    00272
    00273             case SLAVE_STATE_STATUS_ENTRY :
    00274                 spiState = SLAVE_STATE_STATUS ;
    00275             break ;
    00276
    00277             case SLAVE_STATE_END:
    00278             break;
    00279         }
    00280     }
    00281 }
    00282
    00283 /**
    00284  * \brief  Start waiting new command
    00285  */
    00286 static void SpiSlaveNewCommand( void )
    00287 {
    00288     switch ( spiState )
    00289     {
    00290         case SLAVE_STATE_IDLE:
    00291         case SLAVE_STATE_END:
    00292             spiCmd = RC_SYN;
    00293             SpiSlaveTransfer( &spiCmd, 4, 0, 0 ) ;
    00294         break ;
    00295
    00296         case SLAVE_STATE_TEST:
    00297             spiCmd = RC_RDY;
    00298             SpiSlaveTransfer( &spiCmd, 4, 0 , 0 ) ;
    00299         break ;
    00300
    00301         case SLAVE_STATE_DATA:
    00302             if ( spiStatus.totalNumBlocks < numTestBlocks )
    00303             {
    00304                 SpiSlaveTransfer( spiBuffer, 64, 0, 0 ) ;
    00305             }
    00306         break ;
    00307
    00308         case SLAVE_STATE_STATUS_ENTRY:
    00309             spiCmd = RC_RDY ;
    00310             SpiSlaveTransfer( &spiCmd, 4, 0 , 0 ) ;
    00311             spiState = SLAVE_STATE_STATUS ;
    00312         break ;
    00313
    00314         case SLAVE_STATE_STATUS:
    00315             spiCmd = RC_SYN;
    00316             SpiSlaveTransfer( &spiStatus, sizeof( StatusBlock ), 0, 0 ) ;
    00317             spiState = SLAVE_STATE_END ;
    00318         break ;
    00319     }
    00320 }
    00321
    00322 /**
    00323  * \brief Interrupt handler for the SPI slave.
    00324  */
    00325 void SPI_IrqHandler( void )
    00326 {
    00327     uint32_t status;
    00328     uint8_t startNew = 0;
    00329     status = SPI_GetStatus( SPI_SLAVE_BASE ) ;
    00330
    00331     if ( status & SPI_SR_NSSR )
    00332     {
    00333         if ( status & SPI_SR_RXBUFF )
    00334         {
    00335             /* Disable the RX and TX PDC transfer requests */
    00336             SPI_PdcDisableTx( SPI_SLAVE_BASE ) ;
    00337             SPI_PdcDisableRx( SPI_SLAVE_BASE ) ;
    00338         }
    00339
    00340         if ( status & SPI_IDR_ENDRX )
    00341         {
    00342             SPI_DisableIt( SPI_SLAVE_BASE, SPI_IDR_ENDRX ) ;
    00343         }
    00344
    00345         switch ( status & (SPI_SR_RXBUFF | SPI_SR_ENDRX) )
    00346         {
    00347             case (SPI_SR_RXBUFF | SPI_SR_ENDRX):
    00348             case (SPI_SR_RXBUFF):
    00349                 SpiSlaveCommandProcess() ;
    00350                 startNew = 1 ;
    00351             break ;
    00352
    00353             /* Maybe command break data transfer, start new */
    00354             case SPI_SR_ENDRX:
    00355             {
    00356                 /* Command breaks data transfer */
    00357                 SPI_PdcDisableTx( SPI_SLAVE_BASE ) ;
    00358                 SPI_PdcDisableRx( SPI_SLAVE_BASE ) ;
    00359                 SPI_Configure( SPI_SLAVE_BASE, ID_SPI, 0 ) ;
    00360                 SPI_ConfigureNPCS( SPI_SLAVE_BASE, 0 , 0 ) ;
    00361                 startNew = 1 ;
    00362             }
    00363             break;
    00364
    00365             default:
    00366             break;
    00367         }
    00368
    00369         if ( startNew )
    00370         {
    00371             if ( spiCmd != CMD_END )
    00372             {
    00373                 spiStatus.cmdList[spiStatus.totalNumCommands] = spiCmd;
    00374                 spiStatus.totalNumCommands ++;
    00375             }
    00376             SpiSlaveNewCommand();
    00377         }
    00378     }
    00379
    00380 }
    00381
    00382 /**
    00383  * \brief Initialize SPI as slave
    00384  */
    00385 static void SpiSlaveInitialize( void )
    00386 {
    00387     uint32_t i ;
    00388     printf("-I- Initialize SPI as slave ...\n\r");
    00389     /* Configures a SPI peripheral */
    00390     SPI_Configure(SPI_SLAVE_BASE, ID_SPI, 0);
    00391     SPI_ConfigureNPCS(SPI_SLAVE_BASE, 0 , 0);
    00392     /* Disable the RX and TX PDC transfer requests */
    00393     SPI_PdcDisableTx(SPI_MASTER_BASE);
    00394     SPI_PdcDisableRx(SPI_MASTER_BASE);
    00395     /* Enables a SPI peripheral. */
    00396     SPI_Enable(SPI_SLAVE_BASE);
    00397
    00398     /* Reset status */
    00399     spiStatus.totalNumBlocks   = 0;
    00400     spiStatus.totalNumCommands = 0;
    00401     for ( i = 0; i < NB_STATUS_CMD; i++ )
    00402     {
    00403         spiStatus.cmdList[i] = 0 ;
    00404     }
    00405
    00406     /* Start waiting command */
    00407     spiState = SLAVE_STATE_IDLE;
    00408     spiCmd = RC_SYN;
    00409     SpiSlaveTransfer(&spiCmd, 4, 0, 0);
    00410 }
    00411
    00412 /**
    00413  * \brief Initialize SPI as master
    00414  */
    00415 static void SpiMasterInitialize( void )
    00416 {
    00417     printf( "-I- Configure SPI as master\n\r" ) ;
    00418
    00419     /* Master mode */
    00420     SPI_Configure( SPI_MASTER_BASE, ID_SPI, SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_PCS( 0 ) ) ;
    00421     SPI_ConfigureNPCS( SPI_MASTER_BASE, 0, SPI_DLYBCT( 100000, BOARD_MCK ) | SPI_DLYBS(100000, BOARD_MCK) | SPI_SCBR( spiClock, BOARD_MCK) ) ;
    00422
    00423     /* Disable the RX and TX PDC transfer requests */
    00424     SPI_PdcDisableTx( SPI_MASTER_BASE ) ;
    00425     SPI_PdcDisableRx( SPI_MASTER_BASE ) ;
    00426
    00427     /* Enables a SPI peripheral. */
    00428     SPI_Enable( SPI_MASTER_BASE ) ;
    00429 }
    00430
    00431 /**
    00432  * \brief Sets the specified SPI clock configuration.
    00433  * \param configuration  Index of the configuration to set.
    00434  */
    00435 static void SetClockConfiguration( uint8_t configuration )
    00436 {
    00437     spiClock = clockConfigurations[configuration];
    00438     printf("Setting SPI clock #%d ... \n\r", (int)clockConfigurations[configuration]);
    00439     SpiMasterInitialize();
    00440 }
    00441
    00442 /**
    00443  * \brief Perform SPI master transfer using PDC.
    00444  * \param pBuf Pointer to 1st buffer to transfer.
    00445  * \param size Size of the 1st buffer.
    00446  * \param pNextBuf Pointer to 2nd buffer to transfer.
    00447  * \param nextSize Size of the 2nd buffer.
    00448  */
    00449 static void SpiMasterTransfer( void * pBuf, uint16_t size, void * pNextBuf, uint16_t nextSize )
    00450 {
    00451
    00452     SPI_PdcSetTx(SPI_MASTER_BASE, pBuf, size, pNextBuf, nextSize);
    00453     SPI_PdcSetRx(SPI_MASTER_BASE, pBuf, size, pNextBuf, nextSize);
    00454
    00455     /* Enable the RX and TX PDC transfer requests */
    00456     SPI_PdcEnableRx(SPI_MASTER_BASE);
    00457     SPI_PdcEnableTx(SPI_MASTER_BASE);
    00458
    00459     /* Waiting transfer done*/
    00460     while((SPI_GetStatus(SPI_MASTER_BASE)& SPI_SR_RXBUFF) == 0);
    00461
    00462     /* Disable the RX and TX PDC transfer requests */
    00463     SPI_PdcDisableTx(SPI_MASTER_BASE);
    00464     SPI_PdcDisableRx(SPI_MASTER_BASE);
    00465 }
    00466
    00467 /**
    00468  * \brief Start SPI transfer test.
    00469  */
    00470 static void SpiMasterGo( void )
    00471 {
    00472     uint32_t cmd;
    00473     uint32_t block;
    00474     uint32_t i;
    00475     /* Configure SPI as master, setup SPI clock. */
    00476     SpiMasterInitialize();
    00477
    00478     /* Send CMD_TEST to indicate the start of test, device shall return RC_RDY */
    00479
    00480     while(1) {
    00481         cmd = CMD_TEST;
    00482         printf("-> Master sending CMD_TEST... \n\r");
    00483         SpiMasterTransfer(&cmd, 4, 0, 0);
    00484         if (cmd == RC_RDY) {
    00485             printf("   <- Slave response RC_SYN, RC_RDY \n\r");
    00486             break;
    00487         }
    00488         if (cmd != RC_SYN) {
    00489             printf("-E- Response unexpected: 0x%x \n\r", (unsigned int)cmd);
    00490             return;
    00491         }
    00492     }
    00493     /* Send CMD_DATA with 8 blocks(64 bytes per page). */
    00494     printf("-> Master sending CMD_DATA... \n\r");
    00495     cmd = CMD_DATA | 4;
    00496     SpiMasterTransfer(&cmd, 4, 0, 0);
    00497     printf("                                <---- Slave response RC_RDY \n\r");
    00498     for (block = 0; block < 4; block++) {
    00499         for (i = 0; i < 64; i ++) {
    00500             spiBuffer[i] = block;
    00501         }
    00502         printf("-> Master sending block %d ... \n\r", (int)block);
    00503         SpiMasterTransfer(spiBuffer, 64, 0, 0);
    00504         if (block) {
    00505             for (i = 0; i < 64; i++) {
    00506                 if (spiBuffer[i] != (block - 1)) {
    00507                     break;
    00508                 }
    00509             }
    00510             if (i < 64) {
    00511                 printf("-E- block %d contains unexpected data \n\r", (int)block);
    00512             }
    00513             else {
    00514                 printf("   <- Slave response last block %x \n\r", (unsigned int)(block - 1));
    00515             }
    00516         }
    00517     }
    00518
    00519     for (i = 0; i < 4; i++) {
    00520         cmd = CMD_STATUS;
    00521         printf("-> Master sending CMD_STATUS... \n\r");
    00522         SpiMasterTransfer(&cmd, 4, 0, 0);
    00523         if (cmd == RC_RDY){
    00524             printf("   <- Slave response RC_RDY \n\r");
    00525             break;
    00526         }
    00527     }
    00528     if (i >= 4) {
    00529         printf("   <- Slave no response \n\r");
    00530         return;
    00531     }
    00532
    00533     printf("-> Master request slave status... \n\r");
    00534     SpiMasterTransfer(&spiStatus, sizeof(StatusBlock), 0, 0);
    00535
    00536     printf("   <- Slave reports status...\n\r" ) ;
    00537     printf("-I- Received  %d commands:", (int)spiStatus.totalNumCommands ) ;
    00538
    00539     for ( i = 0 ; i < spiStatus.totalNumCommands ; i ++ )
    00540     {
    00541         printf( " 0x%08x", (unsigned int)spiStatus.cmdList[i] ) ;
    00542     }
    00543     printf( " \n\r-I- Received  %d data blocks \n\r", (int)spiStatus.totalNumBlocks ) ;
    00544
    00545     for ( i = 0 ; i < 4 ; i ++ )
    00546     {
    00547         printf( "-> Master sending CMD_END... \n\r" ) ;
    00548         cmd = CMD_END ;
    00549         SpiMasterTransfer( &cmd, 4, 0, 0 ) ;
    00550
    00551         if ( cmd == RC_SYN )
    00552         {
    00553             printf( "   <- Slave response RC_SYN \n\r" ) ;
    00554             break ;
    00555         }
    00556     }
    00557
    00558     if ( i >= 4 )
    00559     {
    00560         printf( "   <- Slave no response \n\r" ) ;
    00561     }
    00562 }
    00563
    00564 /*----------------------------------------------------------------------------
    00565  *         Global functions
    00566  *----------------------------------------------------------------------------*/
    00567 /**
    00568  * \brief Application entry point for spi_slave example.
    00569  *
    00570  * \return Unused (ANSI-C compatibility).
    00571  */
    00572 extern int main( void )
    00573 {
    00574     uint8_t ucKey ;
    00575
    00576     /* Disable watchdog */
    00577     WDT_Disable( WDT ) ;
    00578
    00579     /* Output example information */
    00580     printf( "-- spi slave example %s --\n\r", SOFTPACK_VERSION ) ;
    00581     printf( "-- %s\n\r", BOARD_NAME ) ;
    00582     printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ;
    00583
    00584     /* Configure PIO Pins for SPI */
    00585     PIO_Configure( pSpiPins, PIO_LISTSIZE( pSpiPins ) ) ;
    00586
    00587     /* Configure SPI interrupts for Slave only*/
    00588     NVIC_DisableIRQ( SPI_IRQn ) ;
    00589     NVIC_ClearPendingIRQ( SPI_IRQn ) ;
    00590     NVIC_SetPriority( SPI_IRQn, 0 ) ;
    00591     NVIC_EnableIRQ( SPI_IRQn ) ;
    00592
    00593     SpiSlaveInitialize() ;
    00594
    00595     /* Display menu */
    00596     DisplayMenu() ;
    00597
    00598     while ( 1 )
    00599     {
    00600         ucKey = UART_GetChar() ;
    00601
    00602         switch ( ucKey )
    00603         {
    00604             case 'h' :
    00605                 DisplayMenu() ;
    00606             break ;
    00607
    00608             case 't' :
    00609                 SpiMasterGo() ;
    00610             break ;
    00611
    00612             default :
    00613                 /* Set configuration #n */
    00614                 if ( (ucKey >= '0') && (ucKey <= ('0' + NUM_SPCK_CONFIGURATIONS - 1)) )
    00615                 {
    00616                     SetClockConfiguration( ucKey - '0' ) ;
    00617                 }
    00618             break ;
    00619         }
    00620     }
    00621 }

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines