3 Asynchronous and Synchronous Driver Configuration

Configuring Drivers

MPLAB Harmony v3 enables the user to configure drivers in Synchronous or Asynchronous mode using the MPLAB Code Configurator.

To configure drivers, follow these steps:

  1. In the MCC Project Graph window, from the left Navigation pane, select SPI.
  2. In the right Configuration Options section, click and expand SPI.
  3. For Driver Mode, select Synchronous or Asynchronous.
Figure 3-1. MPLAB Harmony v3 SPI Driver Mode Configuration

Differences

The following table provides the SPI Synchronous and Asynchronous driver APIs to perform the read and write operations.

Table 3-1. MPLAB Harmony v3 SPI Asynchronous and Synchronous Driver APIs and SPI PLIB APIs
SPI Asynchronous Driver APIsSPI Synchronous Driver APIsSPI PLIB APIs
DRV_SPI_WriteTransferAdd DRV_SPI_WriteTransferSPI0_Write (…)
SPI1_Write (…)
DRV_SPI_ReadTransferAdd DRV_SPI_ReadTransfer SPI0_Read (…)
SPI1_Read (…)
Note: It does not matter which driver mode is selected (Synchronous or Asynchronous), the SPI driver uses the same underlying PLIB APIs.

The following table provides the differences in the SPI driver APIs that are generated based on the driver mode selection.

Table 3-2. Differences in SPI Asynchronous and Synchronous Driver APIs
SPI Asynchronous Driver APIsSPI Synchronous Driver APIs
DRV_SPI_WriteTransferAddDRV_SPI_WriteTransfer
DRV_SPI_ReadTransferAddDRV_SPI_ReadTransfer
DRV_SPI_WriteReadTransferAddDRV_SPI_WriteReadTransfer
DRV_SPI_TransferEventHandlerSetN/A
DRV_SPI_TransferStatusGetN/A

The following table provides the common SPI driver APIs that are generated regardless of the driver mode selected.

Table 3-3. Common SPI Asynchronous and Synchronous Driver APIs
SPI Driver APIs
DRV_SPI_Initialize
DRV_SPI_Status
DRV_SPI_Open
DRV_SPI_Close
DRV_SPI_TransferSetup

The following table shows the summary of differences between Synchronous and Asynchronous drivers.

Table 3-4. Summary of the Differences Between Synchronous and Asynchronous Drivers
Asynchronous DriversSynchronous Drivers
Non-Blocking APIsBlocking APIs
Works seamlessly in bare-metal and supports in an RTOS environmentSuitable to use in RTOS environment
Each instance of a driver has a dedicated queue. The driver allows queuing of multiple requests.A request to driver blocks the application until the submitted request is serviced. Therefore a queue is not needed.
A transfer request is identified through a transfer handle. The client can get a transfer request status using a polling or callback mechanism by passing the transfer handle to the APIs. For example:

Polling Mechanism: The API, DRV_SPI_TransferStatusGet(), can be used to poll the status of the queued transfer request.

Callback Mechanism: The API, DRV_SPI_TransferEventHandlerSet(), is called to register the callback function with the driver to notify with an event when the transfer request is completed.

Since the API is blocking, and the return value of the API indicates the transfer status, there is no need for the transfer handle.
Interrupt and Thread SafeInterrupt and Thread Safe
Note: The MPLAB Code Configurator takes care of generating the PLIB APIs regardless of the driver mode is selected.

Both Synchronous (only in RTOS environment) and Asynchronous drivers are supported for UART, I2C, SPI, SDSPI, and memory device (MX25L, AT25DF, NVM, and SST26) peripherals. Only the Asynchronous driver is supported for SDMMC, external EEPROM (AT24 and AT25), SPI Flash (AT25DF), SQI Flash (MX25L and SST26).