megaAVR STK600 UART interrupt example
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <string.h>
#include "compiler.h"
#include "conf_clock.h"
#include "conf_uart.h"
#include <util/setbaud.h>
#include <avr/interrupt.h>
#include "ring_buffer.h"
Macros | |
#define | _ASSERT_ENABLE_ |
#define | BUFFER_SIZE 20 |
The size of the UART buffer. More... | |
Functions | |
ISR (UART0_DATA_EMPTY_IRQ) | |
UART data register empty interrupt handler. More... | |
ISR (UART0_RX_IRQ) | |
Data RX interrupt handler. More... | |
int | main (void) |
The main application. More... | |
static bool | uart_char_waiting (void) |
Function to check if we have a char waiting in the UART receive buffer. More... | |
static uint8_t | uart_getchar (void) |
Function for getting a char from the UART receive buffer. More... | |
static void | uart_init (void) |
Initialize the UART with correct baud rate settings. More... | |
static void | uart_putchar (uint8_t data) |
Function for putting a char in the UART buffer. More... | |
Variables | |
uint8_t | in_buffer [BUFFER_SIZE] |
uint8_t | out_buffer [BUFFER_SIZE] |
struct ring_buffer | ring_buffer_in |
ring buffer to use for the UART reception More... | |
struct ring_buffer | ring_buffer_out |
ring buffer to use for the UART transmission More... | |
const char | test_string [] = "Hello, world!" |
#define _ASSERT_ENABLE_ |
#define BUFFER_SIZE 20 |
The size of the UART buffer.
Referenced by uart_init().
ISR | ( | UART0_DATA_EMPTY_IRQ | ) |
UART data register empty interrupt handler.
This handler is called each time the UART data register is available for sending data.
References ring_buffer_get(), ring_buffer_is_empty(), and ring_buffer_out.
ISR | ( | UART0_RX_IRQ | ) |
Data RX interrupt handler.
This is the handler for UART receive data
References ring_buffer_in, and ring_buffer_put().
|
inlinestatic |
Function to check if we have a char waiting in the UART receive buffer.
true | if data is waiting |
false | if no data is waiting |
References ring_buffer_in, and ring_buffer_is_empty().
Referenced by main().
|
inlinestatic |
Function for getting a char from the UART receive buffer.
Next | data byte in receive buffer |
References ring_buffer_get(), and ring_buffer_in.
Referenced by main().
|
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 BUFFER_SIZE, in_buffer, out_buffer, ring_buffer_in, ring_buffer_init(), and ring_buffer_out.
Referenced by main().
|
inlinestatic |
Function for putting a char in the UART buffer.
data | the data to add to the UART buffer and send |
References ring_buffer_is_empty(), ring_buffer_out, and ring_buffer_put().
Referenced by main().
uint8_t in_buffer[BUFFER_SIZE] |
Referenced by uart_init().
uint8_t out_buffer[BUFFER_SIZE] |
Referenced by uart_init().
struct ring_buffer ring_buffer_in |
ring buffer to use for the UART reception
Referenced by ISR(), uart_char_waiting(), uart_getchar(), and uart_init().
struct ring_buffer ring_buffer_out |
ring buffer to use for the UART transmission
Referenced by ISR(), uart_init(), and uart_putchar().
const char test_string[] = "Hello, world!" |
Referenced by main().