Microchip® Advanced Software Framework

mega_setbaud_example.c File Reference

megaAVR STK600 AVR libc setbaud Example

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include "compiler.h"
#include "conf_clock.h"
#include "conf_uart.h"
#include <util/setbaud.h>

Macros

#define _ASSERT_ENABLE_
 
#define TIMEOUT   250
 

Functions

int main (void)
 Example application on how to use the libc setbaud utility. More...
 
static uint8_t uart_getchar (void)
 Function for getting a char from the UART. More...
 
static void uart_init (void)
 Initialize the uart with correct baud rate settings. More...
 
static void uart_putchar (uint8_t data)
 Function for sending a char over the UART. More...
 

#define _ASSERT_ENABLE_
#define TIMEOUT   250

Referenced by uart_getchar().

int main ( void  )

Example application on how to use the libc setbaud utility.

This application shows how to use the avr libc setbaud utility to get the correct values for the baud rate registers. It also performs a test where it sends a character on the UART and check if the same char is received back.

Note
This application assumes that the TX and RX pins have been externally shorted to create a loop back.

References Assert, uart_getchar(), uart_init(), and uart_putchar().

static uint8_t uart_getchar ( void  )
static

Function for getting a char from the UART.

Note
This function is blocking and will expect to receive something on the UART.
Return values
uint8_tthe data received from the UART
0if timeout

References TIMEOUT.

Referenced by main().

static void uart_init ( void  )
static

Initialize the uart with correct baud rate settings.

This function will initialize the UART baud rate registers with the correct values using the AVR libc setbaud utility. In addition set the UART to 8-bit, 1 stop and no parity.

References UART_PORT_DDR, UART_RX_PIN, and UART_TX_PIN.

Referenced by main().

static void uart_putchar ( uint8_t  data)
static

Function for sending a char over the UART.

Parameters
datathe data to send over UART

Referenced by main().