uart.h File Reference

Interrupt-driven UART driver for the Atmel AVR. More...

#include <avr/io.h>
#include <inttypes.h>

Go to the source code of this file.

Defines

#define BAUD   9600
 The desired baud rate (default is 9600 baud).
#define BAUD_SETTING   (F_CPU/(16UL*BAUD)-1)

Functions

void uart_init (uint16_t brr)
 Set up the UART.
int uart_putchar (char c)
 Send a character.
char uart_getchar (char *c)
 Reads a character from the receiver buffer.
int uart_puts (const char *s)
 Sends a string.


Detailed Description

Interrupt-driven UART driver for the Atmel AVR.

Note:
This driver uses register definitions for avr5 CPUs with one USART, for example the ATmega48 and similar chips. It will need minor modification to compile for older AVRs or AVRs with two UARTs.

Define UART_X2 in your compiler flags to use the X2 mode in UART clock generation. Check the "examples of baud rate setting" table in your data sheet to see if you should be using X2 mode.


Define Documentation

#define BAUD   9600

The desired baud rate (default is 9600 baud).

#define BAUD_SETTING   (F_CPU/(16UL*BAUD)-1)


Function Documentation

char uart_getchar ( char *  c  ) 

Reads a character from the receiver buffer.

This function reads the next byte (if any) from the receive buffer and copies it to the specified address. This is essentially a non-blocking getchar() routine. Nothing is written to the specified address if the receive buffer was empty.

Parameters:
[out] c Pointer to where the byte is to be written.
Return values:
char 1 if something was read, 0 if the receive buffer was empty.

void uart_init ( uint16_t  brr  )  [inline]

Set up the UART.

This function sets up the UART using the baud rate setting specified and initializes the transmit and receive buffers. It should be called with the BAUD_SETTING macro as an argument. X2 clock mode will be enabled if UART_X2 is defined.

Note:
The UART will be set up in 8 bits, no parity mode.
Parameters:
[in] brr Baud rate setting to use.

int uart_putchar ( char  c  ) 

Send a character.

This function writes a byte to the transmit buffer and enables the UDRE interrupt so that the byte will be transmitted.

Parameters:
[in] c Byte to transmit.
Return values:
int The parameter 'c' on success, -1 if there was not enough room in the transmit buffer.

int uart_puts ( const char *  s  ) 

Sends a string.

This function is provided for convenience. It writes a string to the transmit buffer by calling uart_putchar() repeatedly.

Parameters:
[in] s String to write (must be NULL-terminated).
Return values:
int Number of bytes successfully written.


Generated on Mon Mar 26 00:29:13 2007 for UARTDriver by  doxygen 1.5.1