Creating USART Static Drivers
The static driver library is used to control individual Universal Synchronous/Asynchronous Receiver/Transmitter (USART) peripherals (USART1 or USART2 or …) The MPLAB® Harmony Configurator (MHC) is used to configure which USART peripheral is controlled by a specific USART driver instance. These custom drivers are created by MHC when you generate the files (click the "Generate" button.) Here are some examples of static drivers:
rx_byte = DRV_USART0_ReadByte (); // Read a byte from USART driver instance 0.
DRV_USART0_WriteByte ('a'); // Write character 'a' to USART driver instance 0.
DRV_USART1_WriteByte ('b'); // Write character 'b' to USART driver instance 1.
If the static drivers shown above were configured by MHC as shown in the picture below, then the character 'a' will be transmitted on USART4 and 'b' will be transmitted on USART2.
Harmony static drivers are simpler to use than dynamic drivers because they don't rely on an object-oriented (data structure-oriented) programming model. Data structures (objects) defining the drivers are not needed for the static drivers because the static driver functions are generated (customized) by MHC, based on the selections you've made in MHC.
USART Static Driver Functions |
---|
DRV_USART0_Initialize() Initialize USART driver instance 0 (not the non-existant USART0 peripheral) |
DRV_USART0_ReceiverBufferIsEmpty() Returns true if USART instance 0 receiver buffer is empty |
DRV_USART0_ReadByte() Receive a byte from USART instance 0 |
DRV_USART0_WriteByte('c') Transmit the character 'c' to USART instance 0 |
The static driver functions shown above are for USART driver instance 0. The "0" in USART0" indicates which driver instance is being controlled. In other words, if you need two static drivers, MHC will generate a group of "USART0" functions and a group of "USART1" functions (to control driver instance 0 and instance 1 respectively.)
The static driver Application Programming Interface (API) is much smaller than the dynamic driver API and only implements a Byte-by-Byte Transfer Model. These are all the functions implemented for a single USART static driver instance.
Using USART Static Drivers
Once you have used MHC to generate the USART static drivers, you can use them as shown in the example below:
Using the USART Static Driver
You do not need to understand how MHC creates static drivers to use them. If you want these details, click the "USART Static Driver Details" button below. For a higher-level understanding of how to use USART static drivers, click on the "Harmony USART Tutorial" button below.