USART Static Driver Library for Harmony v2

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
Initialize USART driver instance 0 (not the non-existant USART0 peripheral)
Returns true if USART instance 0 receiver buffer is empty
Receive a byte from USART instance 0
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.

USART static driver Details
Learn more >

 Learn More

Harmony USART Tutorial
Learn more >
Example Code and Projects
Learn more >
Entire USART Driver Interface
Learn more >
USART Hardware Description
Learn more >
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.