ATmega64M1 AVR UART, ADC and DAC  v2.0
UART, ADC and DAC libraries for the ATmega16M1, ATmega32M1 and ATmega64M1.
Macros | Functions
uart.h File Reference

Header file for UART communication. More...

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

Go to the source code of this file.

Macros

#define UART_LBT   8
 
#define BAUD_CALC(baud)   ((F_CPU / 4 / baud - 1) / 2)
 

Functions

void uart_init (uint8_t brr_value)
 UART initialization function. More...
 
int uart_transmit (char byte_data, FILE *stream)
 Function to transmit characters. More...
 
int uart_receive (FILE *stream)
 Function to read characters. More...
 
int uart_getline (char line[], int max)
 Function to read line. More...
 

Detailed Description

Header file for UART communication.

Author
Christoph Jurczyk
Date
October 21, 2018

License

This library is released under the GNU General Public License v3.0.

Macro Definition Documentation

◆ BAUD_CALC

#define BAUD_CALC (   baud)    ((F_CPU / 4 / baud - 1) / 2)

Calculation of LINBRR value for UART initialization.

◆ UART_LBT

#define UART_LBT   8

Numbers of samples per bit.

Function Documentation

◆ uart_getline()

int uart_getline ( char  line[],
int  max 
)

Function to read line.

Call this function to read a string until newline termination. Example call:

char read_buffer[256];
while(uart_getline(read_buffer, 256) != EOF)
Parameters
lineIs the buffer for the read line.
maxMaximum number of receiving characters.
Returns
Returns numbers of received characters or EOF flag.

◆ uart_init()

void uart_init ( uint8_t  brr_value)

UART initialization function.

To initialize the UART connection call this function with the desired LINBRR value, which can be calculated wit the following command:

BAUD_CALC(9600)
Note
The baudrate can be change to your desired baudrate.

Call the initialization function as follow:

◆ uart_receive()

int uart_receive ( FILE *  stream)

Function to read characters.

Call this function to read a character from the UART buffer. Example call:

char a = uart_receive();
Parameters
streamIs an optional parameter for the FDEV_SETUP_STREAM.
Returns
Returns the character.

◆ uart_transmit()

int uart_transmit ( char  byte_data,
FILE *  stream 
)

Function to transmit characters.

Call this function with a character or character array to transmit data via the UART connection. Example call:

Parameters
byte_dataIs the to transmitted data e.g. a character.
streamIs an optional parameter for the FDEV_SETUP_STREAM.
Returns
Returns a 0 after successful transmission. This is necessary for the optional use in FDEV_SETUP_STREAM.