Skip to content

samueldonovan1701/avr-USART

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

avr-USART

Simple Serial (USART) communication for Arduino

Written for and tested on a ATMEGA2560

Usage

To use the library, clone or download it to your project directory and

#include "avrUSART/USART.h"

Pre-definitions

USART0 through USART3 are conditionally defined. It is recommended to use these rather than instantiating a new USART object.

If you wish to access other USART ports, you will have to instantiate them yourself.

USART0 is usually tied to the board's USB port

Functions

Constructor

Function Description
USART USART(n) A macro for instanciating a new USART port. The following are assumed defined:
  • UBBRnL
  • UBRRnH
  • UCSRnA
  • UCSRnB
  • UCSRnC
  • UDRN

Core Functions

Function Description
void begin(ulong) Sets baud rate to that provided, as well as the following:
  • Frame Size = 8
  • Stop Bits = 1
  • Parity = Disabled
  • Tx = Enabled
  • Rx = Enabled
char Read() Reads the current character in the USART's data register
void Write(char) Writes a character to the USART's data register. Blocked until the data register is empty
void Write(char*) Sequentially writes a cstring to the data register (must be null terminated)
void SetBaudRate(ulong) Sets the USART port's baud rate

UCSRA Functions

Function Description
bool RxComplete() Returns true if the RxC flag is set, and false otherwise
bool TxComplete() Returns 1 if the TxC flag is set, 0 otherwise
void SetTxComplete() Sets the TxC flag
void ClearTxComplete() Clears the TxC flag
bool DataRegisterEmpty() Returns true if the UDRE flag is set, amd false otherwise
bool FrameError() Returns true if the FE flag is set, and false otherwise
bool DataOverrunError() Returns true if the DOR flag is set, and false otherwise
bool ParityError() Returns true if the PE flag is set, and false otherwise
bool DoubleTransmissionSpeedIsEnabled() Returns true if the U2X flag is set, and false otherwise
void EnableDoubleTransmissionSpeed() Sets the U2X flag
void DisableDoubleTransmissionSpeed() Clears the U2X flag
bool MultiProcessorCommunicationModeIsEnabled() Returns true if the MPCM flag is set, and false otherwise
void EnableMultiProcessorCommunicationMode() Sets the MPCM flag
void DisableMultiProcessorCommunicationMode() Clears the MPCM flag

UCSRB Functions

Function Description
bool RxCompleteInterruptIsEnabled() Returns true if the RXCIE flag is set, and false otherwise
void EnableRxCompleteInterrupt() Sets the RXCIE flag
void DisableRxCompleteInterrupt() Clears the RXCIE flag
bool TxCompleteInterruptIsEnabled() Returns true if the TXCIE flag is set, and false otherwise
void EnableTxCompleteInterrupt() Sets the TXCIE flag
void DisableTxCompleteInterrupt() Clears the TXCIE flag
bool DataRegisterEmptyInterruptIsEnabled() Returns true if the UDRIE flag is set, and false otherwise
void EnableDataRegisterEmptyInterrupt() Sets the UDRIE flag
void EnableDataRegisterEmptyInterrupt() Clears the UDRIE flag
bool RxIsEnabled() Returns true if the RXEN flag is set, and false otherwise
void EnableRx() Sets the RXEN flag
void DisableRx() Clears the RXEN flag
bool TxIsEnabled() Returns true if the TXEN flag is set, and false otherwise
void EnableTx() Sets the TXEN flag
void DisableTx() Clears the TXEN flag
byte GetRxBit9 Returns 1 if the RXB8 is set, and 0 otherwise
byte GetTxBit9() Returns 1 if the TXB8 is set, and 0 otherwise
void SetTxBit9() Sets TXB8
void ClearTxBit9() Clears TXB8

UCSRC Functions

Function Description
USART::Mode GetMode() Returns which mode of operation the USART port is in
void SetMode(USART::Mode) Sets the USART port's mode of operation
USART::Parity GetParity() Returns which parity mode the USART port is in
void SetParity(USART::Parity) Sets the USART port's parity mode
USART::StopBits GetStopBits() Returns how many stop bits the USART port is using for communication
void SetStopBits(USART::StopBits) Sets how many stop bits the USART port will use for communication
USART::FrameSize GetFrameSize() Returns the frame size the USART port is using for communication
SetFrameSize(USART::FrameSize) Sets the frame size the USART port will use for communication
USART::ClockPolarity GetClockPolarity() Returns the clock polarity mode the USART port is using for communication
void SetClockPolarity(USART::ClockPolarity) Sets the clock polarity mode the USART port will use for communication

Enums

Name Values
USART::Mode
  • ASYNC
  • SYNC
  • MSPIM (Master SPI Mode)
USART::Parity
  • DISABLED
  • RESERVED
  • EVEN
  • ODD
USART::StopBits
  • ONE
  • TWO
USART::FrameSize
  • FIVE
  • SIX
  • SEVEN
  • EIGHT
  • NINE
USART::ClockPolarity
  • RISING_EDGE
  • FALLING_EDGE

Supported Boards

  • ATMEGA2560

(may still work on others)

Limitations

  • Need some familiarity with USART

About

Better Serial (USART) communication for Arduino

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages