See Quick start guide for USART module.
This is a driver for configuring, enabling, disabling and use of the on-chip USART.
The USART module depends on the following modules:
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the USART module (USART). | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the USART module (USART). | |
Data Structures | |
struct | usart_rs232_options |
Input parameters when initializing RS232 and similar modes. More... | |
struct | usart_spi_options |
Input parameters when initializing SPI master mode. More... | |
Macros | |
#define | USART_BAUD_1200 0x00 |
Offset in lookup table for baudrate 1200. More... | |
#define | USART_BAUD_19200 0x04 |
Offset in lookup table for baudrate 19200. More... | |
#define | USART_BAUD_2400 0x01 |
Offset in lookup table for baudrate 2400. More... | |
#define | USART_BAUD_38400 0x05 |
Offset in lookup table for baudrate 38400. More... | |
#define | USART_BAUD_4800 0x02 |
Offset in lookup table for baudrate 4800. More... | |
#define | USART_BAUD_57600 0x06 |
Offset in lookup table for baudrate 57600. More... | |
#define | USART_BAUD_9600 0x03 |
Offset in lookup table for baudrate 9600. More... | |
#define | USART_BAUD_UNDEFINED 0xFF |
Baudrate not in lookup table. More... | |
Typedefs | |
typedef struct usart_rs232_options | usart_rs232_options_t |
Input parameters when initializing RS232 and similar modes. More... | |
typedef struct usart_spi_options | usart_spi_options_t |
Input parameters when initializing SPI master mode. More... | |
Enumerations | |
enum | usart_int_level_t { USART_INT_LVL_OFF = 0x00, USART_INT_LVL_LO = 0x01, USART_INT_LVL_MED = 0x02, USART_INT_LVL_HI = 0x03 } |
USART interrupt levels. More... | |
Functions | |
static | PROGMEM_DECLARE (uint16_t, baudctrl_2mhz[]) |
Lookup table containing baudctrl values for CPU frequency 2 Mhz. More... | |
static | PROGMEM_DECLARE (uint16_t, baudctrl_32mhz[]) |
Lookup table containing baudctrl values for CPU frequency 32 Mhz. More... | |
static void | usart_clear_rx_complete (USART_t *usart) |
Clear RX complete interrupt flag. More... | |
static void | usart_clear_tx_complete (USART_t *usart) |
Clear TX complete interrupt flag. More... | |
static bool | usart_data_register_is_empty (USART_t *usart) |
Check if data register empty flag is set. More... | |
static void | usart_format_set (USART_t *usart, USART_CHSIZE_t charSize, USART_PMODE_t parityMode, bool twoStopBits) |
Configure the USART frame format. More... | |
static uint8_t | usart_get (USART_t *usart) |
Read a data to the USART data register. More... | |
uint8_t | usart_getchar (USART_t *usart) |
Receive a data with the USART module. More... | |
bool | usart_init_rs232 (USART_t *usart, const usart_rs232_options_t *opt) |
Initialize USART in RS232 mode. More... | |
void | usart_init_spi (USART_t *usart, const usart_spi_options_t *opt) |
Initialize USART in SPI master mode. More... | |
static void | usart_put (USART_t *usart, uint8_t txdata) |
Write a data to the USART data register. More... | |
enum status_code | usart_putchar (USART_t *usart, uint8_t c) |
Send a data with the USART module. More... | |
static void | usart_rx_disable (USART_t *usart) |
Disable USART receiver. More... | |
static void | usart_rx_enable (USART_t *usart) |
Enable USART receiver. More... | |
static bool | usart_rx_is_complete (USART_t *usart) |
Checks if the RX complete interrupt flag is set. More... | |
bool | usart_set_baudrate (USART_t *usart, uint32_t baud, uint32_t cpu_hz) |
Set the baudrate value in the USART module. More... | |
void | usart_set_baudrate_precalculated (USART_t *usart, uint32_t baud, uint32_t cpu_hz) |
Set the baudrate using precalculated BAUDCTRL values from PROGMEM. More... | |
void | usart_set_bsel_bscale_value (USART_t *usart, uint16_t bsel, uint8_t bscale) |
Set the baudrate by setting the BSEL and BSCALE values in the USART. More... | |
static void | usart_set_dre_interrupt_level (USART_t *usart, enum usart_int_level_t level) |
Set USART DRE interrupt level. More... | |
static void | usart_set_mode (USART_t *usart, USART_CMODE_t usartmode) |
Set the mode the USART run in. More... | |
static void | usart_set_rx_interrupt_level (USART_t *usart, enum usart_int_level_t level) |
Set USART RXD interrupt level. More... | |
static void | usart_set_tx_interrupt_level (USART_t *usart, enum usart_int_level_t level) |
Set USART TXD interrupt level. More... | |
void | usart_spi_set_baudrate (USART_t *usart, uint32_t baud, uint32_t cpu_hz) |
Set the baudrate value in the USART_SPI module. More... | |
static uint8_t | usart_spi_transmit (USART_t *usart, uint8_t txdata) |
Performs a data transfer on the USART in SPI mode. More... | |
static void | usart_tx_disable (USART_t *usart) |
Disable USART transmitter. More... | |
static void | usart_tx_enable (USART_t *usart) |
Enable USART transmitter. More... | |
static bool | usart_tx_is_complete (USART_t *usart) |
Checks if the TX complete interrupt flag is set. More... | |
#define USART_BAUD_1200 0x00 |
Offset in lookup table for baudrate 1200.
Referenced by usart_get_baud_offset().
#define USART_BAUD_19200 0x04 |
Offset in lookup table for baudrate 19200.
Referenced by usart_get_baud_offset().
#define USART_BAUD_2400 0x01 |
Offset in lookup table for baudrate 2400.
Referenced by usart_get_baud_offset().
#define USART_BAUD_38400 0x05 |
Offset in lookup table for baudrate 38400.
Referenced by usart_get_baud_offset().
#define USART_BAUD_4800 0x02 |
Offset in lookup table for baudrate 4800.
Referenced by usart_get_baud_offset().
#define USART_BAUD_57600 0x06 |
Offset in lookup table for baudrate 57600.
Referenced by usart_get_baud_offset().
#define USART_BAUD_9600 0x03 |
Offset in lookup table for baudrate 9600.
Referenced by usart_get_baud_offset().
#define USART_BAUD_UNDEFINED 0xFF |
Baudrate not in lookup table.
Referenced by usart_get_baud_offset(), and usart_set_baudrate_precalculated().
typedef struct usart_rs232_options usart_rs232_options_t |
Input parameters when initializing RS232 and similar modes.
typedef struct usart_spi_options usart_spi_options_t |
Input parameters when initializing SPI master mode.
enum usart_int_level_t |
|
static |
Lookup table containing baudctrl values for CPU frequency 2 Mhz.
|
static |
Lookup table containing baudctrl values for CPU frequency 32 Mhz.
|
inlinestatic |
Clear RX complete interrupt flag.
usart | The USART module. |
|
inlinestatic |
Clear TX complete interrupt flag.
usart | The USART module. |
Referenced by configure_sensor_platform(), ili9341_send_byte(), ili9341_wait_for_send_done(), and usart_spi_transmit().
|
inlinestatic |
Check if data register empty flag is set.
usart | The USART module. |
Referenced by ili9341_send_byte(), usart_putchar(), usart_spi_is_tx_empty(), usart_spi_is_tx_ready(), and usart_spi_transmit().
|
inlinestatic |
Configure the USART frame format.
Sets the frame format, Frame Size, parity mode and number of stop bits.
usart | Pointer to the USART module |
charSize | The character size. Use USART_CHSIZE_t type. |
parityMode | The parity Mode. Use USART_PMODE_t type. |
twoStopBits | Enable two stop bit mode. Use bool type. |
Referenced by usart_init_rs232().
|
inlinestatic |
Read a data to the USART data register.
usart | The USART module. |
Referenced by ili9341_read_byte(), and usart_spi_transmit().
uint8_t usart_getchar | ( | USART_t * | usart | ) |
Receive a data with the USART module.
This function returns the received data from the USART module.
usart | The USART module. |
References usart_rx_is_complete().
Referenced by main(), and usart_serial_getchar().
bool usart_init_rs232 | ( | USART_t * | usart, |
const usart_rs232_options_t * | opt | ||
) |
Initialize USART in RS232 mode.
This function initializes the USART module in RS232 mode using the usart_rs232_options_t configuration structure and CPU frequency.
usart | The USART module. |
opt | The RS232 configuration option. |
true | if the initialization was successfull |
false | if the initialization failed (error in baud rate calculation) |
References usart_rs232_options::baudrate, usart_rs232_options::charlength, usart_rs232_options::paritytype, usart_rs232_options::stopbits, sysclk_enable_peripheral_clock(), sysclk_get_per_hz(), usart_format_set(), usart_rx_enable(), usart_set_baudrate(), usart_set_mode(), and usart_tx_enable().
Referenced by main(), and usart_serial_init().
void usart_init_spi | ( | USART_t * | usart, |
const usart_spi_options_t * | opt | ||
) |
Initialize USART in SPI master mode.
This function initializes the USART module in SPI master mode using the usart_spi_options_t configuration structure and CPU frequency.
usart | The USART module. |
opt | The RS232 configuration option. |
References usart_spi_options::baudrate, usart_spi_options::data_order, IOPORT_CREATE_PIN, IOPORT_DIR_OUTPUT, IOPORT_MODE_INVERT_PIN, IOPORT_MODE_TOTEM, IOPORT_PIN_LEVEL_HIGH, ioport_set_pin_dir(), ioport_set_pin_level(), ioport_set_pin_mode(), usart_spi_options::spimode, sysclk_enable_peripheral_clock(), sysclk_get_per_hz(), UNUSED, USART_DORD_bm, usart_rx_disable(), usart_rx_enable(), usart_set_mode(), usart_spi_set_baudrate(), usart_tx_enable(), and USART_UCPHA_bm.
Referenced by usart_spi_setup_device().
|
inlinestatic |
Write a data to the USART data register.
usart | The USART module. |
txdata | The data to be transmitted. |
Referenced by ili9341_read_byte(), ili9341_send_byte(), and usart_spi_transmit().
enum status_code usart_putchar | ( | USART_t * | usart, |
uint8_t | c | ||
) |
Send a data with the USART module.
This function outputs a data using the USART module.
usart | The USART module. |
c | The data to send. |
References STATUS_OK, and usart_data_register_is_empty().
Referenced by gfx_mono_screen_dump(), log_sha204(), main(), and usart_serial_putchar().
|
inlinestatic |
Disable USART receiver.
usart | Pointer to the USART module. |
Referenced by ili9341_read_byte(), and usart_init_spi().
|
inlinestatic |
Enable USART receiver.
usart | Pointer to the USART module |
Referenced by ili9341_read_byte(), usart_init_rs232(), and usart_init_spi().
|
inlinestatic |
Checks if the RX complete interrupt flag is set.
Checks if the RX complete interrupt flag is set.
usart | The USART module. |
Referenced by ili9341_read_byte(), usart_getchar(), usart_spi_is_rx_full(), and usart_spi_is_rx_ready().
bool usart_set_baudrate | ( | USART_t * | usart, |
uint32_t | baud, | ||
uint32_t | cpu_hz | ||
) |
Set the baudrate value in the USART module.
This function sets the baudrate register with scaling regarding the CPU frequency and makes sure the baud rate is supported by the hardware. The function can be used if you don't want to calculate the settings yourself or changes to baudrate at runtime is required.
usart | The USART module. |
baud | The baudrate. |
cpu_hz | The CPU frequency. |
true | if the hardware supports the baud rate |
false | if the hardware does not support the baud rate (i.e. it's either too high or too low.) |
Referenced by usart_init_rs232().
void usart_set_baudrate_precalculated | ( | USART_t * | usart, |
uint32_t | baud, | ||
uint32_t | cpu_hz | ||
) |
Set the baudrate using precalculated BAUDCTRL values from PROGMEM.
usart | The USART module. |
baud | The baudrate. |
cpu_hz | The CPU frequency. |
References Assert, PROGMEM_READ_WORD, USART_BAUD_UNDEFINED, and usart_get_baud_offset().
void usart_set_bsel_bscale_value | ( | USART_t * | usart, |
uint16_t | bsel, | ||
uint8_t | bscale | ||
) |
Set the baudrate by setting the BSEL and BSCALE values in the USART.
This function sets the selected BSEL and BSCALE value in the BAUDCTRL registers with BSCALE 0. For calculation options, see table 21-1 in XMEGA A manual.
usart | The USART module. |
bsel | Calculated BSEL value. |
bscale | Calculated BSEL value. |
|
inlinestatic |
Set USART DRE interrupt level.
Sets the interrupt level on Data Register interrupt.
usart | Pointer to the USART module. |
level | Interrupt level of the DRE interrupt. Use USART_DREINTLVL_t type. |
|
inlinestatic |
Set the mode the USART run in.
Set the mode the USART run in. The default mode is asynchronous mode.
usart | Pointer to the USART module register section. |
usartmode | Selects the USART mode. Use USART_CMODE_t type. |
USART modes:
Referenced by usart_init_rs232(), and usart_init_spi().
|
inlinestatic |
Set USART RXD interrupt level.
Sets the interrupt level on RX Complete interrupt.
usart | Pointer to the USART module. |
level | Interrupt level of the RXD interrupt. |
|
inlinestatic |
Set USART TXD interrupt level.
Sets the interrupt level on TX Complete interrupt.
usart | Pointer to the USART module. |
level | Interrupt level of the TXD interrupt. |
void usart_spi_set_baudrate | ( | USART_t * | usart, |
uint32_t | baud, | ||
uint32_t | cpu_hz | ||
) |
Set the baudrate value in the USART_SPI module.
This function sets the baudrate register regarding the CPU frequency.
usart | The USART(SPI) module. |
baud | The baudrate. |
cpu_hz | The CPU frequency. |
Referenced by usart_init_spi().
|
inlinestatic |
Performs a data transfer on the USART in SPI mode.
usart | The USART module. |
txdata | The data to be transmitted. |
References usart_clear_tx_complete(), usart_data_register_is_empty(), usart_get(), usart_put(), and usart_tx_is_complete().
Referenced by ssd1306_write_command(), ssd1306_write_data(), st7565r_write_command(), st7565r_write_data(), usart_spi_read_packet(), usart_spi_read_single(), usart_spi_write_packet(), and usart_spi_write_single().
|
inlinestatic |
Disable USART transmitter.
usart | Pointer to the USART module. |
|
inlinestatic |
Enable USART transmitter.
usart | Pointer to the USART module. |
Referenced by usart_init_rs232(), and usart_init_spi().
|
inlinestatic |
Checks if the TX complete interrupt flag is set.
Checks if the TX complete interrupt flag is set.
usart | The USART module. |
Referenced by configure_sensor_platform(), ili9341_wait_for_send_done(), and usart_spi_transmit().