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

NUC122 SPI Peripheral Driver. More...

Collaboration diagram for NUC122 SPI:

Modules

 xSPI Interrupts
 

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


 NUC122 SPI Configure
 

Values that can be passed to SPIConfig.


 NUC122 SPI Slave Select Configure
 

Values that can be passed to SPIAutoSSEnable() SPISSSet() SPISSClear() SPISSConfig().


 NUC122 SPI Byte Reorder
 

Values that can be passed to SPIByteReorderSet().


 NUC122 SPI API
 

NUC122 SPI API Reference.



Detailed Description

NUC122 SPI Peripheral Driver.

The CoX Peripheral Library also provides APIs for full functions of Nuvoton NUC122 SPI.This module supports the whole NUC122 Series.


Contents


1. Spi Physical Block

NUC122_spi_block.png


2. Functional Description

The system control block has the following functions:


3. API Groups

The Spi API is broken into three groups of functions:


3.1 SPI configuration control APIs


3.2 SPI Interrupt Control APIs


3.3 SPI Transfer&Receive Control


4 Program Examples

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

 #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
    //
    SysCtlClockSet(50000000, SYSCTL_OSC_MAIN | SYSCTL_XTAL_12MHZ);

    //
    // Step 2, Enable Peripheral SPI0
    //
    SysCtlPeripheralEnable2(SPI0_BASE);
 
    //
    // Step 3, you should configures a pin for use as a SPI function
    //
    GPIOPinFunctionSet(GPIO_FUNCTION_SPI, GPIO_PORTC_BASE, GPIO_PIN_0);
    GPIOPinFunctionSet(GPIO_FUNCTION_SPI, GPIO_PORTC_BASE, GPIO_PIN_1);
    GPIOPinFunctionSet(GPIO_FUNCTION_SPI, GPIO_PORTC_BASE, GPIO_PIN_2);
    GPIOPinFunctionSet(GPIO_FUNCTION_SPI, GPIO_PORTC_BASE, GPIO_PIN_3);

    //
    // Step 4, you should configure MCU as a master or slave device , data width 
    // MSB or LSB first and Mode
    //
    SPIConfigSet(SPI0_BASE, 100000, SPI_MOTO_FORMAT_MODE_1 |
                                           SPI_MODE_MASTER | 
                                             SPI_MSB_FIRST |
                                            SPI_DATA_WIDTH8);
    //
    // Step 5, you should use SPI slave select pin to connect with an off-chip  
    // slave device. Slave select signal is active low.
    //
    SPISSSet(SPI0_BASE, SPI_SS_HARDWARE, SPI_SS0); 
     
    //
    // Step 6, you can transfer data right now.
    //
    SPIDataWrite(SPI0_BASE, ucSendData, 16);
  }
Note: