Microchip® Advanced Software Framework

usart.c File Reference

USART driver for AVR XMEGA.

Copyright (c) 2009-2018 Microchip Technology Inc. and its subsidiaries.

#include <stdint.h>
#include "compiler.h"
#include "usart.h"
#include "sysclk.h"
#include "ioport.h"
#include "status_codes.h"

Macros

#define USART_DORD_bm   0x04
 
#define USART_UCPHA_bm   0x02
 

Functions

static uint8_t usart_get_baud_offset (uint32_t baud)
 Get the offset for lookup in the baudrate table. 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...
 
enum status_code usart_putchar (USART_t *usart, uint8_t c)
 Send a data with the USART module. 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...
 
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...
 

#define USART_DORD_bm   0x04

Referenced by usart_init_spi().

#define USART_UCPHA_bm   0x02

Referenced by usart_init_spi().

static uint8_t usart_get_baud_offset ( uint32_t  baud)
static

Get the offset for lookup in the baudrate table.

Parameters
baudThe requested baudrate
Returns
The baudrate offset in PROGMEM table
Return values
USART_BAUD_UNDEFINEDfor baudrates not in lookup table

References USART_BAUD_1200, USART_BAUD_19200, USART_BAUD_2400, USART_BAUD_38400, USART_BAUD_4800, USART_BAUD_57600, USART_BAUD_9600, and USART_BAUD_UNDEFINED.

Referenced by usart_set_baudrate_precalculated().