usrat.h File Reference

USART interface. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define RX_BUFFER_SIZE   4
 USART RX buffer length.

Functions

void usart_init (uint16_t baudrate)
 Initialize USART, perform fdevopen with uart_putchar.
int uart_putchar (char data)
 putchar() for USART.
int uart_getchar ()
 getchar() for USART. Wait for data if not available.
uint8_t uart_available (void)
 Check data availability in USART buffer.
uint8_t uart_getc ()
 Nonblocking, nonchecking getchar for USART. Use with care.


Detailed Description

USART interface.


Define Documentation

#define RX_BUFFER_SIZE   4

USART RX buffer length.


Function Documentation

uint8_t uart_available ( void   ) 

Check data availability in USART buffer.

Returns:
1 if buffer is not empty.
00060                          {
00061     return rx_buffer_in != rx_buffer_out;
00062 }

uint8_t uart_getc (  ) 

Nonblocking, nonchecking getchar for USART. Use with care.

00065                     {
00066     uint8_t result = rx_buffer[rx_buffer_out];
00067     rx_buffer_out = (rx_buffer_out + 1) % RX_BUFFER_SIZE;
00068     
00069     return result;
00070 }

int uart_getchar (  ) 

getchar() for USART. Wait for data if not available.

Returns:
value read.
See also:
uart_available()
00052                    {
00053     while (!uart_available());
00054     
00055     return (int) uart_getc();
00056 }

Here is the call graph for this function:

int uart_putchar ( char  data  ) 

putchar() for USART.

Parameters:
data character to print.
00034                             {
00035     //while (!(UCSRA & (1<<UDRE))) {};
00036     if (data == '\n') {
00037         (void)uart_putchar('\r');
00038     }
00039 
00040     //PORTD |= 1<<5;
00041     while (!(UCSRA & (1<<UDRE))) {};
00042     //PORTD &= (uint8_t)(~(1<<5));
00043 
00044     UDR = (uint8_t)data;
00045 
00046     return 0;
00047 }

Here is the call graph for this function:

void usart_init ( uint16_t  baudval  ) 

Initialize USART, perform fdevopen with uart_putchar.

Parameters:
baudval (F_CPU/(16*baudrate))-1
See also:
uart_putchar()
00016                                   {
00017     // Set baud rate
00018     UBRRH = (uint8_t)(baudval>>8);
00019     UBRRL = (uint8_t)baudval;
00020 
00021     rx_buffer_in = rx_buffer_out = 0;
00022 
00023     // Set frame format: 8 data, 1 stop bit
00024     UCSRC = (uint8_t)((1<<URSEL) | (0<<USBS) | (3<<UCSZ0));
00025     
00026     // Enable receiver and transmitter, enable RX complete interrupt
00027     UCSRB = (uint8_t)((1<<RXEN) | (1<<TXEN) | (1<<RXCIE));
00028 
00029     (void)fdevopen(uart_putchar, NULL/*, 0*/);
00030 }

Here is the call graph for this function:


Generated on Fri Nov 13 04:21:27 2009 for [M]ouse by  doxygen 1.5.9