nrfx 3.3
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
UARTE driver

UARTE peripheral driver. More...

Modules

 UARTE peripheral driver configuration
 
 Flags used for @ref nrfx_uarte_rx_enable.
 
 Flags used for @ref nrfx_uarte_tx.
 
 Flags used for @ref nrfx_uarte_tx_evt_t.
 

Data Structures

struct  nrfx_uarte_t
 Structure for the UARTE driver instance. More...
 
struct  nrfx_uarte_rx_cache_t
 Structure used internally to handle reception through cache buffers. More...
 
struct  nrfx_uarte_config_t
 Structure for the UARTE configuration. More...
 
struct  nrfx_uarte_rx_evt_t
 Structure for NRFX_UARTE_EVT_RX_DONE event. More...
 
struct  nrfx_uarte_tx_evt_t
 Structure for the NRFX_UARTE_EVT_TX_DONE event. More...
 
struct  nrfx_uarte_error_evt_t
 Structure for the NRFX_UARTE_EVT_ERROR. More...
 
struct  nrfx_uarte_rx_disabled_evt_t
 Structure for the NRFX_UARTE_EVT_RX_DISABLED. More...
 
struct  nrfx_uarte_event_t
 Structure for UARTE event. More...
 

Macros

#define NRFX_UARTE_INSTANCE(id)
 Macro for creating a UARTE driver instance.
 
#define NRFX_UARTE_DEFAULT_CONFIG(_pin_tx, _pin_rx)
 UARTE driver default configuration.
 
#define NRFX_UARTE_INST_HANDLER_GET(idx)   NRFX_CONCAT_3(nrfx_uarte_, idx, _irq_handler)
 Macro returning UARTE interrupt handler.
 

Typedefs

typedef void(* nrfx_uarte_event_handler_t) (nrfx_uarte_event_t const *p_event, void *p_context)
 UARTE interrupt event handler.
 

Enumerations

enum  nrfx_uarte_evt_type_t {
  NRFX_UARTE_EVT_TX_DONE ,
  NRFX_UARTE_EVT_RX_DONE ,
  NRFX_UARTE_EVT_ERROR ,
  NRFX_UARTE_EVT_RX_BUF_REQUEST ,
  NRFX_UARTE_EVT_RX_DISABLED ,
  NRFX_UARTE_EVT_RX_BUF_TOO_LATE ,
  NRFX_UARTE_EVT_RX_BYTE ,
  NRFX_UARTE_EVT_TRIGGER
}
 Types of UARTE driver events. More...
 

Functions

nrfx_err_t nrfx_uarte_init (nrfx_uarte_t const *p_instance, nrfx_uarte_config_t const *p_config, nrfx_uarte_event_handler_t event_handler)
 Function for initializing the UARTE driver.
 
nrfx_err_t nrfx_uarte_reconfigure (nrfx_uarte_t const *p_instance, nrfx_uarte_config_t const *p_config)
 Function for reconfiguring the UARTE driver.
 
void nrfx_uarte_uninit (nrfx_uarte_t const *p_instance)
 Function for uninitializing the UARTE driver.
 
bool nrfx_uarte_init_check (nrfx_uarte_t const *p_instance)
 Function for checking if the UARTE driver instance is initialized.
 
NRFX_STATIC_INLINE uint32_t nrfx_uarte_task_address_get (nrfx_uarte_t const *p_instance, nrf_uarte_task_t task)
 Function for getting the address of the specified UARTE task.
 
NRFX_STATIC_INLINE uint32_t nrfx_uarte_event_address_get (nrfx_uarte_t const *p_instance, nrf_uarte_event_t event)
 Function for getting the address of the specified UARTE event.
 
nrfx_err_t nrfx_uarte_tx (nrfx_uarte_t const *p_instance, uint8_t const *p_data, size_t length, uint32_t flags)
 Function for sending data over UARTE.
 
bool nrfx_uarte_tx_in_progress (nrfx_uarte_t const *p_instance)
 Function for checking if UARTE is currently transmitting.
 
nrfx_err_t nrfx_uarte_tx_abort (nrfx_uarte_t const *p_instance, bool sync)
 Function for aborting any ongoing transmission.
 
nrfx_err_t nrfx_uarte_rx_enable (nrfx_uarte_t const *p_instance, uint32_t flags)
 Function for enabling the receiver.
 
nrfx_err_t nrfx_uarte_rx_buffer_set (nrfx_uarte_t const *p_instance, uint8_t *p_data, size_t length)
 Function for providing reception buffer.
 
nrfx_err_t nrfx_uarte_rx (nrfx_uarte_t const *p_instance, uint8_t *p_data, size_t length)
 Function for receiving data over UARTE.
 
nrfx_err_t nrfx_uarte_rx_ready (nrfx_uarte_t const *p_instance, size_t *p_rx_amount)
 Function for testing the receiver state in blocking mode.
 
nrfx_err_t nrfx_uarte_rx_abort (nrfx_uarte_t const *p_instance, bool disable_all, bool sync)
 Function for aborting any ongoing reception.
 
uint32_t nrfx_uarte_errorsrc_get (nrfx_uarte_t const *p_instance)
 Function for reading error source mask.
 
bool nrfx_uarte_rx_new_data_check (nrfx_uarte_t const *p_instance)
 Function for checking if there was new RX data since the last check.
 
NRFX_STATIC_INLINE void nrfx_uarte_rxdrdy_enable (nrfx_uarte_t const *p_instance)
 Function for enabling NRFX_UARTE_EVT_RX_BYTE event.
 
NRFX_STATIC_INLINE void nrfx_uarte_rxdrdy_disable (nrfx_uarte_t const *p_instance)
 Function for disabling NRFX_UARTE_EVT_RX_BYTE event.
 
nrfx_err_t nrfx_uarte_int_trigger (nrfx_uarte_t const *p_instance)
 Function for triggering UARTE interrupt.
 

Detailed Description

UARTE peripheral driver.

Macro Definition Documentation

◆ NRFX_UARTE_DEFAULT_CONFIG

#define NRFX_UARTE_DEFAULT_CONFIG (   _pin_tx,
  _pin_rx 
)

UARTE driver default configuration.

This configuration sets up UARTE with the following options:

  • hardware flow control disabled
  • no parity bit
  • one stop bit
  • baudrate: 115200
Parameters
[in]_pin_txTX pin.
[in]_pin_rxRX pin.

◆ NRFX_UARTE_INST_HANDLER_GET

#define NRFX_UARTE_INST_HANDLER_GET (   idx)    NRFX_CONCAT_3(nrfx_uarte_, idx, _irq_handler)

Macro returning UARTE interrupt handler.

param[in] idx UARTE index.

Returns
Interrupt handler.

◆ NRFX_UARTE_INSTANCE

#define NRFX_UARTE_INSTANCE (   id)
Value:
{ \
.p_reg = NRFX_CONCAT_2(NRF_UARTE, id), \
.drv_inst_idx = NRFX_CONCAT_3(NRFX_UARTE, id, _INST_IDX), \
}
#define NRFX_CONCAT_2(p1, p2)
Macro for concatenating two tokens in macro expansion.
Definition: nrfx_common.h:134
#define NRFX_CONCAT_3(p1, p2, p3)
Macro for concatenating three tokens in macro expansion.
Definition: nrfx_common.h:155

Macro for creating a UARTE driver instance.

Typedef Documentation

◆ nrfx_uarte_event_handler_t

typedef void(* nrfx_uarte_event_handler_t) (nrfx_uarte_event_t const *p_event, void *p_context)

UARTE interrupt event handler.

Parameters
[in]p_eventPointer to event structure. Event is allocated on the stack so it is available only within the context of the event handler.
[in]p_contextContext passed to the interrupt handler, set on initialization.

Enumeration Type Documentation

◆ nrfx_uarte_evt_type_t

Types of UARTE driver events.

Enumerator
NRFX_UARTE_EVT_TX_DONE 

Requested TX transfer completed.

NRFX_UARTE_EVT_RX_DONE 

Requested RX transfer completed.

NRFX_UARTE_EVT_ERROR 

Error reported by UART peripheral.

NRFX_UARTE_EVT_RX_BUF_REQUEST 

Request for a RX buffer.

NRFX_UARTE_EVT_RX_DISABLED 

Receiver is disabled.

NRFX_UARTE_EVT_RX_BUF_TOO_LATE 

RX buffer request handled too late.

NRFX_UARTE_EVT_RX_BYTE 

Byte was received.

NRFX_UARTE_EVT_TRIGGER 

Result of nrfx_uarte_int_trigger.

Function Documentation

◆ nrfx_uarte_errorsrc_get()

uint32_t nrfx_uarte_errorsrc_get ( nrfx_uarte_t const *  p_instance)

Function for reading error source mask.

Mask contains values from nrf_uarte_error_mask_t.

Note
Function must be used in the blocking mode only. In case of non-blocking mode, an error event is generated. Function clears error sources after reading.
Parameters
[in]p_instancePointer to the driver instance structure.
Returns
Mask of reported errors.

◆ nrfx_uarte_event_address_get()

NRFX_STATIC_INLINE uint32_t nrfx_uarte_event_address_get ( nrfx_uarte_t const *  p_instance,
nrf_uarte_event_t  event 
)

Function for getting the address of the specified UARTE event.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]eventEvent.
Returns
Event address.

◆ nrfx_uarte_init()

nrfx_err_t nrfx_uarte_init ( nrfx_uarte_t const *  p_instance,
nrfx_uarte_config_t const *  p_config,
nrfx_uarte_event_handler_t  event_handler 
)

Function for initializing the UARTE driver.

This function configures UARTE but peripheral is kept disabled to reduce power consumption.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the initial configuration.
[in]event_handlerEvent handler provided by the user. If not provided driver works in blocking mode.
Return values
NRFX_SUCCESSInitialization was successful.
NRFX_ERROR_ALREADYThe driver is already initialized.
NRFX_ERROR_INVALID_STATEThe driver is already initialized. Deprecated - use NRFX_ERROR_ALREADY instead.
NRFX_ERROR_INVALID_PARAMInvalid configuration.
NRFX_ERROR_BUSYSome other peripheral with the same instance ID is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled.

◆ nrfx_uarte_init_check()

bool nrfx_uarte_init_check ( nrfx_uarte_t const *  p_instance)

Function for checking if the UARTE driver instance is initialized.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueInstance is already initialized.
falseInstance is not initialized.

◆ nrfx_uarte_int_trigger()

nrfx_err_t nrfx_uarte_int_trigger ( nrfx_uarte_t const *  p_instance)

Function for triggering UARTE interrupt.

Function can be used to jump into UARTE interrupt context. User handler is called with the event NRFX_UARTE_EVT_TRIGGER.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
NRFX_ERROR_FORBIDDENFailure. User handler is not configured.
NRFX_SUCCESSIf interrupt is successfully triggered.

◆ nrfx_uarte_reconfigure()

nrfx_err_t nrfx_uarte_reconfigure ( nrfx_uarte_t const *  p_instance,
nrfx_uarte_config_t const *  p_config 
)

Function for reconfiguring the UARTE driver.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_configPointer to the structure with the configuration.
Return values
NRFX_SUCCESSReconfiguration was successful.
NRFX_ERROR_BUSYThe driver is during transfer.
NRFX_ERROR_INVALID_STATEThe driver is uninitialized.

◆ nrfx_uarte_rx()

nrfx_err_t nrfx_uarte_rx ( nrfx_uarte_t const *  p_instance,
uint8_t *  p_data,
size_t  length 
)

Function for receiving data over UARTE.

If an event handler is provided in the nrfx_uarte_init() call, this function returns immediately and the handler is called when the transfer is done. Otherwise, the transfer is performed in blocking mode, that is this function returns when the transfer is finished. Blocking mode is not using interrupt so there is no context switching inside the function. The receive buffer pointer is double-buffered in non-blocking mode. The secondary buffer can be set immediately after starting the transfer and will be filled when the primary buffer is full. The double-buffering feature allows receiving data continuously.

Note
Peripherals using EasyDMA (including UARTE) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function fails with the error code NRFX_ERROR_INVALID_ADDR.
Warning
When the double-buffering feature is used and the UARTE interrupt is processed with a delay (for example, due to a higher priority interrupt) long enough for both buffers to get filled completely, the event handler will be invoked only once, to notify that the first buffer has been filled. This is because from hardware perspective it is impossible to deduce in such case if the second buffer was also filled completely or not. To prevent this from happening, keep the UARTE interrupt latency low or use large enough reception buffers.
Deprecated:
Use nrfx_uarte_rx_enable and nrfx_uarte_rx_buffer_set.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_dataPointer to data.
[in]lengthNumber of bytes to receive. Maximum possible length is dependent on the used SoC (see the MAXCNT register description in the Product Specification). The driver checks it with assertion.
Return values
NRFX_SUCCESSInitialization is successful.
NRFX_ERROR_BUSYThe driver is already receiving (and the secondary buffer has already been set in non-blocking mode).
NRFX_ERROR_FORBIDDENThe transfer is aborted from a different context (blocking mode only).
NRFX_ERROR_INTERNALThe UARTE peripheral reports an error.
NRFX_ERROR_INVALID_ADDRp_data does not point to RAM buffer.

◆ nrfx_uarte_rx_abort()

nrfx_err_t nrfx_uarte_rx_abort ( nrfx_uarte_t const *  p_instance,
bool  disable_all,
bool  sync 
)

Function for aborting any ongoing reception.

Note
NRFX_UARTE_EVT_RX_DONE event will be generated in non-blocking mode. It will contain number of bytes received until the abort was called. The event handler will be called from the UARTE interrupt context.
Warning
When the double-buffering feature is used and the UARTE interrupt is processed with a delay (for example, due to a higher priority interrupt) long enough for the first buffer to be filled completely, the event handler will be supplied with the pointer to the first buffer and the number of bytes received in the second buffer. This is because from hardware perspective it is impossible to deduce the reception of which buffer has been aborted. To prevent this from happening, keep the UARTE interrupt latency low or use large enough reception buffers.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]disable_allIf true, UARTE is stopped. If false and there is a second RX buffer provided, only the first transfer is stopped.
[in]syncIf true, receiver is disabled synchronously.
Return values
NRFX_SUCCESSSuccessfully initiate disabling or disabled (synchronous mode).
NRFX_ERROR_INVALID_STATEReceiver was not enabled.

◆ nrfx_uarte_rx_buffer_set()

nrfx_err_t nrfx_uarte_rx_buffer_set ( nrfx_uarte_t const *  p_instance,
uint8_t *  p_data,
size_t  length 
)

Function for providing reception buffer.

The function should be called as a response to the NRFX_UARTE_EVT_RX_BUF_REQUEST event. If the function is called before enabling the receiver, the first buffer is configured. If the function is called and there is no active buffer but the receiver is enabled but not started, it starts reception.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_dataPointer to a buffer.
[in]lengthBuffer length.
Return values
NRFX_SUCCESSBuffer successfully set.
NRFX_ERROR_INVALID_STATEBuffer provided without pending request.
NRFX_ERROR_TIMEOUTBuffer provided too late. Receiver is being disabled.

◆ nrfx_uarte_rx_enable()

nrfx_err_t nrfx_uarte_rx_enable ( nrfx_uarte_t const *  p_instance,
uint32_t  flags 
)

Function for enabling the receiver.

The event handler will be called from the caller context with the NRFX_UARTE_EVT_RX_BUF_REQUEST event. The user may respond and provide a buffer using nrfx_uarte_rx_buffer_set. An error is returned if buffer is not provided. After that, the receiver is started and another NRFX_UARTE_EVT_RX_BUF_REQUEST is generated. If a new buffer is not provided, then the receiver is disabled once the first buffer becomes full. If a new buffer is provided, then the receiver will seamlessly switch to a new buffer (using a hardware shortcut).

Note
If transmitter is inactive then peripheral is disabled after receiver is stopped to achieve the lowest power consumption.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]flagsOption flags. See Flags used for nrfx_uarte_rx_enable..
Return values
NRFX_SUCCESSReceiver successfully enabled.
NRFX_ERROR_BUSYWhen receiver is already enabled.
NRFX_ERROR_NO_MEMWhen buffer was not provided.

◆ nrfx_uarte_rx_new_data_check()

bool nrfx_uarte_rx_new_data_check ( nrfx_uarte_t const *  p_instance)

Function for checking if there was new RX data since the last check.

Function checks NRF_UARTE_EVENT_RXDRDY event and clears it if it was set.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueAt least one byte was received since the last check.
falseNo new data was received since the last check.

◆ nrfx_uarte_rx_ready()

nrfx_err_t nrfx_uarte_rx_ready ( nrfx_uarte_t const *  p_instance,
size_t *  p_rx_amount 
)

Function for testing the receiver state in blocking mode.

Parameters
[in]p_instancePointer to the driver instance structure.
[out]p_rx_amountPointer to the variable to be filled with the number of received bytes. Can be NULL.
Return values
NRFX_SUCCESSThe receiving operation is completed.
NRFX_ERROR_BUSYThe receiver did not complete the operation.
NRFX_ERROR_FORBIDDENOperation is not supporting in the current configuration.

◆ nrfx_uarte_rxdrdy_disable()

NRFX_STATIC_INLINE void nrfx_uarte_rxdrdy_disable ( nrfx_uarte_t const *  p_instance)

Function for disabling NRFX_UARTE_EVT_RX_BYTE event.

The function disables the RXDRDY hardware event. See the nrfx_uarte_rxdrdy_enable for more details. The event can be disabled at any time.

Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_uarte_rxdrdy_enable()

NRFX_STATIC_INLINE void nrfx_uarte_rxdrdy_enable ( nrfx_uarte_t const *  p_instance)

Function for enabling NRFX_UARTE_EVT_RX_BYTE event.

The function enables the NRF_UARTE_EVENT_RXDRDY hardware event which is generated whenever a byte is received in RXD registers. The event indicates only that data is received, hence it must not be used yet because it may not be present yet in the RAM buffer handled by the EasyDMA. The event can be used only to detect a receiver activity. The event can be enabled at any time. Enabling it may increase the number of interrupts (after each received byte).

Note
If there were a receiver activity prior to enabling the NRF_UARTE_EVENT_RXDRDY event, the NRF_UARTE_EVENT_RXDRDY event may already be set and the NRFX_UARTE_EVT_RX_BYTE will be triggered immediately. To avoid that, it is recommended to clear that event by calling the nrfx_uarte_rx_new_data_check.
Parameters
[in]p_instancePointer to the driver instance structure.

◆ nrfx_uarte_task_address_get()

NRFX_STATIC_INLINE uint32_t nrfx_uarte_task_address_get ( nrfx_uarte_t const *  p_instance,
nrf_uarte_task_t  task 
)

Function for getting the address of the specified UARTE task.

Parameters
[in]p_instancePointer to the driver instance structure.
[in]taskTask.
Returns
Task address.

◆ nrfx_uarte_tx()

nrfx_err_t nrfx_uarte_tx ( nrfx_uarte_t const *  p_instance,
uint8_t const *  p_data,
size_t  length,
uint32_t  flags 
)

Function for sending data over UARTE.

If an event handler is provided in nrfx_uarte_init() call, this function returns immediately (unless special flags are used) and the handler is called when the transfer is done. Otherwise, the transfer is performed in blocking mode, that is, this function returns when the transfer is finished.

Note
Peripherals using EasyDMA (including UARTE) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function will attempt to use the cache buffer provided in the configuration and if it is not available it will return error.
To achieve the lowest power consumption, transmitter is stopped and peripheral is disabled (if receiver is not used) when transfer is completed.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_dataPointer to data.
[in]lengthNumber of bytes to send. Maximum possible length is dependent on the used SoC (see the MAXCNT register description in the Product Specification). The driver checks it with assertion.
[in]flagsOption flags. See Flags used for nrfx_uarte_tx..
Return values
NRFX_SUCCESSInitialization was successful.
NRFX_ERROR_BUSYDriver is busy transferring the data.
NRFX_ERROR_FORBIDDENThe transfer was aborted from a different context (blocking mode only) or transfer cannot be performed due to driver state, configuration or transfer parameters.
NRFX_ERROR_INVALID_ADDRp_data does not point to RAM buffer and cache buffer is not provided or attempted to use non DMA buffer with linked transfer (see NRFX_UARTE_TX_LINK).
NRFX_ERROR_INVALID_LENGTHFlag NRFX_UARTE_TX_EARLY_RETURN is used but length exceeds internal buffer size.

◆ nrfx_uarte_tx_abort()

nrfx_err_t nrfx_uarte_tx_abort ( nrfx_uarte_t const *  p_instance,
bool  sync 
)

Function for aborting any ongoing transmission.

Note
When abortion is not synchronous, the NRFX_UARTE_EVT_TX_DONE event will be generated in non-blocking mode. It will contain the number of bytes sent until the abort was called. If NRFX_UARTE_TX_LINK flag was used for the transfer and linked transfer have not started yet, there will be the second NRFX_UARTE_EVT_TX_DONE event with length equal to 0. The event handler will be called from the UARTE interrupt context.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]syncIf true operation is synchronous. Transmitter is stopped upon function return and no event is generated.
Return values
NRFX_SUCCESSSuccessfully initiated abort or when transmitter synchronously stopped.
NRFX_ERROR_INVALID_STATEAttempt to asynchronously abort when no transfer is active.

◆ nrfx_uarte_tx_in_progress()

bool nrfx_uarte_tx_in_progress ( nrfx_uarte_t const *  p_instance)

Function for checking if UARTE is currently transmitting.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueThe UARTE is transmitting.
falseThe UARTE is not transmitting.

◆ nrfx_uarte_uninit()

void nrfx_uarte_uninit ( nrfx_uarte_t const *  p_instance)

Function for uninitializing the UARTE driver.

Parameters
[in]p_instancePointer to the driver instance structure.

Documentation feedback | Developer Zone | Subscribe | Updated