Defines | Functions

uart.h File Reference

Implementation of USART Stack. More...

#include <stdio.h>
Include dependency graph for uart.h:
This graph shows which files directly or indirectly include this file:

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.

Detailed Description

Implementation of USART Stack.

Author:
Dominic Rathje (dominic.rathje@uni-ulm.de)
Version:
1.0
Note:
  • Compiler : WinAVR 20100110
  • Supported devices : ATMega8

Definition in file uart.h.


Define Documentation

#define UART_CHRSIZE_9BIT   0

set Character Size to 9Bit

Set this to 1 to use 9Bit Character Size. Default is 8Bit

Definition at line 85 of file uart.h.

#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

Definition at line 100 of file uart.h.

#define UART_PRINTF_COMPATIBILITY   1

enable printf compatible functions

In order to save codespace you can set this define to 0 if you do not need printf compatibillity. The value 1 enables the Feature

Definition at line 92 of file uart.h.

#define UART_RX_BUFFER_SIZE   64

Size ofe the receiver FIFO.

the size must be a power of 2 and smaller ore equal to 256. So possible Values are: 2,4,8,16,32,64,128,256

Definition at line 56 of file uart.h.

#define UART_TX_BUFFER_SIZE   64

Size ofe the transmitter FIFO.

the size must be a power of 2 and smaller ore equal to 256. So possible Values are: 2,4,8,16,32,64,128,256

Definition at line 62 of file uart.h.

#define UBRR_val   3

Value of Baudrate Register.

Equation for Calculating the Baud Rate Register Setting:

  • UBRR = ( f_OSC/(16 * BAUD) ) -1

example values vor F_CPU=7.3728MHz

  • 3 => 115200 BAUD
  • 11 => 38400 BAUD
  • 47 => 9600 BAUD example values vor F_CPU=14.7456MHz
  • 7 => 115200 BAUD
  • 23 => 38400 BAUD
  • 95 => 9600 BAUD

Definition at line 79 of file uart.h.


Function Documentation

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.

See also:
uart_getchar for the scanf compatible version
Parameters:
datapointer to a buffer where the received data is copied to
Returns:
true if data has been copied. false if the RX buffer was empty

Definition at line 72 of file uart.c.

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.

See also:
uart_getbyte for the standard version
Returns:
received data or _FDEV_EOF

Definition at line 110 of file uart.c.

void uart_init ( void   )

Initialise the USART Module.

Configures the Port Registers and the USART Module. Call this function at the beginning of your main function.

Definition at line 27 of file uart.c.

Here is the call graph for this function:

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

See also:
uart_sendbyte for the standars version
Parameters:
dataData-Byte to send
Returns:
always 0

Definition at line 101 of file uart.c.

Here is the call graph for this function:

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.

See also:
uart_putchar for the printf compatible version
Parameters:
dataData-Byte to send

Definition at line 48 of file uart.c.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t uart_senddata ( uint8_t  data )

Send one data byte without buffering in the FIFO.

Parameters:
dataData-Byte to send
Returns:
true if data has been send. else false

Definition at line 56 of file uart.c.

uint8_t uart_sendid ( uint8_t  data )

Send one id byte without buffering in the FIFO.

This function is only for use in 9-Bit Character Size and MPCM Mode. The ninth bit es set to 1 to send an address/id frame.

Parameters:
dataData-Byte to send
Returns:
true if data has been send. else false

Definition at line 64 of file uart.c.