3.26.2 EUSART - Enhanced USART

Enhanced Universal Synchronous Asynchronous Receiver Transmitter

3.26.2.1 Introduction

The Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) module is a serial I/O communications peripheral. It contains all the clock generators, shift registers and data buffers necessary to perform an input or output serial data transfer independent of device program execution. The EUSART, also known as a Serial Communications Interface (SCI), can be configured as a full-duplex asynchronous system or half-duplex synchronous system.

3.26.2.2 Supported Device Families

PIC12/16F150xPIC12/16F157xPIC12/16F161x
PIC12/16F184xPIC12/16LF155xPIC16F145x
PIC16F151xPIC16F152xPIC16F152xx
PIC16F153xxPIC16F170xPIC16F171x
PIC16F171xxPIC16F176xPIC16F177x
PIC16F178xPIC16F180xxPIC16F181xx
PIC16F183xxPIC16F184xxPIC16F188xx
PIC16F191xxPIC16F194xPIC16LF156x
PIC16LF190xPIC18F-K20PIC18F-K22
PIC18F-K40PIC18F-K50PIC18F-K80
PIC18F-K90PIC18F-Q10

3.26.2.3 Required header files:


#include "mcc_generated_files/uart/eusart.h"

3.26.2.4 How to use the EUSART PLIB Driver

For use cases for the EUSART, see: How to use the UART Driver.

The examples there use the portable API interface of the driver, but could easily be modified to directly us the PLIB API.

3.26.2.5 Module Documentation

3.26.2.5.1 EUSART1

This file contains API prototypes and other datatypes for the Enhanced Universal Synchronous and Asynchronous Receiver Transceiver (EUSART) module.

Module description

This file contains API prototypes and other datatypes for the Enhanced Universal Synchronous and Asynchronous Receiver Transceiver (EUSART) module.

Version: EUSART1 Driver Version 3.0.1
Data structures
  • struct eusart1_status_t

    This is a structure defined for errors in reception of data.

Functions

Function Documentation

EUSART1_AutoBaudDetectOverflowReset()

void EUSART1_AutoBaudDetectOverflowReset (void )

This API resets the EUSART1 ABR Overflow bit.

Parameters:
None.
Returns:

None.

EUSART1_AutoBaudQuery()

bool EUSART1_AutoBaudQuery (void )

This API reads the EUSART1 ABR Complete bit.

Parameters:
None.
Returns:

bool.

EUSART1_AutoBaudSet()

void EUSART1_AutoBaudSet (bool enable)

This API enables the EUSART1 AutoBaud Detection (ABR).

Parameters:
bool

enable.

Returns:

None.

EUSART1_Deinitialize()

void EUSART1_Deinitialize (void )

Deinitializes and disables the EUSART1 module.

Parameters:
None.
Returns:

None.

EUSART1_Disable()

void EUSART1_Disable (void )

This API disables the EUSART1 module.

Parameters:
None.
Returns:

None.

EUSART1_Enable()

void EUSART1_Enable (void )

This API enables the EUSART1 module.  

Parameters:
None.
Returns:

None.

EUSART1_ErrorGet()

size_t EUSART1_ErrorGet (void )

This function receives the error status of the last read byte.

Parameters:
None.
Returns:

Status of the last read byte. See eusart1_status_t struct for more details.

EUSART1_FramingErrorCallbackRegister()

void EUSART1_FramingErrorCallbackRegister (void(*)(void) callbackHandler)

This API registers the function to be called upon framing error.

Parameters:
callbackHandler

- a function pointer which will be called upon framing error condition.

Returns:

None.

EUSART1_Initialize()

void EUSART1_Initialize (void )

Initializes the EUSART1 module. This routine is called only once during system initialization, before calling other APIs.

Parameters:
None.
Returns:

None.

Section: EUSART1 APIs

EUSART1_IsAutoBaudDetectOverflow()

bool EUSART1_IsAutoBaudDetectOverflow (void )

This API reads the EUSART1 ABR Overflow bit.

Parameters:
None.
Returns:

None.

EUSART1_IsRxReady()

bool EUSART1_IsRxReady (void )

This API checks if the EUSART1 has received available data.

Parameters:
None.
Return values:
true

if EUSART1 receiver FIFO has a data

false

EUSART1 receiver FIFO is empty

EUSART1_IsTxDone()

bool EUSART1_IsTxDone (void )

This function returns the status of Transmit Shift Register (TSR).

Parameters:
None.
Return values:
true

if Data completely shifted out from the TSR

false

if Data is present in Transmit FIFO and/or in TSR

EUSART1_IsTxReady()

bool EUSART1_IsTxReady (void )

This function checks if the EUSART1 transmitter is ready to accept a data byte.

Parameters:
None.
Return values:
true

if EUSART1 transmitter FIFO has atleast 1 byte space

false

if EUSART1 transmitter FIFO is full

EUSART1_OverrunErrorCallbackRegister()

void EUSART1_OverrunErrorCallbackRegister (void(*)(void) callbackHandler)

This API registers the function to be called upon overrun error.

Parameters:
callbackHandler

- a function pointer which will be called upon overrun error condition.

Returns:

None.

EUSART1_Read()

uint8_t EUSART1_Read (void )

This function reads the 8 bits from the FIFO register receiver.

Precondition:

The transfer status must be checked to see if the receiver is not empty before calling this function. Verify the EUSART1_IsRxReady(), before calling this API.

Parameters:
None.
Returns:

8-bit data from RX FIFO register.

EUSART1_ReceiveDisable()

void EUSART1_ReceiveDisable (void )

This API disables the EUSART1 receiver.

Parameters:
None.
Returns:

None.

EUSART1_ReceiveEnable()

void EUSART1_ReceiveEnable (void )

This API enables the EUSART1 receiver. The EUSART1 must be enabled to receive the bytes sent by the RX pin.

Parameters:
None.
Returns:

None.

EUSART1_ReceiveInterruptDisable()

void EUSART1_ReceiveInterruptDisable (void )

This API disables the EUSART1 receiver interrupt.

Parameters:
None.
Returns:

None.

EUSART1_ReceiveInterruptEnable()

void EUSART1_ReceiveInterruptEnable (void )

This API enables the EUSART1 receiver interrupt.

Parameters:
None.
Returns:

None.

EUSART1_ReceiveISR()

void EUSART1_ReceiveISR (void )

This ISR function is called upon receiver interrupt.

Parameters:
void.
Returns:

None.

EUSART1_RxCompleteCallbackRegister()

void EUSART1_RxCompleteCallbackRegister (void(*)(void) callbackHandler)

This API registers the function to be called upon after data has been successfully received.

Parameters:
callbackHandler

- a function pointer which will be called upon receiver interrupt condition.

Returns:

None.

EUSART1_SendBreakControlDisable()

void EUSART1_SendBreakControlDisable (void )

This API disables the EUSART1 send break control.

Parameters:
None.
Returns:

None.

EUSART1_SendBreakControlEnable()

void EUSART1_SendBreakControlEnable (void )

This API enables the EUSART1 to send a break control.

Parameters:
None.
Returns:

None.

EUSART1_TransmitDisable()

void EUSART1_TransmitDisable (void )

This API disables the EUSART1 transmitter.

Parameters:
None.
Returns:

None.

EUSART1_TransmitEnable()

void EUSART1_TransmitEnable (void )

This API enables the EUSART1 transmitter. The EUSART1 must be enabled to send the bytes over to the TX pin.

Parameters:
None.
Returns:

None.

EUSART1_TransmitInterruptDisable()

void EUSART1_TransmitInterruptDisable (void )

This API disables the EUSART1 transmitter interrupt.

Parameters:
None.
Returns:

None.

EUSART1_TransmitInterruptEnable()

void EUSART1_TransmitInterruptEnable (void )

This API enables the EUSART1 transmitter interrupt.

Parameters:
None.
Returns:

None.

EUSART1_TransmitISR()

void EUSART1_TransmitISR (void )

This ISR function is called upon transmitter interrupt.

Parameters:
void.
Returns:

None.

EUSART1_TxCompleteCallbackRegister()

void EUSART1_TxCompleteCallbackRegister (void(*)(void) callbackHandler)

This API registers the function to be called upon after data has been successfully transmitted.

Parameters:
callbackHandler

- a function pointer which will be called upon transmitter interrupt condition.

Returns:

None.

EUSART1_Write()

void EUSART1_Write (uint8_t txData)

This function writes a byte of data to the transmitter FIFO register.

Precondition:

The transfer status must be checked to see if the transmitter is ready to accept a byte before calling this function. Verify the EUSART1_IsTxReady() before calling this API.

Parameters:
txData

- Data byte to write to the TX FIFO.

Returns:

None.

getch()

int getch (void )

This function used to printf support for reads the 8 bits from the FIFO register receiver.

Parameters:
None.
Returns:

8-bit data from RX FIFO register.

putch()

void putch (char txData)

This function used to printf support for writes a byte of data to the transmitter FIFO register.

Parameters:
txData

- Data byte to write to the TX FIFO.

Returns:

None.

Variable Documentation

EUSART1_RxInterruptHandler

void(* EUSART1_RxInterruptHandler) (void)

This indicates the function that will be called upon receive interrupt.

Precondition:

Initialize the EUSART1 module with receive interrupt enabled

Parameters:
None.
Returns:

None.

EUSART1_TxInterruptHandler

void(* EUSART1_TxInterruptHandler) (void)

This indicates the function that will be called upon transmit interrupt.

Precondition:

Initialize the EUSART1 module with transmit interrupt enabled

Parameters:
None.
Returns:

None.

Section: EUSART1 APIs

UART1

const uart_drv_interface_t UART1

External object for eusart1_interface.

Section: Driver Interface

3.26.2.5.2 UART_DRV_INTERFACE

This file contains API prototypes and data types of the Universal Asynchronous Receiver and Transmitter (UART) interface.

This file contains API prototypes and data types of the Universal Asynchronous Receiver and Transmitter (UART) interface.

Version: UART Driver Version 3.0.2

3.26.2.5.3 UART_TYPES

This file contains the enumeration of different Universal Asynchronous Receiver and Transmitter (UART) baud rates.

This file contains the enumeration of different Universal Asynchronous Receiver and Transmitter (UART) baud rates.

Version: UART Driver Version 3.0.2

3.26.2.6 Data Structure Documentation

3.26.2.6.1 eusart1_status_t Struct Reference

This is a structure defined for errors in reception of data.

Detailed Description

This is a structure defined for errors in reception of data.

#include <eusart1.h>

Field Documentation

The documentation for this struct was generated from the following file:

source/source-files/

eusart1.h

@1

struct { ... }

ferr

uint8_t ferr

This is a bit field for Framing Error status

oerr

uint8_t oerr

This is a bit field for Overfrun Error status

perr

uint8_t perr

This is a bit field for Parity Error status

reserved

uint8_t reserved

Reserved

status

size_t status

Group byte for status errors

3.26.2.6.2 uart_drv_interface_t Struct Reference

Structure containing the function pointers of UART driver.

Detailed Description

Structure containing the function pointers of UART driver.

Section: Included Files Section: Data Type Definitions

#include <uart_drv_interface.h>

Data Fields

Field Documentation

The documentation for this struct was generated from the following file:

source/source-files/

uart_drv_interface.h

AutoBaudEventEnableGet

bool(* AutoBaudEventEnableGet) (void)

AutoBaudQuery

bool(* AutoBaudQuery) (void)

AutoBaudSet

void(* AutoBaudSet) (bool enable)

BaudRateGet

uint32_t(* BaudRateGet) (void)

BaudRateSet

void(* BaudRateSet) (uint32_t baudRate)

BRGCountGet

uint32_t(* BRGCountGet) (void)

BRGCountSet

void(* BRGCountSet) (uint32_t brgValue)

Deinitialize

void(* Deinitialize) (void)

ErrorGet

size_t(* ErrorGet) (void)

EventCallbackRegister

void(* EventCallbackRegister) (void(*CallbackHandler)(void))

FramingErrorCallbackRegister

void(* FramingErrorCallbackRegister) (void(*CallbackHandler)(void))

Initialize

void(* Initialize) (void)

IsRxReady

bool(* IsRxReady) (void)

IsTxDone

bool(* IsTxDone) (void)

IsTxReady

bool(* IsTxReady) (void)

OverrunErrorCallbackRegister

void(* OverrunErrorCallbackRegister) (void(*CallbackHandler)(void))

ParityErrorCallbackRegister

void(* ParityErrorCallbackRegister) (void(*CallbackHandler)(void))

Read

uint8_t(* Read) (void)

RxCompleteCallbackRegister

void(* RxCompleteCallbackRegister) (void(*CallbackHandler)(void))

TransmitDisable

void(* TransmitDisable) (void)

TransmitEnable

void(* TransmitEnable) (void)

TxCollisionCallbackRegister

void(* TxCollisionCallbackRegister) (void(*CallbackHandler)(void))

TxCompleteCallbackRegister

void(* TxCompleteCallbackRegister) (void(*CallbackHandler)(void))

Write

void(* Write) (uint8_t)

3.26.2.7 File Documentation

3.26.2.7.1 source/source-files/eusart1.c File Reference

This is the generated driver implementation file for the EUSART1 driver using the Enhanced Universal Synchronous and Asynchronous Receiver Transceiver (EUSART) module.

#include "../eusart1.h"

Functions

Variables

Detailed Description

This is the generated driver implementation file for the EUSART1 driver using the Enhanced Universal Synchronous and Asynchronous Receiver Transceiver (EUSART) module.

EUSART1 Generated Driver API Header File

Version: EUSART1 Driver Version 3.0.1

Function Documentation

EUSART1_DefaultFramingErrorCallback()

static void EUSART1_DefaultFramingErrorCallback (void )[static]

EUSART1_DefaultOverrunErrorCallback()

static void EUSART1_DefaultOverrunErrorCallback (void )[static]

Macro Definition Documentation

EUSART1_RX_BUFFER_MASK

#define EUSART1_RX_BUFFER_MASK (EUSART1_RX_BUFFER_SIZE - 1U)

EUSART1_RX_BUFFER_SIZE

#define EUSART1_RX_BUFFER_SIZE (8U)

EUSART1_TX_BUFFER_MASK

#define EUSART1_TX_BUFFER_MASK (EUSART1_TX_BUFFER_SIZE - 1U)

EUSART1_TX_BUFFER_SIZE

#define EUSART1_TX_BUFFER_SIZE (8U)

Section: Included Files Section: Macro Declarations

Variable Documentation

EUSART1_FramingErrorHandler

void(* EUSART1_FramingErrorHandler) (void) = NULL[static]

EUSART1_OverrunErrorHandler

void(* EUSART1_OverrunErrorHandler) (void) = NULL[static]

EUSART1_RxCompleteInterruptHandler

void(* EUSART1_RxCompleteInterruptHandler) (void) = NULL[static]

EUSART1_TxCompleteInterruptHandler

void(* EUSART1_TxCompleteInterruptHandler) (void) = NULL[static]

eusart1RxBuffer

volatile uint8_t eusart1RxBuffer[EUSART1_RX_BUFFER_SIZE][static]

eusart1RxCount

volatile uint8_t eusart1RxCount[static]

eusart1RxHead

volatile uint8_t eusart1RxHead = 0[static]

eusart1RxLastError

volatile eusart1_status_t eusart1RxLastError[static]

eusart1RxStatusBuffer

volatile eusart1_status_t eusart1RxStatusBuffer[EUSART1_RX_BUFFER_SIZE][static]

eusart1RxTail

volatile uint8_t eusart1RxTail = 0[static]

eusart1TxBuffer

volatile uint8_t eusart1TxBuffer[EUSART1_TX_BUFFER_SIZE][static]

eusart1TxBufferRemaining

volatile uint8_t eusart1TxBufferRemaining[static]

eusart1TxHead

volatile uint8_t eusart1TxHead = 0[static]

Section: EUSART1 variables

eusart1TxTail

volatile uint8_t eusart1TxTail = 0[static]

3.26.2.7.2 source/source-files/eusart1.h File Reference

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "../system/system.h"
#include "uart_drv_interface.h"

Data structures

  • struct eusart1_status_t

    This is a structure defined for errors in reception of data.

Functions

Macros

Detailed Description

EUSART1 Generated Driver API Header File

Macro Definition Documentation

UART1__AutoBaudEventEnableGet

#define UART1__AutoBaudEventEnableGet (NULL)

UART1__IsRxReady

#define UART1__IsRxReady EUSART1_IsRxReady

UART1_AutoBaudQuery

#define UART1_AutoBaudQuery EUSART1_AutoBaudQuery

UART1_AutoBaudSet

#define UART1_AutoBaudSet EUSART1_AutoBaudSet

UART1_BaudRateGet

#define UART1_BaudRateGet (NULL)

UART1_BaudRateSet

#define UART1_BaudRateSet (NULL)

UART1_BRGCountGet

#define UART1_BRGCountGet (NULL)

UART1_BRGCountSet

#define UART1_BRGCountSet (NULL)

UART1_Deinitialize

#define UART1_Deinitialize EUSART1_Deinitialize

UART1_ErrorGet

#define UART1_ErrorGet EUSART1_ErrorGet

UART1_EventCallbackRegister

#define UART1_EventCallbackRegister (NULL)

UART1_FramingErrorCallbackRegister

#define UART1_FramingErrorCallbackRegister EUSART1_FramingErrorCallbackRegister

UART1_Initialize

#define UART1_Initialize EUSART1_Initialize

UART1_interface

#define UART1_interface UART1

UART1_IsTxDone

#define UART1_IsTxDone EUSART1_IsTxDone

UART1_IsTxReady

#define UART1_IsTxReady EUSART1_IsTxReady

UART1_OverrunErrorCallbackRegister

#define UART1_OverrunErrorCallbackRegister EUSART1_OverrunErrorCallbackRegister

UART1_ParityErrorCallbackRegister

#define UART1_ParityErrorCallbackRegister (NULL)

UART1_Read

#define UART1_Read EUSART1_Read

UART1_RxCompleteCallbackRegister

#define UART1_RxCompleteCallbackRegister EUSART1_RxCompleteCallbackRegister

UART1_TransmitDisable

#define UART1_TransmitDisable EUSART1_TransmitDisable

UART1_TransmitEnable

#define UART1_TransmitEnable EUSART1_TransmitEnable

UART1_TxCollisionCallbackRegister

#define UART1_TxCollisionCallbackRegister (NULL)

UART1_TxCompleteCallbackRegister

#define UART1_TxCompleteCallbackRegister EUSART1_TxCompleteCallbackRegister

UART1_Write

#define UART1_Write EUSART1_Write

3.26.2.7.3 source/source-files/uart_drv_interface.h File Reference

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "uart_types.h"

Data structures

Detailed Description

UART Generated Driver Interface Header File

3.26.2.7.4 source/source-files/uart_types.h File Reference

#include <stdbool.h>
#include <stdint.h>

Detailed Description

UART Generated Driver Interface Header File

Enumeration Type Documentation

UART_STANDARD_BAUDS

enum UART_STANDARD_BAUDS

This Enum can be used to set the UART standard baud rates using UARTx_BRGSet function e.g. UART1_BRGSet.

Section: Included Files Section: Data Type Definitions

UART_110
UART_300
UART_600
UART_1200
UART_2400
UART_4800
UART_9600
UART_14400
UART_19200
UART_38400
UART_57600
UART_115200
UART_230400
UART_460800
UART_921600