Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Universal Asynchronous Receiver Transceiver (UART)

The Universal Asynchronous Receiver Transmitter features a two-pin UART that can be used for communication and trace purposes and offers an ideal medium for in-situ programming solutions.

Moreover, the association with two peripheral DMA controller (PDC) channels permits packet handling for these tasks with processor time reduced to a minimum.

Usage
  1. Enable the UART peripheral clock in the PMC.
  2. Enable the required UART PIOs (see pio.h).
  3. Configure the UART by calling uart_init.
  4. Send data through the UART using the uart_write.
  5. Receive data from the UART using the uart_read; the availability of data can be polled with uart_is_rx_ready.
  6. Disable the transmitter and/or the receiver of the UART with uart_disable_tx and uart_disable_rx.

Functions

void uart_disable (Uart *p_uart)
 Disable UART receiver and transmitter. More...
 
void uart_disable_interrupt (Uart *p_uart, uint32_t ul_sources)
 Disable UART interrupts. More...
 
void uart_disable_rx (Uart *p_uart)
 Disable UART receiver. More...
 
void uart_disable_tx (Uart *p_uart)
 Disable UART transmitter. More...
 
void uart_enable (Uart *p_uart)
 Enable UART receiver and transmitter. More...
 
void uart_enable_interrupt (Uart *p_uart, uint32_t ul_sources)
 Enable UART interrupts. More...
 
void uart_enable_rx (Uart *p_uart)
 Enable UART receiver. More...
 
void uart_enable_tx (Uart *p_uart)
 Enable UART transmitter. More...
 
uint32_t uart_get_interrupt_mask (Uart *p_uart)
 Read UART interrupt mask. More...
 
Pdc * uart_get_pdc_base (Uart *p_uart)
 Get UART PDC base address. More...
 
uint32_t uart_get_status (Uart *p_uart)
 Get current status. More...
 
uint32_t uart_init (Uart *p_uart, const sam_uart_opt_t *p_uart_opt)
 Configure UART with the specified parameters. More...
 
uint32_t uart_is_rx_buf_end (Uart *p_uart)
 Check if one receive buffer is filled. More...
 
uint32_t uart_is_rx_buf_full (Uart *p_uart)
 Check if both receive buffers are full. More...
 
uint32_t uart_is_rx_ready (Uart *p_uart)
 Check if Received data is ready. More...
 
uint32_t uart_is_tx_buf_empty (Uart *p_uart)
 Check if both transmit buffers are sent out. More...
 
uint32_t uart_is_tx_buf_end (Uart *p_uart)
 Check if one transmit buffer is sent out. More...
 
uint32_t uart_is_tx_empty (Uart *p_uart)
 Check if Transmit Hold Register is empty. More...
 
uint32_t uart_is_tx_ready (Uart *p_uart)
 Check if Transmit is Ready. More...
 
uint32_t uart_read (Uart *p_uart, uint8_t *puc_data)
 Read from UART Receive Holding Register. More...
 
void uart_reset (Uart *p_uart)
 Reset UART receiver and transmitter. More...
 
void uart_reset_rx (Uart *p_uart)
 Reset UART receiver. More...
 
void uart_reset_status (Uart *p_uart)
 Reset status bits. More...
 
void uart_reset_tx (Uart *p_uart)
 Reset UART transmitter. More...
 
void uart_set_clock_divisor (Uart *p_uart, uint16_t us_divisor)
 Set UART clock divisor value. More...
 
uint32_t uart_write (Uart *p_uart, const uint8_t uc_data)
 Write to UART Transmit Holding Register Before writing user should check if tx is ready (or empty). More...
 

void uart_disable ( Uart *  p_uart)

Disable UART receiver and transmitter.

Parameters
p_uartPointer to a UART instance.

Referenced by buart_if_close().

void uart_disable_interrupt ( Uart *  p_uart,
uint32_t  ul_sources 
)

Disable UART interrupts.

Parameters
p_uartPointer to a UART instance.
ul_sourcesInterrupts to be disabled.

Referenced by buart_if_close(), buart_if_open(), configure_console(), configure_rx_dma(), freertos_uart_serial_init(), local_uart_handler(), and SB_UART_Handler().

void uart_disable_rx ( Uart *  p_uart)

Disable UART receiver.

Parameters
p_uartPointer to a UART instance.

Referenced by freertos_uart_serial_init().

void uart_disable_tx ( Uart *  p_uart)

Disable UART transmitter.

Parameters
p_uartPointer to a UART instance.

Referenced by freertos_uart_serial_init().

void uart_enable ( Uart *  p_uart)

Enable UART receiver and transmitter.

Parameters
p_uartPointer to a UART instance.

Referenced by usart_stream_reset().

void uart_enable_interrupt ( Uart *  p_uart,
uint32_t  ul_sources 
)

Enable UART interrupts.

Parameters
p_uartPointer to a UART instance.
ul_sourcesInterrupts to be enabled.

Referenced by buart_if_open(), configure_console(), configure_rx_dma(), freertos_uart_serial_init(), freertos_uart_write_packet_async(), main(), serial_bridge_init(), and serial_bridge_task().

void uart_enable_rx ( Uart *  p_uart)

Enable UART receiver.

Parameters
p_uartPointer to a UART instance.

Referenced by buart_if_open(), configure_console(), and freertos_uart_serial_init().

void uart_enable_tx ( Uart *  p_uart)

Enable UART transmitter.

Parameters
p_uartPointer to a UART instance.

Referenced by buart_if_open(), configure_console(), and freertos_uart_serial_init().

uint32_t uart_get_interrupt_mask ( Uart *  p_uart)

Read UART interrupt mask.

Parameters
p_uartPointer to a UART instance.
Returns
The interrupt mask value.

Referenced by local_uart_handler().

Pdc* uart_get_pdc_base ( Uart *  p_uart)

Get UART PDC base address.

Parameters
p_uartPointer to a UART instance.
Returns
UART PDC registers base for PDC driver to access.

Referenced by buart_if_open(), and main().

uint32_t uart_get_status ( Uart *  p_uart)

Get current status.

Parameters
p_uartPointer to a UART instance.
Returns
The current UART status.

Referenced by local_uart_handler(), and UART_Handler().

uint32_t uart_init ( Uart *  p_uart,
const sam_uart_opt_t p_uart_opt 
)

Configure UART with the specified parameters.

Note
The PMC and PIOs must be configured first.
Parameters
p_uartPointer to a UART instance.
p_uart_optPointer to sam_uart_opt_t instance.
Return values
0Success.
1Bad baud rate generator value.

References UART_MCK_DIV, UART_MCK_DIV_MAX_FACTOR, sam_uart_opt::ul_baudrate, sam_uart_opt::ul_mck, and sam_uart_opt::ul_mode.

Referenced by buart_if_open(), config_uart_and_pck(), freertos_uart_serial_init(), reconfigure_console(), serial_bridge_init(), and usart_serial_init().

uint32_t uart_is_rx_buf_end ( Uart *  p_uart)

Check if one receive buffer is filled.

Parameters
p_uartPointer to a UART instance.
Return values
1Receive is completed.
0Receive is still pending.
uint32_t uart_is_rx_buf_full ( Uart *  p_uart)

Check if both receive buffers are full.

Parameters
p_uartPointer to a UART instance.
Return values
1Receive buffers are full.
0Receive buffers are not full.
uint32_t uart_is_rx_ready ( Uart *  p_uart)

Check if Received data is ready.

Check if data has been received and loaded in UART_RHR.

Parameters
p_uartPointer to a UART instance.
Return values
1One data has been received.
0No data has been received.

Referenced by atCmd_PsMode_Handler(), SB_UART_Handler(), and usart_serial_is_rx_ready().

uint32_t uart_is_tx_buf_empty ( Uart *  p_uart)

Check if both transmit buffers are sent out.

Parameters
p_uartPointer to a UART instance.
Return values
1Transmit buffer is empty.
0Transmit buffer is not empty.

Referenced by bt_usart_stream_write_buffer(), buffered_uart_putchar(), usart_stream_write(), and wait_for_message_gone().

uint32_t uart_is_tx_buf_end ( Uart *  p_uart)

Check if one transmit buffer is sent out.

Parameters
p_uartPointer to a UART instance.
Return values
1Transmit is completed.
0Transmit is still pending.
uint32_t uart_is_tx_empty ( Uart *  p_uart)

Check if Transmit Hold Register is empty.

Check if the last data written in UART_THR has been loaded in TSR and the last data loaded in TSR has been transmitted.

Parameters
p_uartPointer to a UART instance.
Return values
1Transmitter is empty.
0Transmitter is not empty.

Referenced by init_chip(), is_serial_output_done(), main(), SB_UART_Handler(), test_backup_mode(), test_wait_mode(), and user_change_clock().

uint32_t uart_is_tx_ready ( Uart *  p_uart)

Check if Transmit is Ready.

Check if data has been loaded in UART_THR and is waiting to be loaded in the Transmit Shift Register (TSR).

Parameters
p_uartPointer to a UART instance.
Return values
1Data has been transmitted.
0Transmit is not ready, data pending.
void uart_reset ( Uart *  p_uart)

Reset UART receiver and transmitter.

Parameters
p_uartPointer to a UART instance.

Referenced by usart_stream_reset().

void uart_reset_rx ( Uart *  p_uart)

Reset UART receiver.

Parameters
p_uartPointer to a UART instance.
void uart_reset_status ( Uart *  p_uart)

Reset status bits.

Parameters
p_uartPointer to a UART instance.

Referenced by local_uart_handler().

void uart_reset_tx ( Uart *  p_uart)

Reset UART transmitter.

Parameters
p_uartPointer to a UART instance.
void uart_set_clock_divisor ( Uart *  p_uart,
uint16_t  us_divisor 
)

Set UART clock divisor value.

Parameters
p_uartPointer to a UART instance.
us_divisorValue to be set.
uint32_t uart_write ( Uart *  p_uart,
const uint8_t  uc_data 
)

Write to UART Transmit Holding Register Before writing user should check if tx is ready (or empty).

Parameters
p_uartPointer to a UART instance.
dataData to be sent.
Return values
0Success.
1I/O Failure, UART is not ready.

Referenced by SB_UART_Handler(), serial_bridge_task(), and usart_serial_putchar().