4.26.2 EUSART - Enhanced USART

Enhanced Universal Synchronous Asynchronous Receiver Transmitter

4.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.

4.26.2.2 Supported Device Families

PIC12/16F150x PIC12/16F157x PIC12/16F161x
PIC12/16F184x PIC12/16LF155x PIC16F145x
PIC16F151x PIC16F152x PIC16F152xx
PIC16F153xx PIC16F170x PIC16F171x
PIC16F171xx PIC16F176x PIC16F177x
PIC16F178x PIC16F180xx PIC16F181xx
PIC16F183xx PIC16F184xx PIC16F188xx
PIC16F191xx PIC16F194x PIC16LF156x
PIC16LF190x PIC18F-K20 PIC18F-K22
PIC18F-K40 PIC18F-K50 PIC18F-K80
PIC18F-K90 PIC18F-Q10

4.26.2.3 Required header files:


#include "mcc_generated_files/uart/eusart.h"

4.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.

4.26.2.5 Module Documentation

4.26.2.5.1 EUSART

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

Module description

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

Version: EUSART Driver Version 3.0.0
Functions

Function Documentation

EUSART_AutoBaudDetectOverflowReset()

void EUSART_AutoBaudDetectOverflowReset (void )[inline]

This API resets the EUSART ABR Overflow bit.

Parameters:
None.
Returns:

None.

EUSART_AutoBaudQuery()

bool EUSART_AutoBaudQuery (void )[inline]

This API reads the EUSART ABR Complete bit.

Parameters:
None.
Returns:

bool.

EUSART_AutoBaudSet()

void EUSART_AutoBaudSet (bool enable)[inline]

This API enables the EUSART AutoBaud Detection (ABR).

Parameters:
bool

enable.

Returns:

None.

EUSART_Deinitialize()

void EUSART_Deinitialize (void )

This API disables the EUSART driver. This routine disables the EUSART module.

Parameters:
None.
Returns:

None.

EUSART_Disable()

void EUSART_Disable (void )[inline]

This API disables the EUSART module.

Parameters:
None.
Returns:

None.

EUSART_Enable()

void EUSART_Enable (void )[inline]

This API enables the EUSART module.  

Parameters:
None.
Returns:

None.

EUSART_ErrorGet()

size_t EUSART_ErrorGet (void )

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

Parameters:
None.
Returns:

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

EUSART_FramingErrorCallbackRegister()

void EUSART_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.

EUSART_Initialize()

void EUSART_Initialize (void )

This API initializes the EUSART driver. This routine initializes the EUSART module. This is the first called EUSART routine, and it must only be called during the system initialization.

Parameters:
None.
Returns:

None.

Section: EUSART APIs

EUSART_IsAutoBaudDetectOverflow()

bool EUSART_IsAutoBaudDetectOverflow (void )[inline]

This API reads the EUSART ABR Overflow bit.

Parameters:
None.
Returns:

None.

EUSART_IsRxReady()

bool EUSART_IsRxReady (void )

This API checks if the EUSART has received available data.

Parameters:
None.
Return values:
true

if EUSART receiver FIFO has a data

false

EUSART receiver FIFO is empty

EUSART_IsTxDone()

bool EUSART_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

EUSART_IsTxReady()

bool EUSART_IsTxReady (void )

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

Parameters:
None.
Return values:
true

if EUSART transmitter FIFO has atleast 1 byte space

false

if EUSART transmitter FIFO is full

EUSART_OverrunErrorCallbackRegister()

void EUSART_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.

EUSART_Read()

uint8_t EUSART_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 EUSART_IsRxReady(), before calling this API.

Parameters:
None.
Returns:

8-bit data from RX FIFO register.

EUSART_ReceiveDisable()

void EUSART_ReceiveDisable (void )[inline]

This API disables the EUSART receiver.

Parameters:
None.
Returns:

None.

EUSART_ReceiveEnable()

void EUSART_ReceiveEnable (void )[inline]

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

Parameters:
None.
Returns:

None.

EUSART_ReceiveInterruptDisable()

void EUSART_ReceiveInterruptDisable (void )[inline]

This API disables the EUSART receiver interrupt.

Parameters:
None.
Returns:

None.

EUSART_ReceiveInterruptEnable()

void EUSART_ReceiveInterruptEnable (void )[inline]

This API enables the EUSART receiver interrupt.

Parameters:
None.
Returns:

None.

EUSART_ReceiveISR()

void EUSART_ReceiveISR (void )

This ISR function is called upon receiver interrupt.

Parameters:
void.
Returns:

None.

EUSART_RxCompleteCallbackRegister()

void EUSART_RxCompleteCallbackRegister (void(*)(void) callbackHandler)

This API registers the function to be called upon receiver interrupt.

Parameters:
callbackHandler

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

Returns:

None.

EUSART_SendBreakControlDisable()

void EUSART_SendBreakControlDisable (void )[inline]

This API disables the EUSART send break control.

Parameters:
None.
Returns:

None.

EUSART_SendBreakControlEnable()

void EUSART_SendBreakControlEnable (void )[inline]

This API enables the EUSART to send a break control.

Parameters:
None.
Returns:

None.

EUSART_TransmitDisable()

void EUSART_TransmitDisable (void )[inline]

This API disables the EUSART transmitter.

Parameters:
None.
Returns:

None.

EUSART_TransmitEnable()

void EUSART_TransmitEnable (void )[inline]

This API enables the EUSART transmitter. The EUSART must be enabled to sent the bytes over to the TX pin.

Parameters:
None.
Returns:

None.

EUSART_TransmitInterruptDisable()

void EUSART_TransmitInterruptDisable (void )[inline]

This API disables the EUSART transmitter interrupt.

Parameters:
None.
Returns:

None.

EUSART_TransmitInterruptEnable()

void EUSART_TransmitInterruptEnable (void )[inline]

This API enables the EUSART transmitter interrupt.

Parameters:
None.
Returns:

None.

EUSART_TransmitISR()

void EUSART_TransmitISR (void )

This ISR function is called upon transmitter interrupt.

Parameters:
void.
Returns:

None.

EUSART_TxCompleteCallbackRegister()

void EUSART_TxCompleteCallbackRegister (void(*)(void) callbackHandler)

This API registers the function to be called upon Transmitter interrupt.

Parameters:
callbackHandler

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

Returns:

None.

EUSART_Write()

void EUSART_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 EUSART_IsTxReady() before calling this API.

Parameters:
txData

- Data byte to write to the TX FIFO.

Returns:

None.

Variable Documentation

EUSART_RxInterruptHandler

void(* EUSART_RxInterruptHandler) (void)

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

Precondition:

Initialize the EUSART module with receive interrupt enabled

Parameters:
None.
Returns:

None.

EUSART_TxInterruptHandler

void(* EUSART_TxInterruptHandler) (void)

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

Precondition:

Initialize the EUSART module with transmit interrupt enabled

Parameters:
None.
Returns:

None.

UART1

const uart_drv_interface_t UART1

External object for eusart_interface.

Section: Driver Interface

4.26.2.5.2 UART_DRV_INTERFACE

This file contains APIs for the Universal Asynchronous Receiver-Transmitter module.

This file contains APIs for the Universal Asynchronous Receiver-Transmitter module.

Version: UART Driver Version 3.0.0

4.26.2.5.3 UART_TYPES

This file contains APIs for UART module.

This file contains APIs for UART module.

Version: UART Driver Version 3.0.0

4.26.2.6 Class Documentation

4.26.2.6.1 eusart_status_t Struct Reference

Detailed Description

@breif This is a structre defined for errors in reception of data.

#include <eusart.h>

Member Data Documentation

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

source/

eusart.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

4.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>

Public Attributes

Member Data Documentation

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

source/

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)

4.26.2.7 File Documentation

4.26.2.7.1 source/eusart.c File Reference

This is the generated driver implementation file for the EUSART driver using CCL.

#include "../eusart.h"

Functions

Variables

Detailed Description

This is the generated driver implementation file for the EUSART driver using CCL.

EUSART Generated Driver API Header File

Version: EUSART Driver Version 3.0.0

Function Documentation

EUSART_DefaultFramingErrorCallback()

static void EUSART_DefaultFramingErrorCallback (void )[static]

EUSART_DefaultOverrunErrorCallback()

static void EUSART_DefaultOverrunErrorCallback (void )[static]

Macro Definition Documentation

EUSART_RX_BUFFER_MASK

#define EUSART_RX_BUFFER_MASK (EUSART_RX_BUFFER_SIZE - 1)

EUSART_RX_BUFFER_SIZE

#define EUSART_RX_BUFFER_SIZE (8)

EUSART_TX_BUFFER_MASK

#define EUSART_TX_BUFFER_MASK (EUSART_TX_BUFFER_SIZE - 1)

EUSART_TX_BUFFER_SIZE

#define EUSART_TX_BUFFER_SIZE (8)

Section: Included Files Section: Macro Declarations

Variable Documentation

EUSART_FramingErrorHandler

void(* EUSART_FramingErrorHandler) (void)

EUSART_OverrunErrorHandler

void(* EUSART_OverrunErrorHandler) (void)

EUSART_RxInterruptHandler

void(* EUSART_RxInterruptHandler) (void)

EUSART_TxInterruptHandler

void(* EUSART_TxInterruptHandler) (void)

Section: EUSART APIs

eusartRxBuffer

volatile uint8_t eusartRxBuffer[EUSART_RX_BUFFER_SIZE][static]

eusartRxCount

volatile uint8_t eusartRxCount

eusartRxHead

volatile uint8_t eusartRxHead = 0[static]

eusartRxLastError

volatile eusart_status_t eusartRxLastError

eusartRxStatusBuffer

volatile eusart_status_t eusartRxStatusBuffer[EUSART_RX_BUFFER_SIZE][static]

eusartRxTail

volatile uint8_t eusartRxTail = 0[static]

eusartTxBuffer

volatile uint8_t eusartTxBuffer[EUSART_TX_BUFFER_SIZE][static]

eusartTxBufferRemaining

volatile uint8_t eusartTxBufferRemaining

eusartTxHead

volatile uint8_t eusartTxHead = 0[static]

Section: EUSART variables

eusartTxTail

volatile uint8_t eusartTxTail = 0[static]

4.26.2.7.2 source/eusart.h File Reference

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

Functions

Macros

Detailed Description

EUSART Generated Driver API Header File

Macro Definition Documentation

UART1__AutoBaudEventEnableGet

#define UART1__AutoBaudEventEnableGet (NULL)

UART1__IsRxReady

#define UART1__IsRxReady EUSART_IsRxReady

UART1_AutoBaudQuery

#define UART1_AutoBaudQuery EUSART_AutoBaudQuery

UART1_AutoBaudSet

#define UART1_AutoBaudSet EUSART_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 EUSART_Deinitialize

UART1_ErrorGet

#define UART1_ErrorGet EUSART_ErrorGet

UART1_EventCallbackRegister

#define UART1_EventCallbackRegister (NULL)

UART1_FramingErrorCallbackRegister

#define UART1_FramingErrorCallbackRegister EUSART_FramingErrorCallbackRegister

UART1_Initialize

#define UART1_Initialize EUSART_Initialize

UART1_interface

#define UART1_interface UART1

UART1_IsTxDone

#define UART1_IsTxDone EUSART_IsTxDone

UART1_IsTxReady

#define UART1_IsTxReady EUSART_IsTxReady

UART1_OverrunErrorCallbackRegister

#define UART1_OverrunErrorCallbackRegister EUSART_OverrunErrorCallbackRegister

UART1_ParityErrorCallbackRegister

#define UART1_ParityErrorCallbackRegister (NULL)

UART1_Read

#define UART1_Read EUSART_Read

UART1_RxCompleteCallbackRegister

#define UART1_RxCompleteCallbackRegister EUSART_RxCompleteCallbackRegister

UART1_TransmitDisable

#define UART1_TransmitDisable EUSART_TransmitDisable

UART1_TransmitEnable

#define UART1_TransmitEnable EUSART_TransmitEnable

UART1_TxCollisionCallbackRegister

#define UART1_TxCollisionCallbackRegister (NULL)

UART1_TxCompleteCallbackRegister

#define UART1_TxCompleteCallbackRegister EUSART_TxCompleteCallbackRegister

UART1_Write

#define UART1_Write EUSART_Write

4.26.2.7.3 source/uart_drv_interface.h File Reference

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

Data structures

Detailed Description

UART Generated Driver Interface Header File

4.26.2.7.4 source/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