Minikombajn Pomiarowy  20
 All Files Functions Variables Macros
Macros
usart_driver.h File Reference

XMEGA USART driver header file. More...

#include "avr_compiler.h"

Go to the source code of this file.

Macros

#define USART_RX_BUFFER_SIZE   4
#define USART_TX_BUFFER_SIZE   4
#define USART_RX_BUFFER_MASK   ( USART_RX_BUFFER_SIZE - 1 )
#define USART_TX_BUFFER_MASK   ( USART_TX_BUFFER_SIZE - 1 )
#define USART_Format_Set(_usart, _charSize, _parityMode, _twoStopBits)
 Macro that sets the USART frame format.
#define USART_Baudrate_Set(_usart, _bselValue, _bScaleFactor)
 Set USART baud rate.
#define USART_Rx_Enable(_usart)   ((_usart)->CTRLB |= USART_RXEN_bm)
 Enable USART receiver.
#define USART_Rx_Disable(_usart)   ((_usart)->CTRLB &= ~USART_RXEN_bm)
 Disable USART receiver.
#define USART_Tx_Enable(_usart)   ((_usart)->CTRLB |= USART_TXEN_bm)
 Enable USART transmitter.
#define USART_Tx_Disable(_usart)   ((_usart)->CTRLB &= ~USART_TXEN_bm)
 Disable USART transmitter.
#define USART_RxdInterruptLevel_Set(_usart, _rxdIntLevel)   ((_usart)->CTRLA = ((_usart)->CTRLA & ~USART_RXCINTLVL_gm) | _rxdIntLevel)
 Set USART RXD interrupt level.
#define USART_TxdInterruptLevel_Set(_usart, _txdIntLevel)   (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_TXCINTLVL_gm) | _txdIntLevel
 Set USART TXD interrupt level.
#define USART_DreInterruptLevel_Set(_usart, _dreIntLevel)   (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_DREINTLVL_gm) | _dreIntLevel
 Set USART DRE interrupt level.
#define USART_SetMode(_usart, _usartMode)   ((_usart)->CTRLC = ((_usart)->CTRLC & (~USART_CMODE_gm)) | _usartMode)
 Set the mode the USART run in.
#define USART_IsTXDataRegisterEmpty(_usart)   (((_usart)->STATUS & USART_DREIF_bm) != 0)
 Check if data register empty flag is set.
#define USART_PutChar(_usart, _data)   ((_usart)->DATA = _data)
 Put data (5-8 bit character).
#define USART_IsRXComplete(_usart)   (((_usart)->STATUS & USART_RXCIF_bm) != 0)
 Checks if the RX complete interrupt flag is set.
#define USART_GetChar(_usart)   ((_usart)->DATA)
 Get received data (5-8 bit character).

Detailed Description

XMEGA USART driver header file.

 This file contains the function prototypes and enumerator definitions
 for various configuration parameters for the XMEGA USART driver.

 The driver is not intended for size and/or speed critical code, since
 most functions are just a few lines of code, and the function call
 overhead would decrease code performance. The driver is intended for
 rapid prototyping and documentation purposes for getting started with
 the XMEGA ADC module.

 For size and/or speed critical code, it is recommended to copy the
 function contents directly into your application instead of making
 a function call.
Application note:
AVR1307: Using the XMEGA USART
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author
Atmel Corporation: http://www.atmel.com
Support email: avr@a.nosp@m.tmel.nosp@m..com
Revision:
1694
Date:
2008-07-29 14:21:58 +0200 (ti, 29 jul 2008)


Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  1. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  1. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

#define USART_Baudrate_Set (   _usart,
  _bselValue,
  _bScaleFactor 
)
Value:
(_usart)->BAUDCTRLA =(uint8_t)_bselValue; \
(_usart)->BAUDCTRLB =(_bScaleFactor << USART_BSCALE0_bp)|(_bselValue >> 8)

Set USART baud rate.

Sets the USART's baud rate register.

UBRR_Value : Value written to UBRR ScaleFactor : Time Base Generator Scale Factor

Equation for calculation of BSEL value in asynchronous normal speed mode: If ScaleFactor >= 0 BSEL = ((I/O clock frequency)/(2^(ScaleFactor)*16*Baudrate))-1 If ScaleFactor < 0 BSEL = (1/(2^(ScaleFactor)*16))*(((I/O clock frequency)/Baudrate)-1)

Note
See XMEGA manual for equations for calculation of BSEL value in other modes.
Parameters
_usartPointer to the USART module.
_bselValueValue to write to BSEL part of Baud control register. Use uint16_t type.
_bScaleFactorUSART baud rate scale factor. Use uint8_t type
#define USART_DreInterruptLevel_Set (   _usart,
  _dreIntLevel 
)    (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_DREINTLVL_gm) | _dreIntLevel

Set USART DRE interrupt level.

Sets the interrupt level on Data Register interrupt.

Parameters
_usartPointer to the USART module.
_dreIntLevelInterrupt level of the DRE interrupt. Use USART_DREINTLVL_t type.
#define USART_Format_Set (   _usart,
  _charSize,
  _parityMode,
  _twoStopBits 
)
Value:
(_usart)->CTRLC = (uint8_t) _charSize | _parityMode | \
(_twoStopBits ? USART_SBMODE_bm : 0)

Macro that sets the USART frame format.

Sets the frame format, Frame Size, parity mode and number of stop bits.

Parameters
_usartPointer to the USART module
_charSizeThe character size. Use USART_CHSIZE_t type.
_parityModeThe parity Mode. Use USART_PMODE_t type.
_twoStopBitsEnable two stop bit mode. Use bool type.
#define USART_GetChar (   _usart)    ((_usart)->DATA)

Get received data (5-8 bit character).

This macro reads out the RX register. Use the macro USART_RX_Complete to check if anything is received.

Parameters
_usartThe USART module.
Return values
Receiveddata.
#define USART_IsRXComplete (   _usart)    (((_usart)->STATUS & USART_RXCIF_bm) != 0)

Checks if the RX complete interrupt flag is set.

Checks if the RX complete interrupt flag is set.

Parameters
_usartThe USART module.
#define USART_IsTXDataRegisterEmpty (   _usart)    (((_usart)->STATUS & USART_DREIF_bm) != 0)

Check if data register empty flag is set.

Parameters
_usartThe USART module.
#define USART_PutChar (   _usart,
  _data 
)    ((_usart)->DATA = _data)

Put data (5-8 bit character).

Use the macro USART_IsTXDataRegisterEmpty before using this function to put data to the TX register.

Parameters
_usartThe USART module.
_dataThe data to send.
#define USART_Rx_Disable (   _usart)    ((_usart)->CTRLB &= ~USART_RXEN_bm)

Disable USART receiver.

Parameters
_usartPointer to the USART module.
#define USART_Rx_Enable (   _usart)    ((_usart)->CTRLB |= USART_RXEN_bm)

Enable USART receiver.

Parameters
_usartPointer to the USART module
#define USART_RxdInterruptLevel_Set (   _usart,
  _rxdIntLevel 
)    ((_usart)->CTRLA = ((_usart)->CTRLA & ~USART_RXCINTLVL_gm) | _rxdIntLevel)

Set USART RXD interrupt level.

Sets the interrupt level on RX Complete interrupt.

Parameters
_usartPointer to the USART module.
_rxdIntLevelInterrupt level of the RXD interrupt. Use USART_RXCINTLVL_t type.
#define USART_SetMode (   _usart,
  _usartMode 
)    ((_usart)->CTRLC = ((_usart)->CTRLC & (~USART_CMODE_gm)) | _usartMode)

Set the mode the USART run in.

Set the mode the USART run in. The default mode is asynchronous mode.

Parameters
_usartPointer to the USART module register section.
_usartModeSelects the USART mode. Use USART_CMODE_t type.

USART modes:

  • 0x0 : Asynchronous mode.
  • 0x1 : Synchronous mode.
  • 0x2 : IrDA mode.
  • 0x3 : Master SPI mode.
#define USART_Tx_Disable (   _usart)    ((_usart)->CTRLB &= ~USART_TXEN_bm)

Disable USART transmitter.

Parameters
_usartPointer to the USART module.
#define USART_Tx_Enable (   _usart)    ((_usart)->CTRLB |= USART_TXEN_bm)

Enable USART transmitter.

Parameters
_usartPointer to the USART module.
#define USART_TxdInterruptLevel_Set (   _usart,
  _txdIntLevel 
)    (_usart)->CTRLA = ((_usart)->CTRLA & ~USART_TXCINTLVL_gm) | _txdIntLevel

Set USART TXD interrupt level.

Sets the interrupt level on TX Complete interrupt.

Parameters
_usartPointer to the USART module.
_txdIntLevelInterrupt level of the TXD interrupt. Use USART_TXCINTLVL_t type.