Implementation of USART Stack. More...
#include <stdio.h>
Go to the source code of this file.
Defines | |
#define | UART_DDR DDRD |
Data Directory Register of the desired USART. | |
#define | RXPIN_bm (1<<2) |
Bitmask of the RX-Pin. | |
#define | TXPIN_bm (1<<3) |
Bitmask of the TX-Pin. | |
#define | UART_DATA UDR |
USART Data Register. | |
#define | RXC_vect USART_RXC_vect |
RX-Complete Interrupt Vector. | |
#define | DRE_vect USART_UDRE_vect |
Data-Register-Empty Interrupt Vector. | |
#define | UART_RX_BUFFER_SIZE 64 |
Size ofe the receiver FIFO. | |
#define | UART_TX_BUFFER_SIZE 64 |
Size ofe the transmitter FIFO. | |
#define | UBRR_val 3 |
Value of Baudrate Register. | |
#define | UART_CHRSIZE_9BIT 0 |
set Character Size to 9Bit | |
#define | UART_PRINTF_COMPATIBILITY 1 |
enable printf compatible functions | |
#define | UART_MPCM_ENABLE 0 |
enable mpcm functions | |
Functions | |
void | uart_init (void) |
Initialise the USART Module. | |
void | uart_sendbyte (uint8_t data) |
Send one Byte. | |
uint8_t | uart_getbyte (uint8_t *data) |
Pull one Byte from RX-Buffer. | |
uint8_t | uart_senddata (uint8_t data) |
Send one data byte without buffering in the FIFO. | |
uint8_t | uart_sendid (uint8_t data) |
Send one id byte without buffering in the FIFO. | |
void | uart_mpcm_en (void) |
Enable Multiprocessor Communication Mode. | |
void | uart_mpcm_dis (void) |
Disable Multiprocessor Communication Mode. | |
void | uart_udre_int_en (void) |
Enable Data Register Empty Interrupt. | |
void | uart_udre_int_dis (void) |
Disable Data Register Empty Interrupt. | |
void | uart_rxc_int_en (void) |
Enable Data RX Complete Interrupt. | |
void | uart_rxc_int_dis (void) |
Disable Data RX Complete Interrupt. | |
int | uart_putchar (char c, FILE *sream) |
Send one Byte (printf version) | |
int | uart_getchar (FILE *stream) |
Pull one Byte from RX-Buffer. |
Implementation of USART Stack.
Definition in file uart.h.
#define UART_CHRSIZE_9BIT 0 |
#define UART_MPCM_ENABLE 0 |
enable mpcm functions
In order to save codespace you can set this define to 0 if you do not need the Multi-Processor-Communication-Mode features.. This will diable the functions uart_senddata() and uart_sendid() The value 1 enables the Feature
#define UART_PRINTF_COMPATIBILITY 1 |
#define UART_RX_BUFFER_SIZE 64 |
#define UART_TX_BUFFER_SIZE 64 |
#define UBRR_val 3 |
Value of Baudrate Register.
Equation for Calculating the Baud Rate Register Setting:
example values vor F_CPU=7.3728MHz
uint8_t uart_getbyte | ( | uint8_t * | data ) |
Pull one Byte from RX-Buffer.
If the RX-Fifo is enabled any data receives is automaticaly pusched into the Fifo ba the ISR. This function removes the oldest Byte from the Buffer and copies it into the Memory-Space which is handed over as a parameter.
data | pointer to a buffer where the received data is copied to |
int uart_getchar | ( | FILE * | stream ) |
Pull one Byte from RX-Buffer.
If the RX-Fifo is enabled any data receives is automaticaly pusched into the Fifo ba the ISR. This function removes the oldest Byte from the Buffer and copies it into the Memory-Space which is handed over as a parameter.
void uart_init | ( | void | ) |
int uart_putchar | ( | char | c, |
FILE * | sream | ||
) |
Send one Byte (printf version)
This fuction sends one byte by copyint the data into the fifo-buffer and enabling the UDRE-Interrupt. The actual transmission is then initiated by the Interrupt-Service-Routine. If the buffer is full this function waits until the next byte has been transmitted, so it is always successful.
This is the printf compatible version ov uart_sendbyte
data | Data-Byte to send |
Definition at line 101 of file uart.c.
void uart_sendbyte | ( | uint8_t | data ) |
Send one Byte.
This fuction sends one byte by copying the data into the fifo-buffer and enabling the UDRE-Interrupt. The actual transmission is then initiated by the Interrupt-Service-Routine. If the buffer is full this function waits until the next byte has been transmitted, so it is always successful.
data | Data-Byte to send |
Definition at line 48 of file uart.c.
uint8_t uart_senddata | ( | uint8_t | data ) |
uint8_t uart_sendid | ( | uint8_t | data ) |