Embedded C Firmware Library : Arduino / Atmega328p
1
Register Level Embedded C Hardware Abstraction Library for AVR ATmega48A/PA/88A/PA/168A/PA/328/P or Arduino UNO/NANO/MINI
|
Library for USART Communication. More...
Go to the source code of this file.
Data Structures | |
struct | USART_ConfigData |
Macros | |
USART_MODE | |
Options for USART Operation Mode | |
#define | USART_SYNCHRONOUS_CLOCK_PRIORITY 0 |
#define | USART_MODE_ASYNCHRONOUS (0<<UMSEL00) |
#define | USART_MODE_SYNCHRONOUS (1<<UMSEL00) | USART_SYNCHRONOUS_CLOCK_PRIORITY |
#define | USART_MODE_MASK (1<<UMSEL00) |
USART_PARITY_BIT | |
Options for Parity Bit in USART Data Frame | |
#define | USART_PARITY_BIT_NO (0<<UPM00) |
#define | USART_PARITY_BIT_EVEN (1<<UPM01) |
#define | USART_PARITY_BIT_ODD (1<<UPM01) | (1<<UPM00) |
#define | USART_PARITY_BIT_MASK (1<<UPM01) | (1<<UPM00) |
USART_STOP_BIT | |
Options for Stop Bit in USART Data Frame | |
#define | USART_STOP_BIT_ONE (0<<USBS0) |
#define | USART_STOP_BIT_TWO (1<<USBS0) |
#define | USART_STOP_BIT_MASK (1<<USBS0) |
USART_DATA_BIT | |
Options for Data Bit Length in USART Data Frame | |
#define | USART_DATA_BIT_FIVE (0<<UCSZ00) |
#define | USART_DATA_BIT_SIX (1<<UCSZ00) |
#define | USART_DATA_BIT_SEVEN (1<<UCSZ01) |
#define | USART_DATA_BIT_EIGHT (1<<UCSZ01) | (1<<UCSZ00) |
#define | USART_DATA_BIT_MASK (1<<UCSZ01) | (1<<UCSZ00) |
USART_INTERRUPT | |
Options for USART Interrupts | |
#define | USART_RX_COMPLETE_INTERRUPT (1<<RXCIE0) |
#define | USART_TX_COMPLETE_INTERRUPT (1<<TXCIE0) |
#define | USART_DATA_REGISTER_EMPTY_INTERRUPT (1<<UDRIE0) |
Typedefs | |
USART_CONFIGURATION_DATA | |
Structure used to Configure USART | |
typedef struct USART_ConfigData | USART_ConfigData |
Functions | |
ISR (USART_RX_vect) | |
Interrupt Service Routine for Reception. More... | |
ISR (USART_UDRE_vect) | |
Interrupt Service Routine for Transmission. More... | |
USART_FLUSH_TRANSMIT_RECEIVE_BUFFER | |
Public Functions to Flush USART Transmit and Receive Buffer | |
void | USART_FlushTransmitBuffer () |
Public Function to Flush the Transmit Buffer. More... | |
void | USART_FlushReceiveBuffer () |
Public Function to Flush the Receive Buffer. More... | |
USART_TRANSMIT_INTERRUPT_CONTROL | |
Public Functions to Control USART Transmit Interrupts | |
void | USART_EnableTransmitInterrupt () |
Public Function to Enable Transmit Interrupt. More... | |
void | USART_DisableTransmitInterrupt () |
Public Function to Disable Transmit Interrupt. More... | |
USART_RECEIVE_INTERRUPT_CONTROL | |
Public Functions to Control USART Receive Interrupts | |
void | USART_EnableReceiveInterrupt () |
Public Function to Enable Receive Interrupt. More... | |
void | USART_DisableReceiveInterrupt () |
Public Function to Disable Receive Interrupt. More... | |
USART_CONFIGURATION_AND_CONTROL | |
Public Functions to Control and Configure USART | |
void | USART_Init (USART_ConfigData Data) |
Public Function to Configure and Initialize USART. More... | |
void | USART_DeInit () |
Public Function to De-Initialize USART. More... | |
USART_RECEIVE | |
Public Functions to Receive Data via USART | |
uint8_t | USART_ReceiveBlocking () |
Public Function to Receive 1 Byte of Data in Polling. More... | |
uint8_t | USART_ReceiveByte (uint8_t *Buffer) |
Public Function to Receive 1 Byte of Data. More... | |
uint8_t | USART_ReceiveTwoBytes (uint16_t *Buffer) |
Public Function to Receive 2 Bytes of Data with LSB Byte First. More... | |
uint8_t | USART_ReceiveBytes (uint8_t *Buffer, uint16_t Size) |
Public Function to Receive Multiple Bytes of Data. More... | |
uint8_t | USART_ReceiveChar (char *Character) |
Public Function to Receive char Data. More... | |
uint8_t | USART_ReceiveInt (int *Number, uint8_t Size) |
Public Function to Receive int Data as ASCII. More... | |
uint8_t | USART_ReceiveLong (long *Number, uint8_t Size) |
Public Function to Receive long Data as ASCII. More... | |
uint8_t | USART_ReceiveString (char *Buffer, uint16_t Size) |
Public Function to Receive string Data. More... | |
void | USART_CancelReceive () |
Public Function to Cancel any Interrupt based Reception. More... | |
USART_TRANSMIT | |
Public Functions to Transmit Data via USART | |
uint8_t | USART_TransmitBlocking (uint8_t *Buffer) |
Public Function to Transmit 1 Byte of Data in Polling. More... | |
uint8_t | USART_TransmitByte (uint8_t *Buffer) |
Public Function to Transmit 1 Byte of Data. More... | |
uint8_t | USART_TransmitTwoBytes (uint16_t *Buffer) |
Public Function to Transmit 2 Bytes of Data with LSB Byte First. More... | |
uint8_t | USART_TransmitBytes (uint8_t *Buffer, uint16_t Size) |
Public Function to Transmit Multiple Bytes of Data. More... | |
uint8_t | USART_TransmitChar (char Character) |
Public Function to Transmit char Data. More... | |
uint8_t | USART_TransmitInt (int Number) |
Public Function to Transmit int Data as ASCII. More... | |
uint8_t | USART_TransmitLong (long Number) |
Public Function to Transmit long Data as ASCII. More... | |
uint8_t | USART_TransmitFloat (float Number, uint8_t Precision) |
Public Function to Transmit float Data as ASCII. More... | |
uint8_t | USART_TransmitString (char *Buffer) |
Public Function to Transmit string Data. More... | |
void | USART_CancelTransmit () |
Public Function to Cancel any Interrupt based Transmission. More... | |
Library for USART Communication.
Created: 01-05-2020 08:20:10 PM Author : Arnab Kumar Das Website: www.ArnabKumarDas.com Microcontroller Supported: ATmega48A/PA/88A/PA/168A/PA/328/P or Arduino UNO/NANO/MINI +-\/-+ PC6 1| |28 PC5 (A5/ADC5) RXD (D0) PD0 2| |27 PC4 (A4/ADC4) TXD (D1) PD1 3| |26 PC3 (A3/ADC3) (D2) PD2 4| |25 PC2 (A2/ADC2) PWM (D3) PD3 5| |24 PC1 (A1/ADC1) XCK (D4) PD4 6| |23 PC0 (A0/ADC0) VCC 7| |22 GND GND 8| |21 AREF PB6 9| |20 AVCC PB7 10| |19 PB5 (D13) OC0B (D5) PD5 11| |18 PB4 (D12) OC0A (D6) PD6 12| |17 PB3 (D11) PWM (D7) PD7 13| |16 PB2 (D10) PWM (D8) PB0 14| |15 PB1 (D9) PWM +----+
#define USART_SYNCHRONOUS_CLOCK_PRIORITY 0 |
USART Clock Priority when Synchronous External Clock is used
#define USART_MODE_ASYNCHRONOUS (0<<UMSEL00) |
Sets the USART Mode of Operation to : Asynchronous UART
#define USART_MODE_SYNCHRONOUS (1<<UMSEL00) | USART_SYNCHRONOUS_CLOCK_PRIORITY |
Sets the USART Mode of Operation to : Synchronous USRT
#define USART_MODE_MASK (1<<UMSEL00) |
Mask for USART Mode of Operation
#define USART_PARITY_BIT_NO (0<<UPM00) |
Sets the Parity Bit of USART Data Frame to : No Parity Bit
#define USART_PARITY_BIT_EVEN (1<<UPM01) |
Sets the Parity Bit of USART Data Frame to : Even Parity Bit
#define USART_PARITY_BIT_ODD (1<<UPM01) | (1<<UPM00) |
Sets the Parity Bit of USART Data Frame to : Odd Parity Bit
#define USART_PARITY_BIT_MASK (1<<UPM01) | (1<<UPM00) |
Mask for USART Parity Bit
#define USART_STOP_BIT_ONE (0<<USBS0) |
Sets the Stop Bit of USART Data Frame to : One Stop Bit
#define USART_STOP_BIT_TWO (1<<USBS0) |
Sets the Stop Bit of USART Data Frame to : Two Stop Bit
#define USART_STOP_BIT_MASK (1<<USBS0) |
Mask for USART Stop Bit
#define USART_DATA_BIT_FIVE (0<<UCSZ00) |
Sets the Data Bit length of USART Data Frame to : Five Bit
#define USART_DATA_BIT_SIX (1<<UCSZ00) |
Sets the Data Bit length of USART Data Frame to : Six Bit
#define USART_DATA_BIT_SEVEN (1<<UCSZ01) |
Sets the Data Bit length of USART Data Frame to : Seven Bit
#define USART_DATA_BIT_EIGHT (1<<UCSZ01) | (1<<UCSZ00) |
Sets the Data Bit length of USART Data Frame to : Eight Bit
#define USART_DATA_BIT_MASK (1<<UCSZ01) | (1<<UCSZ00) |
Mask for the Data Bit length of USART Data Frame
#define USART_RX_COMPLETE_INTERRUPT (1<<RXCIE0) |
USART Interrupt Control Bit : Receive Complete Interrupt
#define USART_TX_COMPLETE_INTERRUPT (1<<TXCIE0) |
USART Interrupt Control Bit : Transmit Complete Interrupt
#define USART_DATA_REGISTER_EMPTY_INTERRUPT (1<<UDRIE0) |
USART Interrupt Control Bit : Data Register Empty Interrupt
void USART_FlushTransmitBuffer | ( | ) |
Public Function to Flush the Transmit Buffer.
void USART_FlushReceiveBuffer | ( | ) |
Public Function to Flush the Receive Buffer.
|
inline |
Public Function to Enable Transmit Interrupt.
|
inline |
Public Function to Disable Transmit Interrupt.
|
inline |
Public Function to Enable Receive Interrupt.
|
inline |
Public Function to Disable Receive Interrupt.
void USART_Init | ( | USART_ConfigData | Data | ) |
Public Function to Configure and Initialize USART.
[in] | Data | : Structure Variable containing USART Configuration Data |
USART_ConfigData Data2; Data2.BaudRate = 9600; Data2.DataBit = USART_DATA_BIT_EIGHT; Data2.ParityBit = USART_PARITY_BIT_NO; Data2.StopBit = USART_STOP_BIT_ONE; Data2.UsartMode = USART_MODE_ASYNCHRONOUS; USART_Init(Data2);
void USART_DeInit | ( | ) |
Public Function to De-Initialize USART.
uint8_t USART_ReceiveBlocking | ( | ) |
Public Function to Receive 1 Byte of Data in Polling.
uint8_t USART_ReceiveByte | ( | uint8_t * | Buffer | ) |
Public Function to Receive 1 Byte of Data.
[out] | Buffer | : Pointer to Memory Location to Store Data |
uint8_t USART_ReceiveTwoBytes | ( | uint16_t * | Buffer | ) |
Public Function to Receive 2 Bytes of Data with LSB Byte First.
[out] | Buffer | : Pointer to Memory Location to Store Data |
uint8_t USART_ReceiveBytes | ( | uint8_t * | Buffer, |
uint16_t | Size | ||
) |
Public Function to Receive Multiple Bytes of Data.
[out] | Buffer | : Pointer to Memory Location to Store Data |
[in] | Size | : Variable to Store Number of Bytes to Receive |
uint8_t USART_ReceiveChar | ( | char * | Character | ) |
Public Function to Receive char Data.
[out] | Character | : Pointer to Memory Location to Store char Data |
uint8_t USART_ReceiveInt | ( | int * | Number, |
uint8_t | Size | ||
) |
Public Function to Receive int Data as ASCII.
[out] | Number | : Pointer to Memory Location to Store int Data |
[in] | Size | : Variable to Store Number of Digits to Receive |
uint8_t USART_ReceiveLong | ( | long * | Number, |
uint8_t | Size | ||
) |
Public Function to Receive long Data as ASCII.
[out] | Number | : Pointer to Memory Location to Store long Data |
[in] | Size | : Variable to Store Number of Digits to Receive |
uint8_t USART_ReceiveString | ( | char * | Buffer, |
uint16_t | Size | ||
) |
Public Function to Receive string Data.
[out] | Buffer | : Pointer to Memory Location to Store string Data |
[in] | Size | : Variable to Store Number of Letters to Receive |
void USART_CancelReceive | ( | ) |
Public Function to Cancel any Interrupt based Reception.
uint8_t USART_TransmitBlocking | ( | uint8_t * | Buffer | ) |
Public Function to Transmit 1 Byte of Data in Polling.
uint8_t USART_TransmitByte | ( | uint8_t * | Buffer | ) |
Public Function to Transmit 1 Byte of Data.
[in] | Buffer | : Pointer to Memory Location to Store Data |
uint8_t USART_TransmitTwoBytes | ( | uint16_t * | Buffer | ) |
Public Function to Transmit 2 Bytes of Data with LSB Byte First.
[in] | Buffer | : Pointer to Memory Location to Store Data |
uint8_t USART_TransmitBytes | ( | uint8_t * | Buffer, |
uint16_t | Size | ||
) |
Public Function to Transmit Multiple Bytes of Data.
[in] | Buffer | : Pointer to Memory Location to Store Data |
[in] | Size | : Variable to Store Number of Bytes to Transmit |
uint8_t USART_TransmitChar | ( | char | Character | ) |
Public Function to Transmit char Data.
[in] | Character | : Variable to Store char Data |
uint8_t USART_TransmitInt | ( | int | Number | ) |
Public Function to Transmit int Data as ASCII.
[in] | Number | : Variable to Store int Data |
uint8_t USART_TransmitLong | ( | long | Number | ) |
Public Function to Transmit long Data as ASCII.
[in] | Number | : Variable to Store long Data |
uint8_t USART_TransmitFloat | ( | float | Number, |
uint8_t | Precision | ||
) |
Public Function to Transmit float Data as ASCII.
[in] | Number | : Variable to Store float Data |
[in] | Precision | : Variable to Store Precision of Decimal Number |
uint8_t USART_TransmitString | ( | char * | Buffer | ) |
Public Function to Transmit string Data.
[in] | Buffer | : Pointer to Memory Location to Store string Data |
void USART_CancelTransmit | ( | ) |
Public Function to Cancel any Interrupt based Transmission.
ISR | ( | USART_RX_vect | ) |
Interrupt Service Routine for Reception.
[in] | USART_RX_vect |
ISR | ( | USART_UDRE_vect | ) |
Interrupt Service Routine for Transmission.
[in] | USART_UDRE_vect |