Table of Contents

Serial Interface

This library provides AVR asynchronous serial interface usage functions.

Data Types

Functions

Macro function to calculate USART baud rate register value in asynchronous mode. Parameters:

Initializes asynchronous USART. Parameters:

Blocking character transmission. Functions wait until transmit buffer empties before writing a character to the buffer. Parameters:

Blocking string transmission. Parameters:

Checks for data in receive buffer. Parameters:

Reads a character from receive buffer. Before reading user must check if there actually is a received character. Parameters:

Reads a character from receive buffer if there is any. Parameters:

Example

USART interface is configured to use 8 data bits, one stop bit, 9600 bps baud rate and no parity mode. Program sends a string, waits until some character is received and then reads it out.

#include <homelab/usart.h>
 
// Use USART interface 0.
usart port = USART(0);
 
int main(void)
{	
	char c;
 
	// Interface initialization.
	usart_init_async(port,
		USART_DATABITS_8,
		USART_STOPBITS_ONE,
		USART_PARITY_NONE,
		USART_BAUDRATE_ASYNC(9600));
 
	// String sending.
	usart_send_string(port, "Hello\n");
 
	// Waiting for incoming data.
	while (!usart_has_data(port)) {}
 
	// Read out the received character.
	c = usart_read_char(port);
}