CoX Peripheral Interface(NUC122 Implement) V2.1.1.0
API Reference
xSPI

CoX SPI Peripheral Interface. More...

Collaboration diagram for xSPI:

Modules

 xSPI Interrupts
 

Values that can be passed to SPIIntEnable, SPIIntDisable, and SPIIntClear as the ulIntFlags parameter, and returned from SPIIntStatus.


 xSPI Interrupt Event
 xSPI Configure
 xSPI Slave Select Mode
 xSPI Slave Select
 xSPI API
 

xSPI API Reference.



Detailed Description

CoX SPI Peripheral Interface.

The xSPI is the SPI Peripheral Interrupt of CoX.It defines some common macros and APIs macro and APIs

Contents


1 How is the SPI API Standard Define?

CoX SPI defines the APIs based on the following common functions:


2 API Groups

The CoX SPI APIs can be classified into three groups by functions:


2.1 2.1 SPI configuration control APIs


2.2 SPI Interrupt Control APIs


2.3 SPI Transfer&Receive Control


3 Program Examples

The following example shows how to use the SPI APIs to configue SPI and to implement the function of transferring and receiving.

 \code
 #include "xhw_types.h"
 #include "xsysctl.h"
 #include "xhw_memmap.h"
 #include "xspi.h"
 #include "xhw_spi.h"
 #include "xgpio.h"

 unsigned char ucSendData[] = "Wonderful World!";

 //*****************************************************************************

 //Ininite the SPI and implement the function of data transmission.

 //param None

 //This function is to ininite the SPI and implement the function of data transmission.

 //return none

 //*****************************************************************************
 void SpiInitAndTransfer(void)
 {

    //
    // Step 1, Set SysClk 50MHz using Extern 12M oscillator
    //
    xSysCtlClockSet(50000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ);

    //
    // Step 2, Enable Peripheral SPI0
    //
    xSysCtlPeripheralEnable2(SPI0_BASE);

    //
    // Step 3, Enable GPIO which is multiplex
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPort(PC0));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(PC1));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(PC2));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(PC3));

    //
    // Step 4, you should configures a pin for use as a SPI function
    //
    xSPinTypeSPI(SPI0_CS, PC0);
    xSPinTypeSPI(SPI0_CLK, PC1);
    xSPinTypeSPI(SPI0_MISO, PC2);
    xSPinTypeSPI(SPI0_MOSI, PC3);

    //
    // Step 5, you should configure MCU as a master or slave device , data width 
    // MSB or LSB first and Mode
    //
    xSPIConfigSet(SPI0_BASE, 100000, xSPI_MOTO_FORMAT_MODE_1 |
                                            xSPI_MODE_MASTER | 
                                              xSPI_MSB_FIRST |
                                            xSPI_DATA_WIDTH8);
    //
    // Step 6, you should use SPI slave select pin to connect with an off-chip  
    // slave device. Slave select signal is active low.
    //
    xSPISSSet(SPI0_BASE, xSPI_SS_HARDWARE, xSPI_SS0); 
     
    //
    // Step 7, you can transfer data right now.
    //
    xSPIDataWrite(SPI0_BASE, ucSendData, 16);
  }
Note: