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:
- In the MCC Project Graph window, from the left Navigation pane, select SPI.
- In the right Configuration Options section, click and expand SPI.
- For Driver Mode, select Synchronous or Asynchronous.
Differences
The following table provides the SPI Synchronous and Asynchronous driver APIs to perform the read and write operations.
SPI Asynchronous Driver APIs | SPI Synchronous Driver APIs | SPI PLIB APIs |
---|---|---|
DRV_SPI_WriteTransferAdd
| DRV_SPI_WriteTransfer | SPI0_Write (…) |
SPI1_Write (…) | ||
DRV_SPI_ReadTransferAdd
| DRV_SPI_ReadTransfer
| SPI0_Read (…) |
SPI1_Read (…) |
The following table provides the differences in the SPI driver APIs that are generated based on the driver mode selection.
SPI Asynchronous Driver APIs | SPI Synchronous Driver APIs |
---|---|
DRV_SPI_WriteTransferAdd | DRV_SPI_WriteTransfer |
DRV_SPI_ReadTransferAdd | DRV_SPI_ReadTransfer |
DRV_SPI_WriteReadTransferAdd | DRV_SPI_WriteReadTransfer |
DRV_SPI_TransferEventHandlerSet | N/A |
DRV_SPI_TransferStatusGet | N/A |
The following table provides the common SPI driver APIs that are generated regardless of the driver mode selected.
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.
Asynchronous Drivers | Synchronous Drivers |
---|---|
Non-Blocking APIs | Blocking APIs |
Works seamlessly in bare-metal and supports in an RTOS environment | Suitable 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,
Callback Mechanism: The API,
| 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 Safe | Interrupt and Thread Safe |
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).