SPI Peripheral Library for MPLAB® Harmony v2

This library allows you to control various Serial Peripheral Interface (SPI) functionality, including:

  • Data Transfer Functions
  • Transmitter Functions
  • Receiver Functions
  • Framed Mode Functions
  • Audio Mode Functions

The Serial Peripheral Interface library (SPI-PLIB) controls the SPI communications by accessing the PIC32's SPI Special Function Registers (SFRs). These registers are accessed using the PLIB functions. You do not need to know an SFR name or the specific SFR bit-field when calling an SPI-PLIB function. You have to identify the specific function to be performed on that timer.

Example SPI Library Functions

Mode Control

Function NameDescription
PLIB_SPI_Enable (SPI_ID_2)Turns on the SPI Module
PLIB_SPI_Disable (SPI_ID_1)Disables the SPI Module
PLIB_SPI_MasterEnable (SPI_ID_3)Puts an SPI module in Master Mode
PLIB_SPI_SlaveEnable (SPI_ID_1)Puts an SPI Module in Slave Mode.
PLIB_SPI_BaudRateSet (MY_SPI_INSTANCE,MY_CLOCK_FREQUENCY, 9600)Sets the SPI Baudrate

Reading and Writing Data

Function NameDescription
PLIB_SPI_BufferAddressGet (SPI_ID_1)Returns the address of the SPI module's transmit/receive buffer.
PLIB_SPI_BufferRead (SPI_ID_1)Returns the value in the SPI read buffer
PLIB_SPI_BufferWrite (SPI_ID_3, data)Writes the value - data - to the SPI write buffer

The PLIB parameter for specifying an SPI Model (SPI_ID_x) is defined by the enumSPI_NUMBER_OF_MODULES, in the header file for the PIC32 being used.

 Learn More