microHAL
An abstraction layer for your future F4xx projects
Loading...
Searching...
No Matches
usart.c File Reference

Function defines for the USART driver. More...

#include "usart.h"

Functions

void usart_start (const usart_peripheral_t usart, const uint32_t baudrate, const usart_mode_t mode)
 Initiates the USART peripheral with specified options.
 
void usart_set_dma (const usart_peripheral_t usart, const _Bool forTX, const _Bool forRX)
 Configures the USART DMA functionality.
 
void usart_set_interrupts (const usart_peripheral_t usart, const struct USARTISR config)
 Enables the specified USART interrupts.
 
void usart_set_databits (const usart_peripheral_t usart, const usart_stopbits_t stopbits, const usart_databits_t databits)
 Sets the USART databits to the specified values.
 
void usart_set_parity (const usart_peripheral_t usart, const usart_parity_t parity)
 Sets the USART parity to the specified mode.
 
void usart_tx_message (const usart_peripheral_t usart, const char *message)
 Writes specified message to USART buffer.
 
uint16_t usart_rx_byte (const usart_peripheral_t usart)
 Reads the received data from the USART buffer.
 
void usart_stop (const usart_peripheral_t usart)
 Disable the USART interface.
 

Detailed Description

Function defines for the USART driver.

This file contains all of the function definitions declared in usart.h.

Author
Vasileios Ch. (BillisC)
Bug
None, yet.

Function Documentation

◆ usart_rx_byte()

uint16_t usart_rx_byte ( const usart_peripheral_t usart)

Reads the received data from the USART buffer.

In receive/transceive mode the data will be read from the DR register and the RXNE flag will be cleared. Beware that this method is very slow and may cause overrun errors if not used in conjuction with interrupts.

Parameters
usartThe selected USART
Returns
The received data

◆ usart_set_databits()

void usart_set_databits ( const usart_peripheral_t usart,
const usart_stopbits_t stopbits,
const usart_databits_t databits )

Sets the USART databits to the specified values.

The available number of stopbits and databits for the USART are specified in usart_stopbits_t and usart_databits_t enums respectively. Any other value will be ignored.

Parameters
usartThe selected USART
stopbitsThe number of stop bits
databitsThe word length
Returns
None

◆ usart_set_dma()

void usart_set_dma ( const usart_peripheral_t usart,
const _Bool forTX,
const _Bool forRX )

Configures the USART DMA functionality.

Parameters
usartThe selected USART
forTXEnable / Disable DMA for TX
forTXEnable / Disable DMA for RX
Returns
None

◆ usart_set_interrupts()

void usart_set_interrupts ( const usart_peripheral_t usart,
const struct USARTISR config )

Enables the specified USART interrupts.

The available interrupts are located in the usart_isr struct.

Parameters
usartThe selected USART
configThe ISR configuration
Returns
None

◆ usart_set_parity()

void usart_set_parity ( const usart_peripheral_t usart,
const usart_parity_t parity )

Sets the USART parity to the specified mode.

The available parity modes for the USART are specified in usart_parity_t. Any other value will be ignored. Please note that setting the parity modes will automatically set the PCE (parity control) bit. If the mode is "off" it will be cleared.

Parameters
usartThe selected USART
parityThe selected parity
Returns
None

◆ usart_start()

void usart_start ( const usart_peripheral_t usart,
const uint32_t baudrate,
const usart_mode_t mode )

Initiates the USART peripheral with specified options.

The available modes for the USART peripheral are specified in the usart_mode_t enum. Any other value will be ignored.

Parameters
usartThe selected USART
baudrateThe desired communication bitrate
modeThe desired communication mode
x8_oversampleUse x8 oversampling instead of x16
Returns
None

◆ usart_stop()

void usart_stop ( const usart_peripheral_t usart)

Disable the USART interface.

The function will wait until all transmissions are complete and turn off the specified USART peripheral.

Parameters
usartThe selected USART
Returns
None

◆ usart_tx_message()

void usart_tx_message ( const usart_peripheral_t usart,
const char * message )

Writes specified message to USART buffer.

In transmit/transceive mode the data will be written to the DR register and be shifted out of the TX pin when ready. Using it without DMA is not recommended for multibyte messages.

Parameters
usartThe selected USART
characterPointer to the message
Returns
None